forked from hoffstadt/DearPyGui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmvProfiler.cpp
More file actions
70 lines (56 loc) · 1.86 KB
/
mvProfiler.cpp
File metadata and controls
70 lines (56 loc) · 1.86 KB
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
#include "mvProfiler.h"
//-----------------------------------------------------------------------------
// mvInstrumentor
//-----------------------------------------------------------------------------
void mvInstrumentor::BeginSession(const std::string& name)
{
if (m_CurrentSession)
{
// If there is already a current session, then close it before beginning new one.
// Subsequent profiling output meant for the original session will end up in the
// newly opened session instead. That's better than having badly formatted
// profiling output.
InternalEndSession();
}
}
void mvInstrumentor::EndSession()
{
InternalEndSession();
}
void mvInstrumentor::WriteProfile(const mvProfileResult& result)
{
m_results[result.Name] = result.ElapsedTime;
}
mvInstrumentor& mvInstrumentor::Get()
{
static mvInstrumentor instance;
return instance;
}
void mvInstrumentor::InternalEndSession() {
if (m_CurrentSession)
{
delete m_CurrentSession;
m_CurrentSession = nullptr;
}
}
//-----------------------------------------------------------------------------
// mvInstrumentationTimer
//-----------------------------------------------------------------------------
mvInstrumentationTimer::mvInstrumentationTimer(const char* name)
: m_Name(name), m_Stopped(false)
{
m_StartTimepoint = std::chrono::steady_clock::now();
}
mvInstrumentationTimer::~mvInstrumentationTimer()
{
if (!m_Stopped)
Stop();
}
void mvInstrumentationTimer::Stop()
{
auto endTimepoint = std::chrono::steady_clock::now();
auto highResStart = FloatingPointMicroseconds{ m_StartTimepoint.time_since_epoch() };
auto elapsedTime = std::chrono::time_point_cast<std::chrono::microseconds>(endTimepoint).time_since_epoch() - std::chrono::time_point_cast<std::chrono::microseconds>(m_StartTimepoint).time_since_epoch();
mvInstrumentor::Get().WriteProfile({ m_Name, highResStart, elapsedTime });
m_Stopped = true;
}