千锋重庆Java培训学习Java内存监控工具的介绍

1.JConsole
Jconsole,Java Monitoring and Management Console。

java监控和管理控制台,从java5开始,在JDK中提供。

用于对JVM中内存,线程、类和虚拟机的运行情况等的监控。提供了本地监控和远程监控两种功能。
千锋重庆Java培训学习Java内存监控工具的介绍
2.jps

[root@host bin]# ./jps
17515 Standalone
1487 Jps

3.jmap
jmap是一个可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本。使用方法 jmap -histo pid。如果连用 SHELL jmap -histo pid > a.log可以将其保存到文本中去(windows下也可以使用),在一段时间后,使用文本对比工具,可以对比出GC回收了哪些对象。jmap -dump:format=b,file=f1 3024可以将3024进程的内存heap输出出来到f1文件里。

jmap的常用命令:

(1)jmap -finalizerinfo JVM的进程号

这个表示有多少对象正在finalization队列中,等待finalizer thread进行finalizer,对于finalizer的原理

例如:

[root@tomy tomcat] # /usr/java/latest/bin/jmap -finalizerinfo  25757
Attaching to process ID 25757, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 14.0-b16
Number of objects pending for finalization: 0

(2)jmap -heap JVM的进程号

打印堆的使用情况,以及GC采用什么垃圾回收器

例如:

[root@labs-dev01 tomcat]# /usr/java/latest/bin/jmap -heap  25757
Attaching to process ID 25757, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 14.0-b16
using thread-local object allocation.
Parallel GC with 2 thread(s)
Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 402653184 (384.0MB)
   NewSize          = 1048576 (1.0MB)
   MaxNewSize       = 4294901760 (4095.9375MB)
   OldSize          = 4194304 (4.0MB)
   NewRatio         = 8
   SurvivorRatio    = 8
   PermSize         = 16777216 (16.0MB)
   MaxPermSize      = 67108864 (64.0MB)
Heap Usage:
PS Young Generation
Eden Space:
   capacity = 42598400 (40.625MB)
   used     = 21145576 (20.165992736816406MB)
   free     = 21452824 (20.459007263183594MB)
   49.63936673677885% used
From Space:
   capacity = 1048576 (1.0MB)
   used     = 652736 (0.62249755859375MB)
   free     = 395840 (0.37750244140625MB)
   62.249755859375% used
To Space:
   capacity = 1048576 (1.0MB)
   used     = 0 (0.0MB)
   free     = 1048576 (1.0MB)
   0.0% used
PS Old Generation
   capacity = 357957632 (341.375MB)
   used     = 23543768 (22.453086853027344MB)
   free     = 334413864 (318.92191314697266MB)
   6.577249902021924% used
PS Perm Generation
   capacity = 24903680 (23.75MB)
   used     = 24817640 (23.667945861816406MB)
   free     = 86040 (0.08205413818359375MB)
   99.65450889185855% used

(3)jmap -dump:file= JVM的进程号(java5版本不支持这个参数)

[root@labs-dev01 tomcat]# /usr/java/latest/bin/jmap -dump:file=heap.bin  -F 25757
Attaching to process ID 25757, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 14.0-b16
Dumping heap to mashup ...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Finding object size using Printezis bits and skipping over...
Heap dump file created
[root@tomy tomcat]# /usr/java/latest/bin/jhat heap.bin
Reading from heap.bin...
Dump file created Wed Apr 14 08:57:06 GMT+00:00 2010
Snapshot read, resolving...
Resolving 443412 objects...
Chasing references, expect 88 dots........................................................................................
Eliminating duplicate references........................................................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
上一篇:阿里云服务器搭建(全套步骤)


下一篇:pydub 把音频按时间段切成小段