命令行工具
1、jps命令
jps:虚拟机进程状态工具,该命令在Java环境部署和服务启动查看时经常用到,首先在本地启动一个facade门面微服务,然后在命令行中执行查询;
jps
:命令默认输出的是进程ID和应用主类的名称;-l
:输出进程ID和应用主类的完整路径;-v
:输出向jvm传递的参数,此处展示为idea中显式配置的VM-options参数,其他内容自行查看即可;-m
:输出向main方法传递的参数,服务启动前可以在idea的Program-arguments配置;
$ jps
1281 FacadeApp
$ jps -l
1281 com.explore.facade.FacadeApp
$ jps -v
1281 FacadeApp -Xms128m -Xmx256m -XX:MaxNewSize=256m -XX:MaxPermSize=256m
$ jps -m
1281 FacadeApp hello,main-method
2、jinfo命令
jinfo:在命令后面带pid进程号,可以输出指定进程的配置信息,在应用启动时通常不会指定过多的配置参数,就可以使用该命令查询很多参数的默认值;该命令还可以在运行时动态调整部分参数,只是很少被使用;
$ jinfo 1281 # 只粘贴个别参数
Java System Properties: # 系统参数
java.runtime.version=1.8.0_144-b01
file.encoding=UTF-8
sun.java.command=com.explore.facade.FacadeApp hello,main-method
VM Flags: # 虚拟机参数
-XX:InitialHeapSize=134217728 -XX:MaxHeapSize=268435456 -XX:MaxNewSize=267911168
VM Arguments: # 运行时参数
jvm_args: -Xms128m -Xmx256m -XX:MaxNewSize=256m -XX:MaxPermSize=256m
java_command: com.explore.facade.FacadeApp hello,main-method
$ jinfo -sysprops 1281 # 只输出【Java System Properties】参数
$ jinfo -flags 1281 # 只输出【VM Flags】参数
3、jstat命令
jstat:以指定的频率输出JVM的监控指标,下述命令输出内存占用和GC相关信息,每隔3秒输出一次,连续打印5次;由于这里只是启动一个简单的微服务,没有执行业务逻辑,所以各项指标比较平稳;
$ jstat -gcutil 1281 3000 5
S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT
0.00 0.00 57.97 64.16 92.82 88.75 3 0.028 9 0.516 - - 0.544
0.00 0.00 57.97 64.16 92.82 88.75 3 0.028 9 0.516 - - 0.544
该命令是比较常用的,这里各项指标的统计逻辑,在tools.jar
包中有jstat_options
参考文档,相对路径sun/tools/jstat/resources/
目录下;
option gcutil {
column {
header "^S0^" /* Survivor 0 Space - Percent Used */
data (1-((sun.gc.generation.0.space.1.capacity - sun.gc.generation.0.space.1.used)/sun.gc.generation.0.space.1.capacity)) * 100
}
column {
header "^S1^" /* Survivor 1 Space - Percent Used */
data (1-((sun.gc.generation.0.space.2.capacity - sun.gc.generation.0.space.2.used)/sun.gc.generation.0.space.2.capacity)) * 100
}
......
}
4、jstack命令
jstack:输出指定进程当前时刻在JVM中的线程信息,为了清楚的展示其效果,在服务启动时创建线程死锁,然后通过该命令就会把发生死锁的线程打印出来,通过输出可以发现两条互相等待的线程信息;
$ jstack 1281
Found one Java-level deadlock:
=============================
"test-thread-02":
waiting for ownable synchronizer 0x00000007b00a35d0, (a java.util.concurrent.locks.ReentrantLock$NonfairSync),
which is held by "test-thread-01"
"test-thread-01":
waiting for ownable synchronizer 0x00000007b00a35a0, (a java.util.concurrent.locks.ReentrantLock$NonfairSync),
which is held by "test-thread-02"
Java stack information for the threads listed above:
===================================================
"test-thread-02":
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000007b00a35d0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
"test-thread-01":
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000007b00a35a0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
Found 1 deadlock.
5、jmap命令
jmap:可以输出指定进程的内存中对象映射信息,或者堆的关键信息、内存的使用统计、GC算法、配置、类的实例信息及内存占用等,该命令在解决JVM问题时也经常使用;
$ jmap 1281
$ jmap -heap 1281
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 536870912 (512.0MB)
Heap Usage:
PS Young Generation
Eden Space:
From Space:
To Space:
PS Old Generation
$ jmap -histo:live 1281
num #instances #bytes class name
----------------------------------------------
1311: 1 32 com.explore.facade.FacadeApp$$EnhancerBySpringCGLIB$$313d9e3
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/291797.html