Reputation: 1915
I'm writing a java application that reads input, populates data structures, and then does some computations on them. I want to optimize the final computation part, because with real, large inputs it dominates execution time. Profiling the whole application with giant inputs would take forever. So, I load a moderate-sized input for performance testing, but then input and preprocessing time dominates the profile.
How can I profile just the part of a java application I care about? Is there a way to say "only profile these two classes," or programmatically insert "start profiling here" directives?
Upvotes: 1
Views: 2020
Reputation: 48090
As for profiling only selected classes, most profilers allow to set up filters, so that only a couple of classes are instrumented.
In your case, it sound like you would also like to start and stop profiling when a particular method is called.
In JProfiler, you can add a method trigger for the desired method and add 3 actions to the trigger:
Have a look at this screen cast that shows how triggers are configured.
Disclaimer: My company develops JProfiler.
Upvotes: 0
Reputation: 17341
You can use VisualVM to profile your code. I don't know about only profiling specific classes, but VisualVm can start watching programs that are already running. Also, if you are using Eclipse, there is a launcher that can be used to start and attach the profiler to your program when you start it from Eclipse.
EDIT:
I did some looking and the Profiler tab has a Settings check box. When you select this, it will show a text box where you can set up filters on what classes should be profiled for CPU usage.
Upvotes: 1
Reputation: 533750
I assume you have unit tests and you can construct a unit test or application which just does the portion you are interested in profiling. This way you can performance tune this alone because its the only thing running.
Upvotes: 0