I am trying to selectively monitor/profile a Java application when certain runtime conditions are met. I am already able to dump the heap on-the-fly using the HotSpotDiagnosticMXBean, which has been quite useful.
I am now trying to do something similar with CPU profiling, hoping to more effectively target specific code paths. I have some experience with the command-line HPROF interface and the NetBeans profiler, but both need to be started beforehand.
Is there a way to activate the HPROF profiler programatically from within a running application? Preferably something that would allow me to start and stop the profiling process at will?