How to add enable flag for Flight Recorder in Mave

2019-05-20 03:39发布

问题:

I'm just about start using Java Mission Control 5.3.0.

I have added -XX:+UnlockCommercialFeatures -XX:+FlightRecorder into my web-app's jetty.template.

Then I start the web-app with mvn jetty:run.

But while I was starting Flight Recorder I got the problem occurred pop-up as below.

'Start Flight Recording.. (Last attempt failed)' have encountered a problem.Commercial features are not enabled. In JDK7u4 and above,the JVM must be started with -XX:+UnlockCommercialFeatures -XX:+FlightRecorder .

And I also try adding the flags as below into pom.xml but it doesn't work.

<jvmArgs>
    <jvmArg>-Xmx128m</jvmArg>
    <jvmArg>-Xms128m</jvmArg>
    <jvmArg>-XX:MaxPermSize=512m</jvmArg>
    <jvmArg>-XX:+UnlockCommercialFeatures</jvmArg>
    <jvmArg>-XX:+FlightRecorder</jvmArg>
    <jvmArg>-XX:StartFlightRecording=duration=160s,delay=20s,settings=profile,filename=target/recording.jfr</jvmArg>
</jvmArgs>

What should I do for enable Flight Recorder on my web-app?

回答1:

If you are using jcmd command from jdk, then could enable JFR via:

jcmd 31118 VM.unlock_commercial_features

Then use JFR.

e.g

jcmd 31118 JFR.start name=a



回答2:

That configuration should be added to the running VM of Jetty so I'd try this:

mvn jetty:run -XX:+UnlockCommercialFeatures -XX:+FlightRecorder

I could not test this, and I work most on Tomcat, but I think this could help you



回答3:

I got the answer by using below.

export MAVEN_OPTS="$MAVEN_OPTS -XX:+UnlockCommercialFeatures -XX:+FlightRecorder"