2

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?

4

3 回答 3

4

如果您运行的是较新的 JDK(最新的 1.6 更新 7 或更高版本),您无需做任何事情,只要准备您的 Java 进程以进行分析。只需使用JVisualVM(JDK 附带)附加到您的进程,然后单击配置文件按钮。

于 2010-11-06T06:18:40.490 回答
1

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

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

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

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

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

如果对堆栈进行 10,000 个样本,它将在其中大约 2,000 个样本上。如果抽取 10 个样本,平均会在其中 2 个样本上。

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

那是这项技术的基础。

无论如何,从gprof概念的角度思考对你没有好处。

于 2010-11-07T17:26:43.083 回答
0

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.

于 2010-11-06T06:07:32.003 回答