Getting Started with Intel Energy Profiler for Android

Original author: Bill
  • Transfer
  • Tutorial
If a certain application consumes more power than a competing one, users will notice this very soon and make the appropriate choice. Therefore, it is vital for each developer to ensure that his programs take care of the batteries of tablet PCs and smartphones. The tools included with Intel System Studio can help with this important business.



Overview


Intel VTune Amplifier for specialized systems allows you to optimize the power consumption of applications designed for embedded Linux platforms for Android and Windows operating systems. This is done thanks to the analysis, which is carried out using the Intel Energy Profiler.

By understanding energy consumption, you can identify application scenarios that waste battery power. The end result of the analysis is code optimization and a significant increase in the life of the device from a single charge.

Intel Energy Profiler allows you to monitor how the device operates in low-power modes and analyze the reasons for exiting these modes. The profiler is able to help in the study of changes in the processor clock frequency. This also helps to identify system power problems. In addition, data visualization is supported, which allows you to quickly see and evaluate the improvements made to reduce energy consumption.

Target platform and host system


This article discusses the power profiling process on the target Android platform using the tools included with Intel System Studio installed on a Windows computer. The material also includes comments about the features of working with a system that is installed on Linux. A system installed on Mac OS will work in a similar way, however, we did not experiment on a Mac. The screen copies that are available in the article were made on a computer running Windows.

Check for the necessary drivers


There are several components responsible for working with Android devices in Energy Profiler.

The first is Android kernel level drivers, which require a system permission level. Best of all, if these drivers were built with the kernel and are already present on the device. So you can be sure that they have the necessary permissions.

The next component is a low-level application that interacts with drivers. You can work with the application through the command line. In particular, to collect data from the device. This application is commonly referred to as the Intel SoC Watch Data Collector. It is accessed using the socwatch command, the collector can be installed on the device using an ADB script.

And finally, a component for data visualization, which is built into the Intel VTune Amplifier user interface. It is perfectly acceptable to collect energy analysis data using the Intel SoC Watch via the command line and process the information manually without using the Intel VTune Amplifier graphical tools. That is why many works on optimizing power consumption refer only to the Intel SoC Watch, but not to the Intel Energy Profiler.

In order to find out whether the driver you need is installed on the device you are going to work with, as well as which version of the data collection tool is needed, you need to open the adb shell and check if there is any / lib / modules / or / in the directory system / lib / modules / driver file SOCWATCHx_x.ko.


Example of checking the device for the presence of the SOCWATCH driver

After checking, it turned out that on the device that we use in this example, the driver is already included in the system image. It is located at /lib/modules/SOCWATCH1_3.ko. The driver file name allows us to understand which version of Intel SoC Watch should be used to collect data. This is version 1.3.

If it turned out that the file name looks like SOCWATCH1_5.ko, we would have to use Intel SoC Watch version 1.5. Please note that in Android Lollipop the driver will most likely be located in the / system / lib / modules folder. However, on this version of Android it is worth checking both folders. For example, on an Asus Fonepad 8 tablet computer with an Intel Atom Z3530 CPU updated to Android 5.0, the driver was found in the / lib / modules / folder.

If the necessary driver cannot be found in the system, it must be included in the kernel during assembly. This is beyond the scope of this article. Useful information on this topic can be found in the user manual in the “Building the Kernel Modules” section. Below we will talk about where to find this guide. Particular attention should be paid to ensure that the driver has the same signature as the system core, or - it should be possible to provide the driver with system-level permissions.

Install data collection application


Now, when after checking the driver it became clear which version of the data collection application should be used, it was time to install this application on the device. Please note that you need to install the application on each analyzed device only once.

Locate the system_studio_target.tgz file. It is located in the Intel System Studio installation folder. The path to the directory where it is located may look like/ Targets. Hererepresents the folder where System Studio installation was performed. When using Windows, this is usually "C: \ Program Files (x86) \ Intel \ System Studio yyyy.x.xxx". On Linux, “opt / intel / system_studio_yyyy.x.xxx”.
Here yyyy.x.xxx is the version number of the set of installed applications. The aforementioned .tgz archive contains the files that are needed for host systems running Windows or Linux. The archive should be unpacked somewhere, where it will be easy to find its contents. In our case, it was unpacked into the directory “C: \ Users \ Public \ ISS-2015_SoCWatch”.

