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?
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.