简体   繁体   中英

Java Mission Control Listener?

I currently have some Java code that I would like to profile. I decided to use Java Mission Control after reading some promising things about it. However, every resource I've consulted so far tells me to first start the process I want to profile first, and only then "attach" or profile the code from Mission Control once it is already running (for example this video from oracle: https://youtu.be/WMEpRUgp9Y4?t=14m56s ).

Is there a way to start the process with profiling from the start? Thanks

There is a way to start a profiling recording when you start the process.

Example: Running a profiling recording for 10 minutes.

java -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=duration=10m,name=Test,filename=recording.jfr,settings=profile -jar target/highcpu-0.0.1.jar

See my article for more details: Using Java Flight Recorder

It's not very well documented but there is the possibility. You need to use this jvm options

-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=

The first two are mandatory while the last one need to be configured with various parameters that you can find explained here . It's not straightforward to understand the meaning of each parameter but with some trial and error you can find a good set of option pretty easily.

Just as reference this one is a minimal functional configuration:

java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,disk=true,repository=/tmp,maxage=6h,settings=default MyApp

JDK 11:

-XX:StartFlightRecording

JDK 9, JDK 10:

-XX:+UnlockCommercialFeatures
-XX:StartFlightRecording

JDK 8u40,

-XX:+UnlockCommercialFeatures
-XX:StartFlightRecording=name=whatever

JDK 7u4, JDK 8u20:

-XX:+UnlockCommercialFeatures 
-XX:+FlightRecorder 
-XX:StartFlightRecording=name=whatever

If you want to avoid attaching to the process all together, you can specify a filename, ie -XX:StartFlightRecording=filename=rec.jfr, and then either dump the recording after a period by setting a duration, ie duration=60s, or if you only want it to happen when the JVM exits:

 -XX:StartFlightRecording=
 filename=rec.jfr,dumponexit=true

You can the open then open recording file in JMC. In JDK 11, this has been simplified further so you only need to specify:

 -XX:StartFlightRecording:filename=c:\recs

and the filename will be generated in the specified directory and it will automatically dump when the JVM exits.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM