jcmd jvm performance tuning tool of

Outline

After JDK1.7, add a command-line tool jcmd. He is a versatile tool that can be used to derive the heap, see Java process, export thread information, perform GC, can also be sampled and analyzed (flight recorders jmc tools).

Command Format

1   jcmd <pid | main class> <command ... | PerfCounter.print | -f  file>
2   jcmd -l
3   jcmd -h

description

  • pid: receiving diagnostic process ID request command.
    main class: the process of receiving a diagnosis request command of the main class. When the matching process, main class name contains the substring of any process specified are matched. If you are running multiple Java processes share the same main class, diagnostic command request will be sent to all of these processes.

  • command: receiving diagnostic process command requested main class. When the matching process, main class name contains the substring of any process specified are matched. If you are running multiple Java processes share the same main class, diagnostic command request will be sent to all of these processes.

    Note: If any of the parameters contains spaces, you must use English single or double quotation marks to enclose. In addition, you must use an escape character to transfer parameters in single or double quotes to prevent the operating system shell to deal with these reference marks. Of course, you can both parameters with an apostrophe, and then use the parameters in double quotes (or double quotation marks on both sides of the parameters, the parameters used in single quotes).

  • Perfcounter.print: Available on the print target Java process performance counters. A list of performance counters may vary from the Java process to produce change.

  • -f file: read commands from file file and then invoke the commands on the target Java process. In the file, each command must be written on a separate line. Line with "#" at the beginning will be ignored. When the command is called for all rows is completed, or read command with stop keyword will terminate the processing of the file.

  • -l: View a list of all the process information.

  • -h: View help information. (With -help)

View the process jcmd -l

Command: jcmd -l
description: View all jvm process information on the current machine

1   jcmd 
2   jcmd -l
3   jps 

The effect of these three commands are the same

View performance statistics

Command: jcmd pid PerfCounter.print
description: View performance statistics for the specified process.

 1 C:\Windows\system32>jcmd 9592 PerfCounter.print
 2 9592:
 3 java.ci.totalTime=16704
 4 java.cls.loadedClasses=438
 5 java.cls.sharedLoadedClasses=0
 6 java.cls.sharedUnloadedClasses=0
 7 java.cls.unloadedClasses=0
 8 java.property.java.class.path="D:\work\git\test\target\classes"
 9 java.property.java.endorsed.dirs="D:\Program Files\Java\jre1.8.0_91\lib\endorsed"
10 java.property.java.ext.dirs="D:\Program Files\Java\jre1.8.0_91\lib\ext;C:\Windows\Sun\Java\lib\ext"
11 java.property.java.home="D:\Program Files\Java\jre1.8.0_91"
12 ...

Lists the current java process running operation that can be performed

Command: jcmd PID help

 1 C:\Windows\system32>jcmd 9592 help
 2 9592:
 3 The following commands are available:
 4 JFR.stop
 5 JFR.start
 6 JFR.dump
 7 JFR.check
 8 VM.native_memory
 9 VM.check_commercial_features
10 VM.unlock_commercial_features
11 ManagementAgent.stop
12 ManagementAgent.start_local
13 ManagementAgent.start
14 GC.rotate_log
15 Thread.print
16 GC.class_stats
17 GC.class_histogram
18 GC.heap_dump
19 GC.run_finalization
20 GC.run
21 VM.uptime
22 VM.flags
23 VM.system_properties
24 VM.command_line
25 VM.version
26 help

Option to view specific commands

If you want to view the command options, for example, want to see JFR.dump command option, by the following command:
jcmd 11772 Help JFR.dump

 

 

1.JRF related commands

JRF function with the flight recorder function jmc.exe tool of the same.
To use the JRF-related functions, parameters must be used VM.unlock_commercial_features Unlock business functions.

 

 

 

 

  • Start JFR
    execute the command: jcmd $ PID JFR.start name = abc , duration = 120s

  • Dump JFR
    Wait at least duration (paper setting 120s), execute the command: jcmd PID JFR.dump name = abc, duration = 120s filename = abc.jfr ( Note that the file name must be .jfr suffix)

  • Check the status JFR
    execute the command: jcmd $ PID JFR.check name = abc , duration = 120s

  • Stop JFR
    execute the command: jcmd $ PID JFR.stop name = abc , duration = 120s

  • Analysis JMC
    cut back development machine, the downloading abc.jfr generated in step 3, JMC opened, introducing visual analysis can abc.jfr

VM.uptime

Command: jcmd PID VM.uptime
long view JVM startup time: Description:

GC.class_histogram

