Java 应用程序的性能分析器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3035601/
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
Performance profiler for a java application
提问by Nitin Garg
I need to optimise a Java application. It makes some 3rd party calls. I need some good tool to accurately measure the time taken by individual API calls. To give an idea of complexity- the application takes a data source file containing 1 million rows, and it takes around one hour to complete the processing. As a part of processing , it makes some 3rd party calls (including some network calls). I need to identify which calls are taking more time then others, and based on that, find out a way to optimise the application.
我需要优化 Java 应用程序。它会拨打一些 3rd 方电话。我需要一些好的工具来准确测量单个 API 调用所花费的时间。为了说明复杂性 - 应用程序需要一个包含 100 万行的数据源文件,完成处理大约需要一个小时。作为处理的一部分,它会进行一些 3rd 方调用(包括一些网络调用)。我需要确定哪些调用比其他调用花费更多时间,并在此基础上找出优化应用程序的方法。
Any suggestions would be appreciated.
任何建议,将不胜感激。
采纳答案by aioobe
I can recommend JVisualVM. It's a great monitoring / profiling tool that is bundled with the Oracle/Sun JDK. Just fire it up, connect to your application and start the CPU-profiling. You should get great histograms over where the time is spent.
我可以推荐JVisualVM。它是与 Oracle/Sun JDK 捆绑在一起的出色监控/分析工具。只需启动它,连接到您的应用程序并启动 CPU 分析。你应该得到关于时间花费的很好的直方图。
Getting Started with VisualVMhas a great screen-cast showing you how to work with it.
VisualVM 入门有一个很棒的截屏,向您展示如何使用它。
Screen shot:
截屏:
Another more rudimentary alternative is to go with the -Xprof
command line option:
另一个更基本的选择是使用-Xprof
命令行选项:
-Xprof
Profiles the running program, and sends profiling data to standard output. This option is provided as a utility that is useful in program development and is not intended to be be used in production systems.
-Xprof
分析正在运行的程序,并将分析数据发送到标准输出。此选项是作为在程序开发中有用的实用程序提供的,不打算在生产系统中使用。
回答by ewernli
I've been using YourKita few times and what quite happy with it. I've however never profiled a long-running operation.
我已经使用过几次YourKit,对它非常满意。然而,我从来没有分析过一个长期运行的操作。
Is the processing the same for each row? In which case the size of the input file doesn't really matter. You could profile a subset to figure out which calls are expensive.
每行的处理是否相同?在这种情况下,输入文件的大小并不重要。您可以分析一个子集以找出哪些调用是昂贵的。
回答by s5804
visualvm (part of the SDK) and Java 7 can produce detailed profiling.
visualvm(SDK 的一部分)和 Java 7 可以生成详细的分析。
回答by Michael Borgwardt
It sounds like a normal profiler might not be the right tool in this case, since they're geared towards measuring the CPU time taken by the program being profiled rather than external APIs that it calls, and they tend to incur a high overhead of their own and collect a large amount of data that would probably overwhelm your system if left running for a long time.
在这种情况下,听起来普通的分析器可能不是正确的工具,因为它们旨在测量被分析的程序所花费的 CPU 时间,而不是它调用的外部 API,并且它们往往会产生高开销。拥有并收集大量数据,如果长时间运行,这些数据可能会使您的系统不堪重负。
If you really need to collect performance data over such a long time, and mainly for external calls, then Perf4Jis probably a better tool.
如果你真的需要收集这么长时间的性能数据,并且主要用于外部调用,那么Perf4J可能是一个更好的工具。
回答by arcamax
In our office we use YourKit profiler on a day to day basis. It's really light weight and serves most of the performance related use cases we have had.
在我们的办公室,我们每天都使用 YourKit 分析器。它真的很轻,可以为我们拥有的大多数与性能相关的用例提供服务。
But I have also used Visual VM. It's free and fast. You may first want to give Visual VM a try before going towards YourKit (YourKit is not freeware).
但我也使用过 Visual VM。它免费且快速。在使用 YourKit(YourKit 不是免费软件)之前,您可能首先想尝试一下 Visual VM。
回答by Xorty
I use profiler in NetBeans(it is really brilliant and already built in, no need to install plugin) or JVisualVMwhen not using NetBeans.
当不使用 NetBeans 时 ,我在 NetBeans(它非常出色并且已经内置,无需安装插件)或JVisualVM 中使用分析器。
回答by Andy Fields
Try OPNET's Panorama software product
试用 OPNET 的 Panorama 软件产品
回答by Ivan Senic
Just wanted to mention the inspectIT tool. It recently became completely open source (https://github.com/inspectIT/inspectIT). It provides complete and detailed call graph with contextual information, there are many out-of the box sensor for database calls, http monitoring, exceptions, etc.
只想提一下inspectIT 工具。它最近变得完全开源(https://github.com/inspectIT/inspectIT)。它提供带有上下文信息的完整和详细的调用图,有许多开箱即用的传感器用于数据库调用、http 监控、异常等。
Seams perfect for your use-case..
接缝非常适合您的用例..