Jump to content

Profiling code for C++


Pixel Perfect
 Share

Recommended Posts

File Name: Profiling code for C++

File Submitter: Pixel Perfect

File Submitted: 08 May 2010

File Category: C/C++ Code

 

Profilers are useful tools for optimizing your code and detecting where valuable processing time is being consumed, I found this one available as Freeware and managed to get it working today and have been using it successfully to profile my latest game code. It struck me as something that might be useful to the community.

 

My thanks to Harald Hoyer for making this profiling code available. I have modified the cpp file to ensure it

works with MS Visual C++ 2008 Express Edition and included the modified file. The profiler can profile multiple

areas of your code, see the header file for a breakdown of the commands and usage. The output is sorted by

time spent in each routine.

 

 

Instructions for use (a simple one off function profile):

 

Include the two C++ files hwprof.h and hwprof.cpp in your project

 

Add the following to your main header file:

 

// Three lines needed for Profiler
#define PROFILE	&Profile
#include "HWProf.h"
CHWProfile Profile;

 

Add the following to the line before and after the call you want to monitor for example:

 

// Starts the profiler
BEGIN_PROF("Test");  

// The function being profiled
pAIManager->calcPathToPosition(pathFindTestStartPos, pathFindTestEndPos);  

// Ends the profiler
END_PROF();  	

 

Then add the following profiler output dump lines at the end of your main routine before you terminate

your application:

 

// Profiling output - comment out if not needed
Profile.dumpprint();
Profile.reset();

 

 

The Profiler output appears in the debug output window in Visual C++ 2008. An example is shown below:

 

 

=========== Profile ==================

 

c:\users\ian\documents\visual studio 2008\projects\leadwerks engine 2\navarea editor\main.cpp(1657): 0: 1x 271µs 271µs 100% Test

 

Total: 271µs

 

======================================

 

 

Have fun!

 

Click here to download this file

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

Thanks Pixel. This is definitely a handy tool.

 

Just a quick question, does it just measure the time doing the funtion?

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Well I haven't played much with it yet having only just got it working last night but it's basic output as far as I've determined so far is:

 

<FileName> <Line number> <Number Of Iterations> <Averaged time per call> <Total time in call>

<Percentage of overall time> <Your label text>

 

for every set of Begin_Prof / End_Prof sections sorted in descending order of time taken.

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...