VisualVM中的配置文件整个Java程序执行 [英] Profile Entire Java Program Execution in VisualVM

查看:69
本文介绍了VisualVM中的配置文件整个Java程序执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java性能分析中,如今似乎所有(免费)的技术通向JDK6附带的VisualVM Profiler.它看起来像是一个很好的程序,每个人都吹捧如何将它附加到正在运行的进程中"作为主要功能.问题是,这似乎是在本地进程上使用它的唯一方法.我希望能够在探查器中启动我的程序,并跟踪其整个执行.

In Java profiling, it seems like all (free) roads nowadays lead to the VisualVM profiler included with JDK6. It looks like a fine program, and everyone touts how you can "attach it to a running process" as a major feature. The problem is, that seems to be the only way to use it on a local process. I want to be able to start my program in the profiler, and track its entire execution.

我尝试使用如何分析应用程序中所述的-Xrunjdwp选项用visualvm 启动,但是在两种传输方法(共享内存和服务器)之间,对我来说都没有用. VisualVM似乎与前者没有任何集成,VisualVM拒绝连接到localhost127.0.0.1,因此后者也不好.我还尝试将简单的System.in读入程序以在执行过程中插入暂停,但是在这种情况下,VisualVM会阻塞直到读完成,并且不允许您在执行开始后才能进行性能分析. 我还尝试研究 Eclipse插件,但是网站上充斥着无效链接,并且启动器在尝试使用NullPointerException时会崩溃,并且失败了.(这可能不再准确).

I have tried using the -Xrunjdwp option described in how to profile application startup with visualvm, but between the two transport methods (shared memory and server), neither is useful for me. VisualVM doesn't seem to have any integration with the former, and VisualVM refuses to connect to localhost or 127.0.0.1, so the latter is no good either. I also tried inserting a simple read of System.in into my program to insert a pause in execution, but in that case VisualVM blocks until the read completes, and doesn't allow you to start profiling until after execution is under way. I have also tried looking into the Eclipse plugin but the website is full of dead links and the launcher just crashes with a NullPointerException when I try to use it (this may no longer be accurate).

从C语言开始,这对我来说似乎不是一个特别困难的任务.我只是想念一些东西吗?还是这真的是不可能的要求?我愿意接受各种建议,包括使用其他(也是免费的)探查器,并且我不反对命令行.

Coming from C, this doesn't seem like a particularly difficult task to me. Am I just missing something or is this really an impossible request? I'm open to any kinds of suggestions, including using a different (also free) profiler, and I'm not averse to the command line.

推荐答案

考虑使用 HPROF 并使用 HPjmeter 之类的工具打开数据文件-或仅在您喜欢的编辑器中读取生成的文本文件.

Consider using HPROF and opening the data file with a tool like HPjmeter - or just reading the resulting text file in your favorite editor.

Command used: javac -J-agentlib:hprof=heap=sites Hello.java

SITES BEGIN (ordered by live bytes) Fri Oct 22 11:52:24 2004
          percent          live          alloc'ed  stack class  rank   self  accum     bytes objs     bytes  objs trace name
    1 44.73% 44.73%   1161280 14516  1161280 14516 302032 java.util.zip.ZipEntry
    2  8.95% 53.67%    232256 14516   232256 14516 302033 com.sun.tools.javac.util.List
    3  5.06% 58.74%    131504    2    131504     2 301029 com.sun.tools.javac.util.Name[]
    4  5.05% 63.79%    131088    1    131088     1 301030 byte[]
    5  5.05% 68.84%    131072    1    131072     1 301710 byte[]

HPROF能够显示CPU使用率,堆分配统计信息, 并监视竞争配置文件.此外,它还可以报告 完整的堆转储以及所有监视器和线程中的状态 Java虚拟机.

HPROF is capable of presenting CPU usage, heap allocation statistics, and monitor contention profiles. In addition, it can also report complete heap dumps and states of all the monitors and threads in the Java virtual machine.

这篇关于VisualVM中的配置文件整个Java程序执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