forked from hoffstadt/DearPyGui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmvProfiler.h
86 lines (60 loc) · 2.2 KB
/
mvProfiler.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
#pragma once
#include <chrono>
#include <string>
#include <map>
#include "mvTypes.h"
using FloatingPointMicroseconds = std::chrono::duration<double, std::micro>;
//-----------------------------------------------------------------------------
// Useful structs
//-----------------------------------------------------------------------------
struct mvProfileResult
{
std::string Name;
FloatingPointMicroseconds Start;
std::chrono::microseconds ElapsedTime;
};
struct mvInstrumentationSession
{
std::string Name;
};
//-----------------------------------------------------------------------------
// mvInstrumentor
//-----------------------------------------------------------------------------
class mvInstrumentor
{
public:
mvInstrumentor() : m_CurrentSession(nullptr) {}
// Call to begin recording profile data (must call end session at a later time)
void BeginSession(const std::string& name);
// Call to end recording profile data
void EndSession();
// Used to write data to the profiling file
void WriteProfile(const mvProfileResult& result);
const std::map<std::string, std::chrono::microseconds>& getResults() const { return m_results; }
static mvInstrumentor& Get();
private:
// Note: you must already own lock on m_Mutex before
// calling InternalEndSession()
void InternalEndSession();
private:
mvInstrumentationSession* m_CurrentSession;
std::map<std::string, std::chrono::microseconds> m_results;
};
//-----------------------------------------------------------------------------
// mvInstrumentationTimer
//-----------------------------------------------------------------------------
class mvInstrumentationTimer
{
public:
mvInstrumentationTimer(const char* name);
~mvInstrumentationTimer();
void Stop();
private:
const char* m_Name;
b8 m_Stopped;
std::chrono::time_point<std::chrono::steady_clock> m_StartTimepoint;
};
#define MV_PROFILE_BEGIN_SESSION(name) ::mvInstrumentor::Get().BeginSession(name)
#define MV_PROFILE_END_SESSION() ::mvInstrumentor::Get().EndSession()
#define MV_PROFILE_SCOPE(name) ::mvInstrumentationTimer timer##__LINE__(name);
#define MV_PROFILE_FUNCTION() MV_PROFILE_SCOPE(__func__)