Java 应用程序分析
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22250303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java application profiling
提问by Arry
I am looking for a Java code profiler which I can use to profile my application (its a service which runs in backend) on production (so means low over head, and it must not slow down my application). Primarily I want calling tree profiling, that is if a() calls b() and then b() calls c(), then how much time a() b() and c() took, both inclusively and exclusively.
我正在寻找一个 Java 代码分析器,我可以用它在生产中分析我的应用程序(它是一个在后端运行的服务)(因此意味着低开销,并且它不能减慢我的应用程序的速度)。主要是我想调用树分析,也就是说,如果 a() 调用 b() 然后 b() 调用 c(),那么 a() b() 和 c() 花费了多少时间,包括和唯一的。
Have seen jvisualvm
and jprofiler
, but this is not what I am looking for, because I cannot tie my production application to them as it will cause a major performance issue.
已经看到jvisualvm
and jprofiler
,但这不是我要找的,因为我无法将我的生产应用程序绑定到它们,因为它会导致主要的性能问题。
Also, I did go through metrics
(https://github.com/dropwizard/metrics), but it does not give me a functionality to profile the calling tree.
另外,我确实通过了metrics
(https://github.com/dropwizard/metrics),但它没有给我分析调用树的功能。
Callgrind
(http://valgrind.org/docs/manual/cl-manual.html) type library is what I need, as it gives calling tree profiling functionality and advanced options like avoiding calling cycles (recursion). But I am not sure that Callgrind can be used on production as it dumps data when program terminates.
Callgrind
( http://valgrind.org/docs/manual/cl-manual.html) 类型库是我所需要的,因为它提供了调用树分析功能和高级选项,例如避免调用循环(递归)。但是我不确定 Callgrind 是否可以用于生产,因为它会在程序终止时转储数据。
Can anyone suggest good calling tree profiler for java that can be used on production without compromising the performance?
任何人都可以建议可以在不影响性能的情况下用于生产的 Java 的良好调用树分析器吗?
采纳答案by kc2001
Take a look at Java Mission Controlin conjunction with Flight Recorder. Starting with the release of Oracle JDK 7 Update 40 (7u40), Java Mission Control is bundled with the HotSpot JVM, so it is highly integrated and purports to have small effects on run-time performance. I have only just started looking at it, and I do see some call tree functionality.
结合Flight Recorder 来看看Java Mission Control。从 Oracle JDK 7 Update 40 (7u40) 的发布开始,Java Mission Control 与 HotSpot JVM 捆绑在一起,因此它高度集成并且声称对运行时性能的影响很小。我才刚刚开始研究它,我确实看到了一些调用树功能。
回答by Aaron Digulla
I don't know of any tool which can do profiling without an impact on performance.
我不知道有什么工具可以在不影响性能的情况下进行分析。
You could add logging to the methods that you're interested in. Make sure you include the time stamp in the log; then you can do the timing. You should also configure the logging framework to log asynchronously to reduce the performance loss.
您可以将日志记录添加到您感兴趣的方法中。确保在日志中包含时间戳;然后你可以做计时。您还应该将日志记录框架配置为异步记录以减少性能损失。
A load time weaver like AspectJis able to add these calls at runtime, which would allow you to easily select the methods you want to monitor without changing the source code all the time.
像AspectJ这样的加载时间编织器能够在运行时添加这些调用,这将允许您轻松选择要监视的方法,而无需一直更改源代码。
Using an around
aspect, you can even add timing logging, so you don't have to parse the logs and try to find matching log entries. See this blog post for details.
使用around
方面,您甚至可以添加计时日志记录,因此您不必解析日志并尝试查找匹配的日志条目。有关详细信息,请参阅此博客文章。
Have a look at perfspy(tutorial), it might already do out of the box what you need.
Related:
有关的:
回答by Andrew
Intel Amplifier XE http://software.intel.com/en-us/intel-vtune-amplifier-xehas got low overhead if any noticeable. It uses stack sampling technology to minimize the impact and it can attach and detach to running non-stop processes in production. You even do not need to have sources during profiling, you can dive into sources later after offline performance results browsing.
Intel Amplifier XE http://software.intel.com/en-us/intel-vtune-amplifier-xe 的开销很低(如果有的话)。它使用堆栈采样技术来最大程度地减少影响,并且可以连接和分离生产中运行的不间断流程。您甚至不需要在分析期间拥有源,您可以在离线性能结果浏览后深入了解源。
回答by cruftex
In general you don't (or I won't recommend) profilers that instrument your application. Instrumenting always means an uncontrollable production overhead.
一般来说,您不会(或者我不会推荐)分析您的应用程序的分析器。仪器仪表总是意味着无法控制的生产开销。
What you can use is a sampling profiler. A sampling profiler makes a snapshot of the stack traces at a controllable interval. What you don't get is call counts, but, after some runtime, you get a good overview where you have hotspots. Since you can adjust the sample interval of the profiler you can influence the overhead of it.
您可以使用的是采样分析器。采样分析器以可控的时间间隔对堆栈跟踪进行快照。您没有得到的是调用计数,但是,经过一段时间的运行后,您可以很好地了解热点所在的位置。由于您可以调整分析器的采样间隔,因此您可以影响它的开销。
A usable sampling profiler is shipped with the JDK, see the hprof page in the java 7 documentation. In former times there existed some graphical analysis tools for the hprof cpu traces (not the heap traces). Now they are gone. However, you can already work with the generated text file.
JDK 附带了一个可用的采样分析器,请参阅java 7 文档中的hprof 页面。以前有一些图形分析工具用于 hprof cpu 跟踪(不是堆跟踪)。现在他们走了。但是,您已经可以使用生成的文本文件。
I took a quick look on the Java Mission Control stuff mentioned above. I think it is quite mighty and will satisfy a lot of needs, in the white paper they say it has only 2% overhead. However, it is not totally what I personally need or want. For my applications it is better to have a "light" profiling enabled all the time.
我快速浏览了上面提到的 Java Mission Control 内容。我认为它非常强大,可以满足很多需求,在白皮书中他们说它只有 2% 的开销。然而,这并不完全是我个人需要或想要的。对于我的应用程序,最好始终启用“轻量级”分析。