Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Muto::Instrumentor Class Reference

#include <Instrumentor.h>

Public Member Functions

void BeginSession (const std::string &name, const std::string &filepath="results.json")
 
void EndSession ()
 
 Instrumentor ()
 
void InternalEndSession ()
 
void WriteFooter ()
 
void WriteHeader ()
 
void WriteProfile (const ProfileResult &result)
 

Static Public Member Functions

static Instrumentor & Get ()
 

Private Attributes

InstrumentationSession * m_CurrentSession
 
std::mutex m_Mutex
 
std::ofstream m_OutputStream
 

Constructor & Destructor Documentation

◆ Instrumentor()

Muto::Instrumentor::Instrumentor ( )
inline
54 : m_CurrentSession(nullptr)
55 {
56 }
InstrumentationSession * m_CurrentSession
Definition Instrumentor.h:49

References m_CurrentSession.

Member Function Documentation

◆ BeginSession()

void Muto::Instrumentor::BeginSession ( const std::string &  name,
const std::string &  filepath = "results.json" 
)
inline
59 {
60 std::lock_guard lock(m_Mutex);
61 if (m_CurrentSession) {
62 // If there is already a current session, end it and start new one
63 if (Log::GetCoreLogger())
64 {
65 MU_CORE_ERROR("Instrumentor::BeginSession('{0}') when session '{1}' already open.", name, m_CurrentSession->Name);
66 }
68 }
70 if (m_OutputStream.is_open()) {
71 m_CurrentSession = new InstrumentationSession{ name };
73 }
74 else {
75 if (Log::GetCoreLogger())
76 {
77 MU_CORE_ERROR("Instrumentor could not open results file '{0}'.", filepath);
78 }
79 }
81 m_CurrentSession = new InstrumentationSession{ name };
82 }
#define MU_CORE_ERROR(...)
error: indicates an error that has occurred
Definition Log.h:42
std::ofstream m_OutputStream
Definition Instrumentor.h:50
void WriteHeader()
Definition Instrumentor.h:115
std::mutex m_Mutex
Definition Instrumentor.h:51
void InternalEndSession()
Definition Instrumentor.h:127
static std::shared_ptr< spdlog::logger > & GetCoreLogger()
Returns the core logger instance.
Definition Log.h:24
std::string Name
Definition Instrumentor.h:43
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51

References InternalEndSession(), m_CurrentSession, Muto::InstrumentationSession::Name, and WriteHeader().

◆ EndSession()

void Muto::Instrumentor::EndSession ( )
inline
85 {
86 std::lock_guard lock(m_Mutex);
88 }

References InternalEndSession().

◆ Get()

static Instrumentor & Muto::Instrumentor::Get ( )
inlinestatic
139 {
140 static Instrumentor instance;
141 return instance;
142 }
Instrumentor()
Definition Instrumentor.h:53

Referenced by Muto::InstrumentationTimer::Stop().

◆ InternalEndSession()

void Muto::Instrumentor::InternalEndSession ( )
inline
128 {
130 {
131 WriteFooter();
132 m_OutputStream.close();
133 delete m_CurrentSession;
134 m_CurrentSession = nullptr;
135 }
136 }
void WriteFooter()
Definition Instrumentor.h:121

References m_CurrentSession, and WriteFooter().

Referenced by BeginSession(), and EndSession().

◆ WriteFooter()

void Muto::Instrumentor::WriteFooter ( )
inline
122 {
123 m_OutputStream << "]}";
124 m_OutputStream.flush();
125 }

Referenced by InternalEndSession().

◆ WriteHeader()

void Muto::Instrumentor::WriteHeader ( )
inline
116 {
117 m_OutputStream << "{\"otherData\": {},\"traceEvents\":[";
118 m_OutputStream.flush();
119 }

Referenced by BeginSession().

◆ WriteProfile()

void Muto::Instrumentor::WriteProfile ( const ProfileResult &  result)
inline
91 {
92 m_OutputStream << ",";
93
94 std::string name = result.Name;
95 std::replace(name.begin(), name.end(), '"', '\'');
96
97 m_OutputStream << "{";
98 m_OutputStream << "\"cat\":\"function\",";
99 m_OutputStream << "\"dur\":" << (result.End - result.Start) << ',';
100 m_OutputStream << "\"name\":\"" << name << "\",";
101 m_OutputStream << "\"ph\":\"X\",";
102 m_OutputStream << "\"pid\":0,";
103 m_OutputStream << "\"tid\":" << result.ThreadID << ",";
104 m_OutputStream << "\"ts\":" << result.Start;
105 m_OutputStream << "}";
106
107 std::lock_guard lock(m_Mutex);
109 {
110 //m_OutputStream << json.str();
111 m_OutputStream.flush();
112 }
113 }

References m_CurrentSession, and Muto::ProfileResult::Name.

Referenced by Muto::InstrumentationTimer::Stop().

Member Data Documentation

◆ m_CurrentSession

InstrumentationSession* Muto::Instrumentor::m_CurrentSession
private

◆ m_Mutex

std::mutex Muto::Instrumentor::m_Mutex
private

◆ m_OutputStream

std::ofstream Muto::Instrumentor::m_OutputStream
private

The documentation for this class was generated from the following file: