-
Notifications
You must be signed in to change notification settings - Fork 5
/
SimplePerfTimer.h
57 lines (43 loc) · 1.5 KB
/
SimplePerfTimer.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
#ifndef SIMPLEPERFTIMER_H
#define SIMPLEPERFTIMER_H
#define ENABLE_SIMPLEPERF
#define SIMPLEPERF_SHOWIMMEDIATE false
#ifdef ENABLE_SIMPLEPERF
// in a larger project this should go into a precompiled header...
#include <windows.h>
#include <string>
#include <vector>
#include <tuple>
#define PERF_PRINTF_FUNC printf
class SimplePerfTimer
{
public:
SimplePerfTimer(const char* strText, bool bShowImmediate);
~SimplePerfTimer();
SimplePerfTimer(const SimplePerfTimer&) = delete;
SimplePerfTimer& operator=(const SimplePerfTimer&) = delete;
static void ReportAll();
private:
unsigned m_id;
const char *m_str;
const bool m_bShowImmediate;
LARGE_INTEGER m_start;
static std::vector<std::tuple<std::string, double, int>> s_data;
static LARGE_INTEGER s_freq;
static int s_indent;
};
#define SIMPLEPERF_FUNCSTART SimplePerfTimer __xperfstart##__COUNTER__(__FUNCTION__" : %f\n", SIMPLEPERF_SHOWIMMEDIATE)
#define SIMPLEPERF_SCOPED(str) SimplePerfTimer __xperfstart##__COUNTER__(str" : %f\n", SIMPLEPERF_SHOWIMMEDIATE)
#define SIMPLEPERF_START(str) { SimplePerfTimer __xperfstart##__COUNTER__(str" : %f\n", SIMPLEPERF_SHOWIMMEDIATE)
#define SIMPLEPERF_END }
#define SIMPLEPERF_REPORTALL SimplePerfTimer::ReportAll
#define SIMPLEPERF_REPORTALL_ATEXIT atexit(SimplePerfTimer::ReportAll);
#else
#define SIMPLEPERF_FUNCSTART
#define SIMPLEPERF_SCOPED
#define SIMPLEPERF_START
#define SIMPLEPERF_END
#define SIMPLEPERF_REPORTALL
#define SIMPLEPERF_REPORTALL_ATEXIT
#endif // ENABLE_SIMPLEPERF
#endif // SIMPLEPERFTIMER_H