Power Auto Analysis

By Rukhsana Yeasmin

A single application can drain a device’s battery and negatively impact consumers’ perception of a platform. Unlike performance, there is no natural market-driven motivation to make one’s application power-efficient. There may be a few exceptions where an application is so obviously flawed but more often than not apps will be sipping power with no one being aware. Hence, power efficiency is extremely important.

Developers want free and easy-to-use tools that may give some directions toward reasons behind high power consumption of an application. Windows Performance Analyzer can be used to trace the power data files. But the user needs to manually look through the entire trace to find potential problem areas, which might lead to a situation similar to searching for a needle in a haystack. Also the user needs some knowledge of what to look for. This is where the Power Auto-Analyzer can help. Here we are going after low hanging fruits. Our goal is to come-up with a list of functions consuming most of the CPU times and being called repeatedly during the idle times of an application and to show the statistics at the time regions of high CPU usage. Hence, someone using this tool will get some idea of possible problematic issues and may attempt to fix those.

The general assumption is that, during idle times a process should have minimal CPU activities resulting in lower power consumption. However, having high CPU usage during idle times is an indication of potential problem cases causing inefficient power use and there are rooms to power optimize the application by handling these issues. For example, use of Sleep API with low timeout value, busy wait may result in frequent context switches. Higher context switches cause more overhead to the system, prevent it to go to the idle state and thus increase the overall power consumption of the system. Excessive IO activity could result in larger number of interrupts and thus increase the power consumption rate. There could be several reasons behind high CPU usage and periodic activities during the idle times of a process. One possible way to figure it out is to search for the common call stacks during the times of high CPU usage and periodic events and then to look for the functions being called at those times.

Power auto-analyzer automatically detects the top power consuming threads in an application. If someone has an idle time trace of a process, he/ she can run the tool, which will automatically detect regions of high CPU usage and repetitions along with the common call stacks in those regions – to detect the top most CPU time consuming threads and functions being called at the peak regions of those threads in the application. It shows statistics of those regions that could also be interesting to the user. It lists all disk read/ write events initialization, completion, IO times and the IO paths for each thread of the application.

The algorithm detects high CPU usage areas by walking through the entire events trace of each thread of the given application file and looking for clustered regions of event occurrence or regions of very high CPU usage. If the region has multiple events in it, the algorithm runs an overlapping sliding window through each such clustered region and generates statistics of CPU usage and repetitions of the events inside the window. Sometimes it may show a single event as one region, if its CPU usage is very high compared to overall thread and process usage (in this case, the “Count” statistic should be 1). A region is considered to be a region of interest, if it has higher CPU usage and repetition compared to the overall application usage. The algorithm then merges successive overlapping windows inside a clustered region (based on CPU usage and repetition statistics) from the list of regions of interest to get the final clustered regions of interest. Finally it detects the common call stacks of the events in each such region by building a tree with context switched events call stacks, along with other useful statistics of those regions. The algorithm also generates disk IO statistics of each thread of the process of interest. The algorithm used “traceevent.dll” to parse the raw .etl trace files of an application.

Below is an example trace of an application having high CPU usage at idle times. From the figure (snapshot taken from WPA) we see there are periodic peak regions of high CPU usage. Events inside those regions were being called at an average of 5ms frequency. Tracking functions being called repeatedly at those regions will give some idea of potential reasons behind keeping the CPU busy at idle times and consuming more power.

CPU usage of the whole process of interest (time shown in secs.):

The most CPU time consuming thread (time shown in secs.):     

If we run power auto-analyzer for this trace, it will automatically detect the peak regions and find the common function call stacks and other statistics in these regions.

Output Regions from Power Auto-Analyzer:

Process Name: AfterMouse.race (Process ID: 1464) : : Thread ID: 2084

The regions having high CPU usage and the corresponding common call stacks are shown below:

Figure: Common call stacks at different peak regions of an idle analysis trace

In the above table, common call stacks for the detected peak regions are shown. “No common stack” indicates no match found in the call stacks of the events inside a region starting from the root function. Now, the user may look at the functions being called repeatedly at those high CPU usage regions. The program generates other useful statistics such as disk IO statistics, so if IO is a bottleneck, user may detect it by looking at the frequency of disk IO events, IO times and durations. In the above example the CPU usage peaks are quite clearly visible, but there are cases where it is hard to visually predict the problem regions. Our algorithm could successfully filter the desired regions in those cases too through comparative analysis of the CPU usage at different regions of a thread and the average CPU usage of that thread and the whole process.

The algorithm generates three output files:

    1) "CommonStacks_HighCPUUsageRegions.csv”: shows potential problem regions grouped by common call stacks, sorted by the average CPU usage of the regions.

   2)  "Statistic_HighCPUUsageRegion.csv": shows other statistics of the regions of interest shown in file 1, such as - region start, region end, percent of total events in the region belonging to this thread, average CPU usage, number of events count, mean time interval of events occurrence, coefficient of variation of the time intervals of events occurrence.

   3) "DiskIO_Statistics.csv": shows the disk IO events statistics of each thread of the process of interest, i.e. IO type, IO initialization time, IO completion time, Time spent in IO, IO path.

These files will provide statistics of high power consumption areas during idle times of an application.

Power auto-analyzer is a free and easy to use tool, which will direct the user toward potential problem areas by analyzing an idle trace file of a particular application. The user may use this information to fix issues in an application which are keeping the CPU busy at idle times and thus resulting in high power usage.

Descargar PowerAnalyzer.zip2.06 MB
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.