How to record JFR (Java Flight Recorder) and output a dump file

We will introduce how to record JFR (Java Flight Recorder) and output a dump file. Here, the state of ** Eclipse GlassFish 5.1.0 ** is recorded.

environment

[[email protected] ~]$ cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[[email protected] ~]$
[[email protected] ~]$ java -version
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)
[[email protected] ~]$
[[email protected] ~]$ /opt/glassfish5/glassfish/bin/asadmin version
Version string could not be obtained from Server [localhost:4848].
(Turn debugging on e.g. by setting AS_DEBUG=true in your environment, to see the details.)
Using locally retrieved version string from version class.
Version = GlassFish Server Open Source Edition  5.1.0  (build default-private)
Command version executed successfully.
[[email protected] ~]$

For ** GlassFish 5.1.0 ** installation, see the previous post How to install Eclipse GlassFish 5.1.0 on CentOS 7. Please give me.

1. Setting JVM options when starting Glassfish

Add the following to the JVM options when starting Glassfish.

Specifically, "domain / configs / java-config" of domain.xml under" / opt / glassfish5 / glassfish / domains / domain1 / config" (java-config tag in the configs tag in the domain tag) Add the following 3 lines to (inside).

/opt/glassfish5/glassfish/domains/domain1/config/domain.Add to xml


<jvm-options>-XX:+UnlockCommercialFeatures</jvm-options>
<jvm-options>-XX:+FlightRecorder</jvm-options>
<jvm-options>-XX:FlightRecorderOptions=defaultrecording=true,disk=true,repository=/var/log/jvm/repositories,maxsize=2048m,maxage=25h,dumponexit=true,dumponexitpath=/var/log/jvm/dump.jfr</jvm-options>

Here, / var / log / jvm is used as the temporary directory, so create a jvm directory under / var / log, and the glassfish user can create files and files under / var / log / jvm. Make sure you can create the directory.

Execution result


[[email protected] ~]$ su
password:
[[email protected] glassfish]# cd /var/log
[[email protected] log]#
[[email protected] log]# mkdir jvm
[[email protected] log]# chown glassfish:glassfish jvm
[[email protected] log]# exit
exit
[[email protected] ~]$

2. Start Glassfish

Start Glassfish with the following command.

/opt/glassfish5/glassfish/bin/asadmin start-domain domain1

Execution result


[[email protected] config]$ /opt/glassfish5/glassfish/bin/asadmin start-domain domain1
Waiting for domain1 to start ......
Successfully started the domain : domain1
domain  Location: /opt/glassfish5/glassfish/domains/domain1
Log File: /opt/glassfish5/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
[[email protected] config]$

3. Output of JFR dump file

First, check the process ID of glassfish with the following command.

ps -ef | grep glassfish | grep -v grep

Execution result


[[email protected] config]$ ps -ef | grep glassfish | grep -v grep
glassfi+ 26302     1  5 19:54 pts/0    00:00:16 /usr/java/jdk1.8.0_241-amd64/bin/java -cp /opt/glassfish5/glassfish/modules/glassfish.jar -XX:+UnlockCommercialFeatures -XX:+UnlockDiagnosticVMOptions -XX:NewRatio=2 -XX:FlightRecorderOptions=defaultrecording=true,disk=true,repository=/var/log/jvm/repositories,maxsize=2048m,maxage=25h,dumponexit=true,dumponexitpath=/var/log/jvm/dump.jfr -XX:+FlightRecorder -XX:MaxPermSize=192m -Xmx512m -javaagent:/opt/glassfish5/glassfish/lib/monitor/flashlight-agent.jar -client -Djavax.xml.accessExternalSchema=all -Djavax.net.ssl.trustStore=/opt/glassfish5/glassfish/domains/domain1/config/cacerts.jks -Djdk.tls.rejectClientInitiatedRenegotiation=true -Djdk.corba.allowOutputStreamSubclass=true -Dfelix.fileinstall.dir=/opt/glassfish5/glassfish/modules/autostart/ -Dorg.glassfish.additionalOSGiBundlesToStart=org.apache.felix.shell,org.apache.felix.gogo.runtime,org.apache.felix.gogo.shell,org.apache.felix.gogo.command,org.apache.felix.shell.remote,org.apache.felix.fileinstall -Dcom.sun.aas.installRoot=/opt/glassfish5/glassfish -Dfelix.fileinstall.poll=5000 -Djava.endorsed.dirs=/opt/glassfish5/glassfish/modules/endorsed:/opt/glassfish5/glassfish/lib/endorsed -Djava.security.policy=/opt/glassfish5/glassfish/domains/domain1/config/server.policy -Dosgi.shell.telnet.maxconn=1 -Dfelix.fileinstall.bundles.startTransient=true -Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory -Dfelix.fileinstall.log.level=2 -Djavax.net.ssl.keyStore=/opt/glassfish5/glassfish/domains/domain1/config/keystore.jks -Djava.security.auth.login.config=/opt/glassfish5/glassfish/domains/domain1/config/login.conf -Dfelix.fileinstall.disableConfigSave=false -Dfelix.fileinstall.bundles.new.start=true -Dcom.sun.aas.instanceRoot=/opt/glassfish5/glassfish/domains/domain1 -Dosgi.shell.telnet.port=6666 -Dgosh.args=--nointeractive -Dcom.sun.enterprise.security.httpsOutboundKeyAlias=s1as -Dosgi.shell.telnet.ip=127.0.0.1 -DANTLR_USE_DIRECT_CLASS_LOADING=true -Djava.awt.headless=true -Dcom.ctc.wstx.returnNullForDefaultNamespace=true -Djava.ext.dirs=/usr/java/jdk1.8.0_241-amd64/lib/ext:/usr/java/jdk1.8.0_241-amd64/jre/lib/ext:/opt/glassfish5/glassfish/domains/domain1/lib/ext -Djdbc.drivers=org.apache.derby.jdbc.ClientDriver -Djava.library.path=/opt/glassfish5/glassfish/lib:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib com.sun.enterprise.glassfish.bootstrap.ASMain -upgrade false -domaindir /opt/glassfish5/glassfish/domains/domain1 -read-stdin true -asadmin-args --host,,,localhost,,,--port,,,4848,,,--secure=false,,,--terse=false,,,--echo=false,,,--interactive=true,,,start-domain,,,--verbose=false,,,--watchdog=false,,,--debug=false,,,--domaindir,,,/opt/glassfish5/glassfish/domains,,,domain1 -domainname domain1 -instancename server -type DAS -verbose false -asadmin-classpath /opt/glassfish5/glassfish/lib/client/appserver-cli.jar -debug false -asadmin-classname com.sun.enterprise.admin.cli.AdminMain
[[email protected] config]$

