
Start Java Flight Recorder — Notes
This note isn’t a full-blown tutorial of JFR, rather just the steps I recently followed to run JFR on one of the applications I am working on.
JFR is designed to be much less intrusive to the running app and thereby affecting its performance considerably less.
Note: I am using Azul OpenJDK for my application.
- Download jcmd and other Azul OpenJDK tools from their official website.
2. Extract the tools in the above tar:
tar
xf zulu8.58.0.13-ca-jdk8.0.312-linux_x64.tar.gz
3. Move the above tools to a location accessible to the user running the service. (in case it is the logged-in user, ignore this step)
JFR is a stickler about the user running the application to have access to flight recording (Reasonable). Oh and by the way, It doesn’t care if you are root!
mv zulu8.58.0.13-ca-jdk8.0.312-linux_x64 /home/<java-app-user>/
4. Change the user to <java-app-user> (in case it is the logged-in user, ignore this step)
sudo su -l java-app-user -s /bin/bash
5. Set the following environment variables(Essential for jcmd to load libraries correctly)
export JAVA_HOME=/usr/java/jre-xxx
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/:$JAVA_HOME/lib:/home/content-library/zulu8.58.0.13-ca-jdk8.0.312-linux_x64/lib
6. Run the Flight recorder for the desired duration using the command:
../zulu8.58.0.13-ca-jdk8.0.312-linux_x64/bin/jcmd com.abc.MainClassName JFR.start duration=100s filename=flight.jfr
7. Import flight.jfr into Azul/Oracle Java Mission Control software for analysis.