Analyze Code

You identified the critical section that caused significant Wait time and poor processor utilization. Double-click this critical section in the Bottom-up pane to view the source. Intel® VTune™ Amplifier opens source and disassembly code. Focus on the Source pane and analyze the source code:

  1. Understand basic options provided in the Source window.

  2. Identify the hottest code lines.

Understand Basic Source View Options

The table below explains some of the features available in the Source pane for the Locks and Waits viewpoint.

Source window toolbar. Use hotspot navigation buttons to switch between most performance-critical code lines. Hotspot navigation is based on the metric column selected as a Data of Interest. For the Locks and Waits viewpoint, this is Wait Time: Self by Thread Concurrency. Use the source file editor button to open and edit your code in your default editor.

Source code of the application displayed if the function symbol information is available. When you go to the source by double-clicking the synchronization object in the Bottom-up pane, the VTune Amplifier opens the wait function containing this object. The source code in the Source pane is not editable.

If the function symbol information is not available, the Assembly pane opens displaying assembler instructions for the selected wait function. To view the source code in the Source pane, make sure to build the target properly.

Processor time and concurrency bar attributed to a particular code line. The Self Time metric shows the time the application spent at this particular source line while the Total Time includes Self time of the function itself and Self time of all functions that were called from that function, if any.

The colored bar represents the distribution of the Wait time according to the concurrency levels (Idle, Poor, Ok, Ideal, and Over) defined by the VTune Amplifier. The longer the bar, the higher the value. Ok level is not available for systems with a small number of cores.

Number of times the corresponding system wait API was called while this code line was executing. For a lock, it is the number of times the lock was contended and caused a wait.

Wait Time during which the CPU was busy. This often occurs when a synchronization API causes the CPU to poll while a software thread is waiting. Some Spin Time may be preferable to the alternative of increased context switches. Too much Spin Time, however, may reflect a lost opportunity for productive work.

Identify the Hottest Code Lines

For the sample code, the VTune Amplifier highlights line 166 entering the rgb_mutex mutex in the draw_task function. The draw_task function was waiting for almost 54 seconds while this code line was executing and most of the time the processor was underutilized. During this time, the critical section was contended 508 times.

The rgb_mutex is the place where the application is serializing. Each thread has to wait for the mutex to be available before it can proceed. Only one thread can be in the mutex at a time. You need to optimize the code to make it more concurrent. Click the Source Editor button on the Source window toolbar to open the code editor and optimize the code.

Key Terms

Next Step

Remove Lock

For more complete information about compiler optimizations, see our Optimization Notice.