You must know will be of JavaJDK tool

JDK has many diagnostic tools for monitoring system, for Java programmers is undoubtedly to know your program is running good or bad performance of a powerful tool.

These tools can be found in the JDK bin directory.

1

JPS

In Linux has a command is called ps, you can view all current processes on the system, while also providing similar jps JDK, Java view running processes.

You can see the parameters of the command.

2

By default, jps output of the Java process, including process ID, and the main class name.

We can also pass additional parameters to print additional information.

For example, -l print module name and the name of the package;

3

-v print parameters passed to the Java virtual machine (e.g., -XX: + UnlockExperimentalVMOptions -XX: + UseZGC);

4

-m print parameters passed to the main class.

5

You can also use -lvm used together.

When the JVM starts, it will create a perf memory to store PerfData, if the parameters are used -XX:-UsePerfDatato prohibit other processes visible, jps command will not be able to see that the Java process.

Jstat

Jstat command is run data for printing a Java process.

6

It supports -classto view the class loading related data, -compilerand -printcompilationview the information in-time compilation.

As well as -gcdata related to garbage collection and so on.

You need to specify sub-commands and Java execution process ID.

7

Figure above, S0C and S1C representing the size of the two regions Survivor, C refers Capacity, capacity.

S0U and S1U is the size of two Survivor areas has been used, U refers Utility, and practical.

EC and EU represent the capacity and use of the Eden area.

OC and OU represent the capacity and use of the Old District.

MC and MU represent the capacity and use of the area.

CCSC and represent CCSU size of the compressed volume and the use of space and the use of relatively few.

YGC represents YoungGC, that is, the number of the young generation GC happens, more accurately should be called MinorGC, YGCT representative of the time spent.

FGC代表FullGC发生的次数,它发生在老年代,FGCT代表所用的时间。

GCT代表所有GC所占用的时间。

可以看到11次YGC只耗时0.439,而8次FGC却用了数倍时间,1.419。

现在我们已经知道每一个标记代表什么了,可以尝试一下使用更详细的gc子命令来查看对应Java进程了。

jstat命令默认执行一次只返回一次,如果我想一直监控某个Java进程,可以添加可以时间参数。

如下图,jstat -gcnew 13496 500,后面跟一个500,就说明每500ms打印一次。

8

还可以指定打印的次数,比如jstat -gcnew 13496 500 5,后面跟500 5,就说明每500ms打印一次,总共打印5次。

9

在我们查看内存区域容量变化时,如果发现老年代的使用率不断增加,就说明有大量对象无法进行回收,我们的程序出现了性能上的问题。

再比如,我们可以添加-t来打印程序运行时间Timestamp,如果GCT占据了大部分程序运行时间,或者说这个时间比在持续上升时。就说明我们程序的堆内存已经在逐步走向奔溃了。

10

Jmap

知道程序有了问题,我们就可以利用Jmap命令来分析了。

Jmap同样包括多条子命令。

11

-clstats,该子命令将打印被加载类的信息。

13

-finalizerinfo,该子命令将打印所有待 finalize 的对象。

14

-histo,该子命令将统计各个类的实例数目以及占用内存,并按照内存使用量从多至少的顺序排列。此外,-histo:live只统计堆中的存活对象。

12

-dump,该子命令将导出 Java 虚拟机堆的快照。同样,-dump:live只保存堆中的存活对象。

我们通常会利用jmap -dump:live,format=b,file=filename.bin命令,将堆中所有存活对象导出至一个文件之中。

15

-heap,该子命令将输出当前堆中的配置信息。

16

Jinfo

Jinfo命令可用来查看目标Java进程的参数。

17

Jstack

这是一个非常有用的命令,它可以用来打印目标 Java 进程中各个线程的栈轨迹,以及这些线程所持有的锁,所以这个命令可以帮助我们处理死锁。

Let's write a simple code will deadlock.

18

Program Paozhaopaozhe deadlock occurs.

19

We use jstack to see.

20

We can see the thread Thread-athat locked the String.class the lock, waiting in Waiting Main.class.

The thread Thread-b, it locked up Main.class, waiting in Waiting String.class.

Jstack even help us find the cause of a deadlock occurs.

21

Guess you like

Origin www.cnblogs.com/LexMoon/p/jdktools.html