If you are already using the beta version of Intel System Studio 2016 , the file you need can be found at "C: \ Program Files (x86) \ Intel_sw_development_tools \ system_studio_2016.x.xxx \ Targets".

Using the command line, navigate to one of the newly unzipped folders, whose name corresponds to the version of the Intel SoC Watch driver that was previously identified on the device. In our case, this is the folder "C: \ Users \ Public \ ISS-2015_SoCWatch \ system \ studio \ target \ socwatch_android_v1.3d \".

Please note that in this folder you can find the User Guide, which contains a lot of useful information. In particular, here you can find descriptions of the options available for a specific version of the data collector and a quick start guide that covers most of what we are talking about here. The manual also contains information on how to analyze the results.

Make sure that the Android device is connected to the computer via USB and run the installation script. When working on Windows, you need to run the batch file socwatch_android_install.bat. On Linux, you'll need the shell script socwatch_android_install.sh. If you have already used these scripts, you will see a message stating that the installation failed. Therefore, if you accidentally installed the wrong version of the Android application, before installing the necessary version, you will need to remove the / data / socwatch folder from the device using adb shell. If successful, you will see a list of files being copied to the device.


Installing a data collector on a device

Data collection


The collection of data for analysis, in the simplest form of this process, consists of three steps. The first is setting up the environment. The second is loading the driver. The third is to run a script that collects data.

Environment setting


This step must be performed every time a new ADB connection is made to the data collection device.

Connect to the device using ADB and go to the / data / socwatch directory. Here you will find the setup_socwatch_env.sh script. Run the script. During its operation, the current environment settings will be shown on the screen. In addition, among the displayed data, you will see a reminder that you need to download the driver, but we will do this in the next step. And now we need the following commands:

source ./setup_socwatch_env.sh

or

. ./setup_socwatch_env.sh



Setting up the environment for collecting data using a shell script

Driver download


This should be done every time before data collection if the device is rebooted. At the same time, if a new connection is made to the prepared device through the ADB shell, the driver does not need to be reloaded.

At this step, a driver is loaded into the device’s RAM, the detection of which on the device was done above. This is done using the insmod command. In our example, the driver is located at /lib/modules/SOCWATCH1_3.ko, it is present on the device and can be downloaded for further work. For greater certainty, you can check again if the driver is loaded. This is done using the lsmod command. Here is an example of its use:

insmod /lib/modules/SOCWATCHx_y.ko



Download and confirm driver download socwatch

Some versions of socwatch require the download of an additional driver (socperf_xxx.ko). Whether it is true or not, it will be indicated after the set_socwatch_env.sh script has been executed.

Running a script to collect data


This step must be performed every time a new data file is required for analysis. The exact launch parameters will vary depending on the version of the data collector used, on the capabilities of the device and on the necessary set of information that needs to be collected for analysis. You can get a brief help on working with this tool using the --help option. The following is an example of starting socwatch.

./socwatch --max-detail -f cpu -s 5 -t 30 -o ./results/GSG_examplerun



Starting data collection

Here the program collects information about the C-states and P-states of the processor core, waiting 5 seconds before the data collection begins. The collection is carried out within 30 seconds. The results are displayed in the / data / socwatch / results / folder, with the file names starting with “GSG_examplerun”.

Please note that connecting an Android device to a computer via a USB cable is very likely to affect the device’s power consumption mode. Therefore, the cable is often disconnected immediately after the command is started, but before data collection begins. This can be done, for example, using the background task and the nohup command. The appropriate command might look like this: "nohup ./socwatch &". After it is completed, the cable can be disconnected.

It is often highly desirable that data be collected only when a particular application is running. This can be achieved using the socwatch “-p” parameter. You can learn more about this technique from the user manual or by using the --help switch.

Visualize Results with VTune Amplifier


In order to analyze the data collected using Intel VTune Amplifier, we need to go through two more steps. Namely, copy the files with the collected data from the device and import them into the application.

Copy files from device


