Jprofiler - CPU profiling
Jprofiler can serve many purposes, and CPU profiling and analysis is one of them.
This article is more about how to analyze the collected CPU profile data rather than collecting the data(which is pretty straight forward).
Below are a few points to note while analyzing a CPU profile:
(note: The callStacks have been blacked out purposely)
- After collecting the profile, it is ideal to select the "Thread Status" as "All States" to begin with. This makes sure that you don't miss out on the Threads that might be culprits, but are not in Runnable state.
2. Take a quick look at hotspot section to see if there is something that is obvious and wrong. The hot spots view shows a list of calls of a selected type. The list is truncated at the point where calls use less than 0.1% of the total time of all calls. The methods can be sorted based on self-time here and seen if there is any one particular method taking more than necessary time at a glance.
3. Take a look at Threads section, and see if there is any one particular thread that is doing all the work. If yes, and if that is one doing most of the work that you are interested in, then you can set it as root and reduce the noise of other non-required calls.
4. Now go through the CPU call tree and find the method that corresponds to your run which is consuming most of the CPU time and one that looks fishy.
5. Set this method as root (this will reduce the noise of other methods) and subject it to further analysis. (right click > set as root)
-NOTE : This root selected is applied through all the tabs. To see all the calls in any tabs, you need to first remove this root.
6. Next, you can > right click, analysis, calculate cumulative outgoing calls. This is helpful because, in the regular call tree you will see the calls going out of out of the method for only that particular call stack. But by checking cumulative outgoing call, you can check the all outgoing call from the particular method.
7. As a compliment to "calculate cumulative outgoing calls" you can also check "calculate backtrace to selected method".
a. This instead of showing the outgoing calls from the method like above, it shows the backtrace that contribute to the invocation of the selected method.
b. Back trace analysis has total time and self-time selection options on the top, much similar to the options in hotspot view
8. Also, it will be interesting now to see the hotspot section, as there will be fewer methods and only the methods of your interest now, due to the root set in step 5. I will show only the hot spot methods under this root.
9. Once you have narrowed down to the method that is taking time, you can use the option "show call graph" to see a pictorial view of inbound and outgoing call from it.
Hope this helps.
Nice ??