* Move GetTickCount() hacks to porting.h and replace by a real call to SDL_GetTicks().
[matthijs/ABM2.git] / ABM2 / Engine / profiler.h
1 #ifndef PROFILER_H_INCLUDED\r
2 #define PROFILER_H_INCLUDED\r
3 \r
4 #define MAX_PROFILER_SAMPLES 50\r
5 \r
6 \r
7 class IProfilerOutputHandler;\r
8 class CProfileSample;\r
9 \r
10 class CProfileSample\r
11 {\r
12 public:\r
13         CProfileSample(std::string sampleName);\r
14         ~CProfileSample();\r
15 \r
16         static void Output();\r
17 \r
18         static void ResetSample(std::string sampleName);\r
19         static void ResetAll();\r
20 \r
21         static IProfilerOutputHandler *outputHandler;\r
22 \r
23         static bool bProfilerIsRunning;\r
24 \r
25 protected:\r
26         //index into the array of samples\r
27         int iSampleIndex;\r
28         int iParentIndex;\r
29 \r
30         inline float GetTime(){ return ((float)GetTickCount())/1000.0f; }\r
31 \r
32         static struct profileSample\r
33         {\r
34                 profileSample()\r
35                 {\r
36                         bIsValid=false; \r
37                         dataCount=0;\r
38                         averagePc=minPc=maxPc=-1;\r
39                 }\r
40 \r
41                 bool bIsValid;          //whether or not this sample is valid (for use with fixed-size arrays)\r
42                 bool bIsOpen;           //is this sample currently being profiled?\r
43                 unsigned int callCount; //number of times this sample has been profiled this frame\r
44                 std::string name;       //name of the sample\r
45                 \r
46                 float startTime;        //starting time on the clock, in seconds\r
47                 float totalTime;        //total time recorded across all profiles of this sample\r
48                 float childTime;        //total time taken by children of this sample\r
49 \r
50                 int parentCount;        //number of parents this sample has (useful for indenting)\r
51 \r
52                 float averagePc;        //average percentage of game loop time taken up\r
53                 float minPc;            //minimum percentage of game loop time taken up\r
54                 float maxPc;            //maximum percentage of game loop time taken up\r
55                 unsigned long dataCount;//number of percentage values that have been stored\r
56         } samples[MAX_PROFILER_SAMPLES];\r
57         static int lastOpenedSample;\r
58         static int openSampleCount;\r
59         static float rootBegin, rootEnd;\r
60 };\r
61 \r
62 class IProfilerOutputHandler\r
63 {\r
64 public:\r
65         virtual void BeginOutput(float tTotal)=0;\r
66         virtual void Sample(float fMin, float fAvg, float fMax, float tAvg, int callCount, std::string name, int parentCount)=0;\r
67         virtual void EndOutput()=0;\r
68 };\r
69 \r
70 #ifdef _DEBUG\r
71 #define PROFILE(name) CProfileSample _profile_sample(name);\r
72 #else\r
73 #define PROFILE(name)\r
74 #endif\r
75 \r
76 #endif\r