开发者

How to profile object creation in Java? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
开发者_如何学Python

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed last year.

Improve this question

The system I work with is creating a whole lot of objects and garbage collecting them all the time which results in a very steeply jagged graph of heap consumption. I would like to know which objects are being generated to tune the code, but I can't figure out a way to dump the heap at the moment the garbage collection starts. When I tried to initiate dumpHeap via JConsole manually at random times, I always got results after GC finished its run, and didn't get any useful data.

Any notes on how to track down excessive temporary object creation are welcome.


Have a look at what BTrace can do (http://kenai.com/projects/btrace/pages/Home), alternatively try using jvisualvm in JDK 6u18 which does live memory sampling.


What you're looking for are the most intensive allocation sites in your program. You can use a tool like: Allocation Instrumentor for Java. The answer to your comment:

When I tried to initiate dumpHeap via JConsole manually at random times, I always got results after GC finished its run, and didn't get any useful data.

is that a heap dump triggers a GC in the VM because the heap dump is a report of what is live in the heap (for the most part) - the VM wants the most accurate picture of what is live at the time the heap dump was triggered and therefore a GC event will always happen right after the dump request is initiated.

Tuning the Java heap is an art - and there is plenty of material out on the web on how to do it.


Apache JMeter

Quote from the projects page:

Apache JMeter may be used to test performance both on static and dynamic resources (files, Servlets, Perl scripts, Java Objects, Data Bases and Queries, FTP Servers and more). It can be used to simulate a heavy load on a server, network or object to test its strength or to analyze overall performance under different load types.

I remember M. Fowler mentioned that it's almost impossible to guess what causes performance issues until you test the whole system with a profiler.


You could use the JVMPI interface (and tools like Dr.MEM) and create your own custom solution if non of the solutions prescribed above solve your purpose. This could however be an overkill depending on your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