You can see that the process ID is 26302.

Output the JFR (Java Flight Recorder) record to a dump file with the following command.

jcmd <process ID> JFR.dump recording = 0 filename = <path of output dump file>

Execution result


[[email protected] ~]$ jcmd 26302 JFR.dump recording=0 filename=/home/glassfish/perf/test_$(date "+%Y%m%d_%H%M%S").jfr
26302:
Dumped recording 0, 2.5 MB written to:

/home/glassfish/perf/test_20200726_200546.jfr
[[email protected] ~]$

Check the output dump file.

Execution result


[[email protected] ~]$ cd /home/glassfish/perf
[[email protected] perf]$ ls -l
2600 in total
-rw-rw-r--.1 glassfish glassfish 2660207 July 26 20:05 test_20200726_200546.jfr
[[email protected] perf]$

3. Refer to the dump file (jfr file) output by "jmc.exe"

Transfer the output jfr dump file (test_20200726_200546.jfr) to the Windows PC on which jdk1.8 is installed.

Start "jmc.exe" (Java Mission Contorol) under " C: \ Program Files \ Java \ jdk1.8.0_231 \ bin ".

01.png

Open the jfr dump file (test_20200726_200546.jfr) output by selecting "File"-"Open File" from the menu.

02.png

03.png

You can refer to the jfr dump file output by "jmc.exe" (Java Mission Contorol).

04.png

reference

Java Platform, Standard Edition Tools Reference

Recommended Posts

How to record JFR (Java Flight Recorder) and output a dump file
[Java] How to output and write files!
How to ZIP a JAVA CSV file and manage it in a Byte array
How to jump from Eclipse Java to a SQL file
How to convert A to a and a to A using AND and OR in Java
How to convert a file to a byte array in Java
How to develop and register a Sota app in Java
How to make a Java container
I checked Java Flight Recorder (JFR)
Log output to file in Java
How to make a Java array
How to load a Spring upload file and view its contents
How to read a file and treat it as standard input
Convert Excel to Blob with java, save it, read it from DB and output it as a file!
How to make a Java calendar Summary
[Java] How to use the File class
[Introduction to Java] How to write a Java program
How to make a Discord bot (Java)
How to output Java string to console screen
How to test a private method in Java and partially mock that method
[IntelliJ IDEA] How to automatically add final when saving a Java file
The story of forgetting to close a file in Java and failing
How to find out the Java version of a compiled class file
How to make an app with a plugin mechanism [C # and Java]
Scraping and writing specific elements to a file
How to output Excel and PDF using Excella
[Java] How to use FileReader class and BufferedReader class
Basics of Java development ~ How to write a program (flow and conditional branching) ~
How to display a web page in Java
How to dump from database (DB) to seeds file
How to convert a solidity contract to a Java contract class
A story about trying to operate JAVA File
How to get and study java SE8 Gold
How to access Java Private methods and fields
[Java] How to use Calendar class and Date class
How to save a file with the specified extension under the directory specified in Java to the list
Create a Java Servlet and JSP WAR file to deploy to Apache Tomcat 9 in Gradle
<java> Read Zip file and convert directly to string
How to create a Java environment in just 3 seconds
[Java] Types of comments and how to write them
How to input / output IBM mainframe files in Java?
[Java] How to play rock-paper-scissors (equivalent to paiza rank A)
[Java] How to extract the file name from the path
Java memory management and how to read GC Viewer
How to create a data URI (base64) in Java
[Java] How to get a request by HTTP communication
[Java] How to execute tasks on a regular basis
How to download a file (Servlet, HTML, Apache, Tomcat)
[Java] How to cut out a character string character by character
[Java] How to erase a specific character from a character string
[Java] How to start a new line with StringBuilder
How to write comments in the schema definition file in GraphQL Java and reflect them in GraphQL and GraphQL Playground
How to request a CSV file as JSON with jMeter
How to read your own YAML file (*****. Yml) in Java
Generate and execute Jar file of Java file belonging to package
Assign a Java8 lambda expression to a variable and reuse it
[Ruby] How to split each GraphQL query into a file
How to decompile apk file to java source code with MAC
Java conditional branching: How to create and study switch statements
How to create a lightweight container image for Java apps
How to deploy a simple Java Servlet app on Heroku