Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.
This is aimed at developers who have access to licensee prototypes and certain levels of SDK or are using reference boards.
The Sampling Profiler can be used to provide a rough, statistical view of software activity on a device. It does this by logging the thread ID and current Program Counter value at one millisecond intervals. It is accompanied by a command line-based program that can be used to analyse this data on a PC. This information can then be used to investigate performance problems, and inform code inspection of likely bottlenecks.
Build the ROM
To use the profiler, it first has to be added to the ROM. This can be done by adding ‘profiler.iby’ to the buildrom command line;
buildrom h4hrp techview profiler.iby
Start the Profiler
The simplest way to control the profiler is from eshell. A command line such as:
start profiler start
This starts another thread that the profiler application runs in so you can switch back to other tasks using the <Control><Alt><Shift><T> key combination.
Run the code you wish to profile
At this point the profiler will be running, and gathering samples. A short pause before starting the code to be analyzed can help the thread activity analysis phase by visually separating out the various chunks of processing shown.
Stop the Profiler
After you have profiled what you need, switch back to the eshell and stop the profiler;
And then to close the profiler data file;
Retrieve the profile data
You should have a file, profiler.dat, in the root of the C drive of the reference board. You can copy it to the MMC card and transfer it back to the build machine for analysis.
Analyze the data by activity
You should convert the data to a form suitable to be displayed in Excel in order to generate a graph, so you get an overall picture of the activity of the software you have profiled.
Copy the profile file
Copy it to the ROM folder as you need the symbol table to extract the names. Create the activity format file by running the following command:
analyse –r h4hrp_001.techview.symbol
profiler.dat -v –mx > profile.xls
Create the activity graph
Open profile.xls file in Excel. To ensure the graph shows the thread names, delete the first six rows of the data. This is summary data and will mess up the graph if it is included. Similarly, the time stamps in the first column will mess up the graph but you cannot delete them as they are needed to cross reference the areas of the graph that you are interested in to the actual times.
Select all of the data and then click on the "chart wizard". This opens up a four-stage wizard:
- select "Area" from chart type and "Stacked" from the sub-type, select "Next"
- adjust the area to miss out the time stamp in the first column. Change the A to a B. E.g.
=profile!$A$2:$V$941 gets changed to
=profile!$B$2:$V$941, select "Next"
- ignore the next pane and press "Next", select "As new sheet" and press "Finish".
Select the active section and threads
By looking at the graph created, you should be able to work out what your program was doing and when, allowing you to locate the area you are interested in. You can hover over the data area with your mouse and a pop-up window will tell you which thread was running at that point. You can then use the row number of the point to find its timestamp by looking at the value in the first column of the same row number in the data sheet. Additionally, you can delete rows you are not interested in. Remember that Excel will renumber the rows so delete the end of the range first. The graph will be redrawn with the new data.
Create a listing by function
Once you know the range of timestamps and within which thread they occurred, you can create a list of the functions ranked in order of the activity. For example, if you were interested in what functions were called between the 51300 and 76900 timestamps in the EFile thread, you would use the following command:
analyse –r h4hrp_001.techview.symbol
profiler.dat -bf –p –s51300-76900 –t EFile* >
- the sample range has no spaces after the –s or between the two numbers in the range and the hyphen separating them
- the sample range is the timestamps that come from the first column of the datasheet used to create the activity graph
- the thread name does have a space after the –t, and can include wildcards both at the beginning and the end of the name.
You can read the output file into a text editor (such as Notepad) where you will find the list of functions in the timestamp range selected. Usually, the top five or so functions will be of interest. You can then go to an IDE and inspect the relevant sections of code.