-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathprofiler.h
50 lines (40 loc) · 994 Bytes
/
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
/*
* profiler.h
*
* Created on: Nov 26, 2016
* Author: nullifiedcat
*/
#ifndef PROFILER_H_
#define PROFILER_H_
#include "beforecheaders.h"
#include <chrono>
#include <string>
#include "aftercheaders.h"
class ProfilerNode;
class ProfilerSection {
public:
ProfilerSection(std::string name);
void OnNodeDeath(ProfilerNode& node);
std::chrono::nanoseconds m_min;
std::chrono::nanoseconds m_max;
std::chrono::nanoseconds m_sum;
unsigned m_calls;
std::chrono::time_point<std::chrono::high_resolution_clock> m_log;
std::string m_name;
};
class ProfilerNode {
public:
ProfilerNode(ProfilerSection& section);
~ProfilerNode();
std::chrono::time_point<std::chrono::high_resolution_clock> m_start;
ProfilerSection& m_section;
};
#define ENABLE_PROFILER false
#if ENABLE_PROFILER
#define PROF_SECTION(id) \
static ProfilerSection __PROFILER__##id(#id); \
ProfilerNode __PROFILER_NODE__##id(__PROFILER__##id);
#else
#define PROF_SECTION(id)
#endif
#endif /* PROFILER_H_ */