Wednesday, January 12, 2011

Profiling of C++ - Applications in Visual Studio for free

Introduction

While the Team- or Premium-editions of Visual Studio contain a profiler, users of e.g. the professional edition are lacking such a feature. In this article, I present a method for profiling C++-applications with freely available tools and a simple application for presenting the results in an informative view.
Of course the resulting solution will not be as comfortable as an integrated profiler, but if you use profiling only when you find bottlenecks, this method is certainly sufficient - and €5.000 cheaper.
The following method was tested with Visual Studio 2008 Professional and Visual C++ 2010 Express.

The Method

The method consists of four steps
Generate a special "/PROFILE" build using Visual Studio (all editions can do this)
Profile the freshly compiled application with the freely available MS tool "VSPerfCmd"
Convert the resulting .vsp-file to .csv-files using "VSPerfReport"
Analyze the resulting - huge - csv-files with the attached Profile Result Viewer.


Generate a /PROFILE-build

Note: the following steps should of course be done with a release build and with debugging symbols enabled.
In Visual Studio 2008, go to the solution explorer, select the project and open the properties page.
In the section "Configuration Properties" choose "Linker" - "Advanced".
Set "Profile" to "Enable Profiling information (/PROFILE)" (the exact steps for other versions of Visual Studio might differ).

screenshot1.png

Read more: Codeproject