分析 Java 代码

发布于 2024-09-30 13:34:57 字数 127 浏览 1 评论 0原文

我正在尝试从源代码分析一个名为 Nutch 的 Java Web 搜索程序。据我了解,要进行分析,我需要在编译器中启用分析,以便生成要在 GProf 等程序中打开的配置文件。如果我编译软件的所有操作都是在源根目录下运行 ANT,我该怎么做?

I'm attempting to profile a Java web search program called Nutch from source. As far as I understand, to profile, I need to enable profiling in the compiler in order to generate a profile file to be opened in a program such as GProf. How do I do this if all I do to compile the software is run ANT withing the source root directory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅语花开 2024-10-07 13:34:57

如果您运行的是较新的 JDK(最新的 1.6 update 7 或更高版本),则无需执行任何操作即可准备要分析的 Java 进程。只需使用 JVisualVM (随 JDK 一起提供) ) 附加到您的流程,然后单击配置文件按钮。

If you're running a newer JDK (the latest 1.6 update 7 or greater), you don't need to do anything as far as preparing your Java process to profile. Simply use JVisualVM (which comes with the JDK) to attach to your process, and click the profile button.

清浅ˋ旧时光 2024-10-07 13:34:57

您在回复 @Charlie 的回答时说,理想情况下您希望了解有关程序如何该程序花费时间的信息。

还有另一种观点 - 您需要知道程序为什么花费时间。

每个周期花费的原因是一系列原因,其中每个链接都是调用堆栈上的一行代码。这条链条并不比它最薄弱的一环更坚固。

除非程序尽可能快,否则就会遇到“瓶颈”。

例如,如果“瓶颈”浪费了 20% 的时间,那么它由 20% 的时间位于堆栈上的可优化代码行(即不合理)组成。您所要做的就是找到它。

如果从堆栈中采集 10,000 个样本,则将在其中大约 2,000 个样本上进行采样。如果抽取 10 个样本,则平均为其中 2 个样本。

事实上,如果您随机暂停程序几次并研究调用堆栈,如果您在少于 2 个样本 上看到可优化的代码行,那么您就发现了“瓶颈”。
您可以修复它,获得不错的加速,然后重复整个过程。

这是 这种技术

无论如何,根据gprof概念进行思考是行不通的你很好。

You say in response to @Charlie's answer that ideally you would like information about how the program spends it's time.

There's another viewpoint - you need to know why the program spends its time.

The reason each cycle is spent is a chain of reasons, where each link is a line of code on the call stack. The chain is no stronger than its weakest link.

Unless the program is as fast as possible, you've got "bottlenecks".

For example, if a "bottleneck" is wasting 20% of the time, then it consists of an optimizable line of code (i.e. poorly justified) that is on the stack 20% of the time. All you have to do is find it.

If 10,000 samples of the stack are taken, it will be on about 2,000 of them. If 10 samples are taken, it will be on 2 of them, on average.

In fact, if you randomly pause the program several times and study the call stack, if you see an optimizable line of code on as few as 2 samples, you've found a "bottleneck".
You can fix it, get a nice speedup, and repeat the whole process.

That is the basis of this technique.

Regardless, thinking in terms of gprof concepts will not serve you well.

誰ツ都不明白 2024-10-07 13:34:57

你在这里确实是在问一个 Ant 问题。您可以将编译器的命令行标志添加为编译目标的 ant 文件中的属性。请参阅此处 标记。

顺便说一下,有很多好的分析工具。查看此 Google 搜索

You're really asking an Ant question here. You can add command line flags for the compiler as attributes in the ant file for the compile target. See the <compilerarg> tag here.

There are a lot of good profiling tools, by the way. Have a look at this google search.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文