In order to copy files from the device, you need to use the command line to go to the computer directory where you can save these files. It is recommended that this be a folder other than the one in which Intel VTune Amplifier projects are stored. The fact is that upon import, these files will be automatically copied there, so it is best to transfer them from the device to some temporary directory.

If you omit this step and try to go directly to the files on the device (for example, the beginning of the path to them may look like “devicename / internal storage / data”), you will not be able to work with them due to various restrictions related to permissions.

When you go to the temporary directory on the command line where you want to copy files from the device, use the adb pull command. If you don’t remember the exact file names, you can get a list of them with a command like “adb shell ls / data / socwatch / results”. Here are examples of commands with which we copied the necessary files:

adb pull /data/socwatch/results/GSG_examplerun.csv
adb pull /data/socwatch/results/GSG_examplerun.sw1



Copying files with test results to a computer

Import data into VTune for further analysis


At this step, we only need a file with the extension .sw1, which was copied from the device. The .csv file (comma separated values) is a text file with the results, it can be used as a data source for your own data analysis scripts or other tools.

Launch the Intel VTune Amplifier app and download the project you want. If you are not familiar with this product, see the article Getting Started with Intel VTune Amplifier for Specialized Systems or some similar manual. On the “Welcome” tab, click on the link “Import Result ...”. You can do otherwise - go to the “Energy Analysis” group, which can be found in the “Analysis Type” section of the “New Analysis” tab, and click “Import Data”.

Please note that the above steps apply to Intel System Studio 2015 Update 1 or later. If you are using an earlier version of Intel System Studio, you may need to use the command line tools to import the data.


Importing data from the Welcome tab


Importing data from the analysis type selection screen

In both cases, the next step is the Import a File and Create a Result tab. It will have a field in which you can specify the path to the .sw1 file copied from the device that you want to import into the application.


Tab for selecting a file for import

After a file is selected, click on the Import button and observe how the program analyzes and displays data that can be viewed.

Interpretation of Results


Which data will be available for analysis depends heavily on the hardware of the device under test, on the version of the data collector and command line parameters used to collect the information.

When loading the results, the "Platform Power Analysis" view mode will be selected by default (usually there are no other options), the "Summary" tab will be displayed. On this tab, you can find useful information such as "Elapsed time", that is, the test time, and the operating time of the processor cores (usually this is the number of cores times the test time). There is also information about events (events per second per core) that cause the processor to exit the low-power mode. On the same tab, you can find information about the frequency of active nuclei and the causes of events that “wake them up”.

Here is an example of analyzing the data obtained after using this command:

./socwatch --max-detail -f cpu -f device -f sys -t 30 -s 5 –o ./results/idleasleep

The device was connected to the computer via a USB cable, was in locked mode, the screen was turned off. As expected, the results indicate that it consumed very little energy.


Data on a device that was in sleep mode

Another useful bookmark is Correlate Metrics. Here you can see the time layout for various states and events. Here you can easily zoom in on the desired length of time and explore the exact time frame of events and how they relate to each other. In addition, note that if you hold the mouse pointer over the area of ​​interest for a while, you can see a pop-up message with more detailed information. This moment is shown in the following figure.


Viewing data on the System Correlate Metrics tab

If necessary, you can compare the results of two tests in the same window. For example, such a technique makes it easy to compare the results of two data collections performed with the same conditions. They do this in order to check if there are any improvements, or to make sure that the results obtained earlier can be reproduced.

To compare the results of two tests, first you need to separately import both data sets into the application, then close their data analysis tabs. At this step, it is recommended to rename the analysis results in the Project Navigator window so that it is more convenient to work with them, however, this is not necessary. Then you need to use the “Compare Results” icon and indicate which particular analysis results should be compared. The application will show both sets of analytical data in one window, where they can be compared. Here is an example of comparing two datasets obtained from various tests.


Comparison of the results of several tests: general information


Comparison of the results of several tests: reasons for the processor to exit the low-power mode

Summary


We examined an example of using Intel System Studio tools for analyzing the power consumption of devices running on the Android platform. Now you have everything you need to start analyzing and optimizing your applications.

Homework


» Intel VTune Amplifier 2015 Documentation
» Optimization and Productivity Guides

Also popular now: