Using Microsoft Profiler to identify performance issues in your ATOM App

BrianDevArch's picture

When it comes to writing a great application for the netbook there are many attributes we strive for including a slick user interface, a rich feature set and on this platform most of all... PERFORMANCE.

Sure, a stellar user interface and dazzling eye candy will get an initial purchase, but it is the efficient code behind the scenes that pulls it all together into a smooth customer experience.

One errant CPU hogging loop or memory leak and your beautiful application slows to a crawl. I have given a few tips on writing optimized code in another blog post, and this post aims to build on that subject by locating the source of existing performance woes. Read on as we explore a simple tool which aims to speed up your ATOM Netbook applications.

What is profiling?

In a nutshell, profiling allows you to analyze your program in real time (while it is running) as opposed to a static analysis of your code. This pinpoints memory management issues and long running method calls, allowing you to step in and make changes to improve performance.

Why profile on the netbook platform?

As ATOM SDK developers we enjoy creating applications which target an amazing hardware architecture. Lengthy battery life, and extreme portability are brought to us thanks to the ATOM CPU. Because netbook hardware is highly optimized, we must ensure our code is up to the task at hand and compliments it. Inefficient code will decrease battery life and degrade overall system performance; this is where profiling steps in. By profiling our netbook applications we can identify performance offenders and ensure our users enjoy our offering (and their netbook).

Microsoft Visual Studio Profiler to the rescue!

Look no further than your copy of Microsoft Visual Studio 2008 for a free and effective profiling tool. Profiler is included in Team Suite versions of Visual Studio, and downloadable as a stand alone tool for other versions. Think of Profiler as a command line tool that logs key performance data. How do we analyze the results you ask?

There is a complementary tool called PerfConsole written by Josh Williams at Microsoft. This handy tool analyzes the data gathered by Microsoft Profiler into easily digestible reports.
* If you have Visual Studio Team Suite this is done automatically for you

Getting started with Visual Studio Profiler

The Visual Studio Profiler is available from within the Visual Studio IDE if you have the Team Suite version. For everyone else (or should you prefer external tools), you may download a stand alone CLI (command line interface) version which is not as pretty by just as powerful.

For the following instructions I am going to explain the basic steps required to use the stand alone version. These steps are high level and provide links to further details.

1.) Acquire Profiler and PerfConsole

Download and install Profiler (Microsoft Profiler)

* Further installation instructions: How to: Install the Stand-Alone Profiler

Download and install Performance Console (Performance Console aka PerfConsole)

* Performance Console provides an easy to use CLI for profile data analysis. Documentation is found in your local install folder: ~\docs\PerfConsole.doc

2.) Choose between sampling and instrumentation profiling methods. Please see 'Further Reading' section below for more detail. Be sure to create a simple test plan, outlining the application interactions you will execute during your profiling session. This will help to expose any hidden performance bottlenecks.

3.) Execute Profiler to gather performance data. This data will be analyzed later using PerfConsole. Please ensure you have adequate disk space before you begin profiling. Profile log files tend to be large (into the GB in some cases), so a hard disk with plenty of space is advised.

  Profiler Quick Start:

  A.) Enable profiling in your application. In the Linker properties for your project, set the 'Profile' value to 'Enable'

  B.) From a command prompt set the path to Profiler.
  Since we do not use 64-bit on the netbook platform we will only setup the path to the 32-bit version of Profiler:

  set path=%path%;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Team Tools\Performance Tools

  * Please start your command prompt with elevated permissions to allow the Profiler will run correctly

  c.) To run an instrumentation profiling session on your application we need to prepare the binary. We do this using the vsinstr.exe utility:

  vsinstr.exe MyAtomApp.exe

  * A backup of your application will be created automatically

  D.) Start Profiler:

  vsperfcmd /start:trace /output:MyAtomApp.vsp

  E.) Run your application. Ensure you follow your test plan (created in step 2). This will ensure that you capture as much detail as possible, making it easier to locate any defects.

  F.) Stop Profiler:

  vsperfcmd /shutdown<./i>

  G.) Execute vsperfreport.exe to generate a rudimentary report which can be viewed in Excel. You may output the results to an alternate path if desired:

  vsperfreport MyAtomApp.vsp /output:c:\temp /summary:all

  Further Details:
  MSDN VSPerfCmd
  MSDN VSPerfReport

4.) Use PerfConsole to process the data collected in step 3. You will be presented with a series of result graphs, from which you may identify expensive methods or memory issues.

What to do with those results

That wasn't terribly painful, now the rewards are just around the corner. We now venture back into familiar territory, our environment. Get back into Visual Studio and begin optimizing our code, and/or mitigating those memory issues. Once completed, test your changes by running Profiler again and measuring the improvement. Repeat this as needed until your application is running smoothly and efficiently.

Further reading

Profiling is a large topic, and thankfully there are many articles discussing how to use it to pinpoint performance issues. Please find below a
few links to get you started:
Walkthrough: Command-Line Profiling Using Sampling

Walkthrough: Command-Line Profiling Using Instrumentation

More details on PerfConsole

Please feel free to stop by the Developer Forum if you have any questions, best of luck in your ATOM SDK endeavors.

5
Average: 5 (3 votes)
9Kviews

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Posted On : November 11, 2010 - 05:18
Garcia Mendez (not verified)

Thanks. This page helped me a lot!

Posted On : January 19, 2011 - 05:02
Nayan's picture
Offline
Last seen: 1 year 2 weeks ago
Joined: Jan 14 2011
Points: 3620

Very good Topic.It also helped me a lot.

:-)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.