forked from 1dot13/source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofiler.h
87 lines (76 loc) · 2.19 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
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once
#include <vector>
#include <set>
#include <ostream>
//#ifndef PROFILER_ENABLED
//#define PROFILER_ENABLED
//#endif
#ifdef PROFILER_ENABLED
#define STRINGIZE(x) #x
#define NAMED_ PERFORMANCE_MARKER(x) PerfMarker x(__FILE__, STRINGIZE(x), __LINE__);
#define END_NAMED_ PERFORMANCE_MARKER(x) x.endMark();
#define PERFORMANCE_MARKER PerfMarker MARK(__FILE__, __FUNCTION__, __LINE__);
#define PERIODIC_PROFILING
#else
#define PERFORMANCE_MARKER
#endif
#pragma warning (disable : 4512)//disables assignment operator could not be generated
struct PerfDatum
{
PerfDatum( const char* const fileName,
const char* const functionName,
const int lineNumber,
__int64 cycles = 0,
__int64 calls = 0);
const char* const _fileName;
const char* const _functionName;
const int _lineNumber;
__int64 _cycles; //Number of CPU cycles used
__int64 _calls; //Number of calls to this function
};
#pragma warning (default : 4512)//disables assignment operator could not be generated
class PerfSort
{
public:
bool operator()(const PerfDatum& lhs, const PerfDatum& rhs) const;
};
class PerfSort2
{
public:
bool operator()(const PerfDatum& lhs, const PerfDatum& rhs) const;
};
typedef std::set<PerfDatum, PerfSort> PERF_LOG_T;
typedef std::vector<PerfDatum* > PERF_STACK_T;
class PerfManager
{
public:
~PerfManager(void);
static PerfManager* instance();
void enterFunction( const char* const fileName,
const char* const functionName,
const int lineNumber);
void exitFunction();
void log(std::ostream &os);
private:
PerfManager(void);
__int64 getCPUCount(void) const;
void calibrate(void);
int getPercision(const double value) const; //used for formatting percentages
static PerfManager* _instance;
PERF_LOG_T _perfLog;
PERF_STACK_T _perfStack;
__int64 _callTime; //Time it takes to call the getCPUCount function
__int64 _totalTime;
__int64 _lastTime; //The last time we got hte CPU count.
};
class PerfMarker
{
public:
PerfMarker( const char* const fileName,
const char* const functionName,
const int lineNumber);
~PerfMarker();
void endMark();
private:
bool _onStack;
};