Tomcat内存分析相关方法(jmap和mat)

Linux环境命令行

首先,根据进程命令,获取运行的tomcat的进程ID

ps aux | grep tomcat | grep java | grep bsc

在第二列可以看到进程ID

然后使用jmap可以查看内存占比:

/home/work/bsc/java/jdk-1.7-7u60/bin/jmap -heap 7840

输出的结果包括了内存各个部分的占比:

[work@xxxx.com logs]$ /home/work/bsc/java/jdk-1.7-7u60/bin/jmap -heap 10433
Attaching to process ID 10433, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.60-b09

using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC

Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 8388608000 (8000.0MB)
   NewSize          = 1048576000 (1000.0MB)
   MaxNewSize       = 1048576000 (1000.0MB)
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 134217728 (128.0MB)
   MaxPermSize      = 268435456 (256.0MB)
   G1HeapRegionSize = 0 (0.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
   capacity = 943718400 (900.0MB)
   used     = 393328672 (375.1074523925781MB)
   free     = 550389728 (524.8925476074219MB)
   41.67860582139757% used
Eden Space:
   capacity = 838860800 (800.0MB)
   used     = 288471072 (275.1074523925781MB)
   free     = 550389728 (524.8925476074219MB)
   34.388431549072266% used
From Space:
   capacity = 104857600 (100.0MB)
   used     = 104857600 (100.0MB)
   free     = 0 (0.0MB)
   100.0% used
To Space:
   capacity = 104857600 (100.0MB)
   used     = 0 (0.0MB)
   free     = 104857600 (100.0MB)
   0.0% used
concurrent mark-sweep generation:
   capacity = 1288736768 (1229.03515625MB)
   used     = 706435104 (673.7090148925781MB)
   free     = 582301664 (555.3261413574219MB)
   54.816089797478334% used
Perm Generation:
   capacity = 134217728 (128.0MB)
   used     = 65034240 (62.021484375MB)
   free     = 69183488 (65.978515625MB)
   48.45428466796875% used

27139 interned Strings occupying 3055832 bytes.

如上可以清楚的看到内存配置信息、年轻代(包括eden、from、to)、老年代、永久代各自的内存信息和占比。

使用Eclipse的memory analysis tool工具进行详细分析

首先,使用命令将内存dump到文件:

/home/work/bsc/java/jdk-1.7-7u60/bin/jmap -dump:format=b,file=/home/work/tmp/bsc.bin 10433

MAT(Memory Analyzer Tool)工具是eclipse的一个插件,使用起来非常方便,尤其是在分析大内存的dump文件时,可以非常直观的看到各个对象在堆空间中所占用的内存大小、类实例数量、对象引用关系、利用OQL对象查询,以及可以很方便的找出对象GC Roots的相关信息,当然最吸引人的还是能够快速为开发人员生成内存泄露报表,方便定位问题和分析问题。

MAT工具的下载地址为: http://www.eclipse.org/mat/downloads.php

MAT插件的下载地址为: http://download.eclipse.org/mat/1.3/update-site/

mat_image

 

然后就可以查看内存中的数据,点击饼图,也可以看下占比最大的对象是什么,从而分析程序的行为。

本文地址:http://crazyant.net/1980.html

相关推荐

1 thought on “Tomcat内存分析相关方法(jmap和mat)”

Leave a Comment