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