Command: jcmd PID GC.class_histogram
description: View system statistics class

 

 

Here and effect jmap -histo pid is the same as
the instance of each class can view the number and footprint size.

Thread.print

Command: jcmd PID Thread.print
description: View thread stack information.

The command with  jstack  command.

GC.heap_dump

Command: jcmd PID GC.heap_dump FILE_NAME
Description: View the JVM Heap Dump

1 C:\Users\jjs>jcmd 10576 GC.heap_dump d:\dump.hprof
2 10576:
3 Heap dump file created

跟 jmap命令:jmap -dump:format=b,file=heapdump.phrof pid 效果一样。
导出的 dump 文件,可以使用MAT 或者 Visual VM 等工具进行分析。

注意:如果只指定文件名,默认会生成在启动 JVM 的目录里。

VM.system_properties

命令:jcmd PID VM.system_properties
描述:查看 JVM 的属性信息

 1 C:\Users\jjs>jcmd 10576 VM.system_properties
 2 10576:
 3 #Wed Jan 31 22:30:20 CST 2018
 4 java.vendor=Oracle Corporation
 5 osgi.bundles.defaultStartLevel=4
 6 ......
 7 os.version=10.0
 8 osgi.arch=x86_64
 9 path.separator=;
10 java.vm.version=25.91-b15
11 org.osgi.supports.framework.fragment=true
12 user.variant=
13 osgi.framework.shape=jar
14 java.awt.printerjob=sun.awt.windows.WPrinterJob
15 osgi.instance.area.default=file\:/C\:/Users/jjs/eclipse-workspace/
16 sun.io.unicode.encoding=UnicodeLittle
17 org.osgi.framework.version=1.8.0
18 ......

VM.flags

命令:jcmd PID VM.flags
描述:查看 JVM 的启动参数

1 C:\Users\jjs>jcmd 10576 VM.flags
2 10576:
3 -XX:CICompilerCount=3 -XX:ConcGCThreads=1 
4 -XX:G1HeapRegionSize=1048576 -XX:InitialHeapSize=268435456 
5 -XX:MarkStackSize=4194304 -XX:MaxHeapSize=1073741824 
6 -XX:MaxNewSize=643825664 -XX:MinHeapDeltaBytes=1048576 
7 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops 
8 -XX:+UseFastUnorderedTimeStamps -XX:+UseG1GC 
9 -XX:-UseLargePagesIndividualAllocation -XX:+UseStringDeduplication

VM.command_line

命令:jcmd PID VM.command_line
描述:查看 JVM 的启动命令行

1 C:\Users\jjs>jcmd 10576 VM.command_line
2 10576:
3 VM Arguments:
4 jvm_args: -Dosgi.requiredJavaVersion=1.8 
5 -Dosgi.instance.area.default[email protected]/eclipse-workspace 
6 -XX:+UseG1GC -XX:+UseStringDeduplication 
7 -Dosgi.requiredJavaVersion=1.8 -Xms256m -Xmx1024m
8 java_command: <unknown>
9 java_class_path (initial): D:\tool\...\org.eclipse.equinox.launcher.jar

GC.run_finalization

命令:jcmd PID GC.run_finalization
描述: 对 JVM 执行 java.lang.System.runFinalization()

1 C:\Users\jjs>jcmd 10576 GC.run_finalization
2 10576:
3 Command executed successfully

执行一次finalization操作,相当于执行java.lang.System.runFinalization()

GC.run

命令:jcmd PID GC.run
描述:对 JVM 执行 java.lang.System.gc()

1 C:\Users\jjs>jcmd 10576 GC.run
2 10576:
3 Command executed successfully

告诉垃圾收集器打算进行垃圾收集,而垃圾收集器进不进行收集是不确定的。

PerfCounter.print

命令:jcmd PID PerfCounter.print
描述:查看 JVM 性能相关的参数

1 C:\Users\jjs>jcmd 10576 PerfCounter.print
2 10576:
3 java.ci.totalTime=93024843
4 java.cls.loadedClasses=18042
5 java.cls.sharedLoadedClasses=0
6 java.cls.sharedUnloadedClasses=0
7 java.cls.unloadedClasses=3
8 ......

VM.version

命令:jcmd PID VM.version
描述:查看目标jvm进程的版本信息

1 C:\Users\jjs>jcmd 10576 VM.version
2 10576:
3 Java HotSpot(TM) 64-Bit Server VM version 25.91-b15
4 JDK 8.0_91

 

Guess you like

Origin www.cnblogs.com/lgjava/p/12180791.html