HPROF Java Software Launch on the fly

I am trying to selectively control / profile a Java application when certain execution conditions are met. I can already drop the heap on the fly using HotSpotDiagnosticMXBean , which was quite useful.

Now I'm trying to do something similar with CPU profiling, hoping to target specific code codes more efficiently. I have experience with the HPROF interface and the NetBeans profiler, but both must be started in advance.

Is there a way to activate the HPROF profiler programmatically from a running application? Preferably, something that would allow me to start and stop the profiling process at will?

+8
java profiler hprof
source share
1 answer

According to the JVMTI documentation , native agent libraries, such as hprof, must be loaded very early during JVM initialization before any bytecode is run. So no, this is impossible to do on the fly.

An alternative would be to restart the Java process with the modified JVM parameters in the main function, although this is not trivial.

+1
source share

All Articles