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?

Charlie Martin
  • 110,348
  • 25
  • 193
  • 263
Dan Snyder
  • 1,483
  • 7
  • 20
  • 29

3 Answers3

4

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.

Amir Afghani
  • 37,814
  • 16
  • 84
  • 124
1

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.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • This is a helpful viewpoint. The final goal of this project is not to optimize this code though. The real goal is to determine where and when an FPGA can be used to speedup the overall process time of this program. So in reality, I want to get a good idea about what is important for the running of my program, so I can determine the proper insertion point for hardware acceleration. – Dan Snyder Nov 08 '10 at 05:09
  • @Dan: Interesting. In your shoes, I *would* optimize the code, though, because while hardware acceleration is nice, you don't know, there could be a factor of 5 just waiting to be picked up for free. When you've squeezed out all the juice possible from the code, then samples will show exactly what's taking the bulk of the time, and where hardware acceleration would help. I've been in situations like that. Good luck. – Mike Dunlavey Nov 08 '10 at 13:04
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.

Charlie Martin
  • 110,348
  • 25
  • 193
  • 263
  • Thanks, Ideally I would just like some concrete information about how Nutch spends it's time, specifically when using Lucene calls. I'll definitely look through some profiler's. This is my first experience with such software. – Dan Snyder Nov 07 '10 at 08:36