title: Using Java profiler in Junit
body: <p>Is there a Java profiler that can be integrated as part of JUnit testing.</p>
  
  <p>For example, I would like to have a condition that if a certain method in a test is using over X% of the CPU the test should fail/pass.</p>
  
  <p>Or if a certain method is running for more than X amount of minutes it should fail.</p>
  
  <p>I looked at YourKit, JVM monitor, and other suggested tools in here, as well as
  running <code>java -Xrunhprof:cpu=samples,file=myprogram.hprof</code></p>
  
  <p>but all of these do not offer to be used as part of the test.</p>
  
  <p>I would also be ok with invoking the profiler from the test, saving the results (automatically) to a csv/txt/any other file, and writing some code to extract the information.</p>
  
  <p>An open source/free tool would be better, if such exists  </p>