9.5. Optimizing Process CPU Usage
When a particular process or application has been determined to be a CPU bottleneck, it is necessary to determine where (and why) it is spending its time.Figure 9-3 shows the method for investigating a processs CPU usage.
Figure 9-3.
9.5.1. Is the Process Spending Time in User or Kernel Space?
You can use the time command to determine whether an application is spending its time in kernel or user mode. oprofile can also be used to determine where time is spent. By profiling per process, it is possible to see whether a process is spending its time in the kernel or user space.If the application is spending a significant amount of time in kernel space (greater than 25 percent), go to Section 9.5.2. Otherwise, go to Section 9.5.3.
9.5.2. Which System Calls Is the Process Making, and How Long Do They Take to Complete?
Next, run strace to see Section 9.9.
9.5.3. In Which Functions Does the Process Spend Time?
Next, run oprofile on the application using the cycle event to determine which functions are using all the CPU cycles (that is, which functions are spending all the application time).Keep in mind that although oprofile shows you how much time was spent in a process, when profiling at the function level, it is not clear whether a particular function is hot because it is called very often or whether it just takes a long time to complete.One way to determine which case is true is to acquire a source-level annotation from oprofile and look for instructions/source lines that should have little overhead (such as assignments). The number of samples that they have will approximate the number of times that the function was called relative to other high-cost source lines. Again, this is only approximate because oprofile samples only the CPU, and out-of-order processors can misattribute some cycles.It is also helpful to get a call graph of the functions to determine how the hot functions are being called. To do this, go to Section 9.5.4.
9.5.4. What Is the Call Tree to the Hot Functions?
Next, you Section 9.9.
9.5.5. Do Cache Misses Correspond to the Hot Functions or Source Lines?
Next, run Section 9.9.
Optimizing Linux® Performance: A Hands-On Guide to Linux® Performance ToolsBy
Table of Contents
| Index