Best way to profile memory usage in a Java application?

可紊 提交于 2019-11-28 20:23:05

With something like JProfiler all you need to do is add certain parameters to the JVM. It uses JVMTI.

I think you should be reading up on profilers and exactly what they can do for you. I also suggest reading up on JVMTI.

The JVMTM Tool Interface (JVM TI) is a new native programming interface for use by tools. It provides both a way to inspect the state and to control the execution of applications running in the Java virtual machine (JVM). JVM TI supports the full breadth of tools that need access to JVM state, including but not limited to: profiling, debugging, monitoring, thread analysis, and coverage analysis tools.

Note: JVM TI replaces the Java Virtual Machine Profiler Interface (JVMPI) and the Java Virtual Machine Debug Interface (JVMDI). JVMPI and JVMDI will be removed in the next major release of J2SETM.

Yourkit also has a pretty good profiler

Liran Orevi

Have you checked

VisualVM and Eclipse-Callisto?

Thorbjørn Ravn Andersen

A good place to start is to see if your JVM supports "java -Xrunhprof" as this can generate heap profiling information without making your scenario more complex.

See http://docs.oracle.com/javase/7/docs/technotes/samples/hprof.html

You might find that enough for you for starting.

Several profiler's such as yourkit have API's for tracing memory allocations. Another option here are monitoring tools such as jxinsight or glassbox or jamon

For analyzing heap dumps theEclipse Memory Analyzer is the best tool you can get. It's free and open source, so you can automate the analysis of heap dumps as much as you want.

I develop in Eclipse but I have Netbeans around to use its excellent Profiler. It is limited compared to some commercial ones but still good enough for spotting most bottlenecks

You can use jrcmd which is a command line utility that comes with the JRockit JVM. If you know the pid of the Java process you can just do:

JROCKIt_HOME\bin\jrcmd <pid> print_object_summary

and it will give you:

31.8% 3198k    41907   -137k [C
11.9% 1196k      300     +0k [B
11.4% 1151k    49118     +6k java/lang/String
 6.1% 612k     5604     +0k java/lang/Class
 4.3% 431k     2388     +0k [I
 3.5% 353k    15097     +0k java/util/HashMap$Entry
 ...

In addition to the above answers I also enjoyed using profiler a couple of years ago. Don't know if that helps.

I do recommend dynaTrace production edition. Amazing tool to profile memory application. Low overhead and 100% of executed transactions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!