From a868e34fa1a79189dd4fbdede2938e308535e5e8 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Sat, 16 Mar 2024 16:25:24 +0100 Subject: [PATCH] explicit std namespace --- src/ofxProfiler.h | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/ofxProfiler.h b/src/ofxProfiler.h index 23d58c6..a89c3ea 100644 --- a/src/ofxProfiler.h +++ b/src/ofxProfiler.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "ofMain.h" @@ -12,34 +13,34 @@ namespace ofxProfiler { -using FloatingPointMicroseconds = chrono::duration ; +using FloatingPointMicroseconds = std::chrono::duration ; struct ProfileResult { - string Name; + std::string Name; FloatingPointMicroseconds Start; - chrono::microseconds ElapsedTime; - thread::id ThreadID; + std::chrono::microseconds ElapsedTime; + std::thread::id ThreadID; }; struct InstrumentationSession { - string Name; + std::string Name; }; class Instrumentor { private: - mutex m_Mutex; + std::mutex m_Mutex; InstrumentationSession * m_CurrentSession; - ofstream m_OutputStream; + std::ofstream m_OutputStream; public: Instrumentor() : m_CurrentSession(nullptr){ } - void BeginSession(const string & name = "I do not want to name my profiling sessions.", - const string & filepath = "results.json", + void BeginSession(const std::string & name = "I do not want to name my profiling sessions.", + const std::string & filepath = "results.json", const bool continueSession = false){ - lock_guard lock(m_Mutex); + std::lock_guard lock(m_Mutex); if(!m_CurrentSession || !continueSession){ // if there is no session, or it should not be continued if(m_CurrentSession){ @@ -62,17 +63,17 @@ class Instrumentor { } void EndSession(){ - lock_guard lock(m_Mutex); + std::lock_guard lock(m_Mutex); InternalEndSession(); } void WriteProfile(const ProfileResult & result){ - stringstream json; + std::stringstream json; - string name = result.Name; + std::string name = result.Name; replace(name.begin(), name.end(), '"', '\''); - json << setprecision(3) << fixed; + json << std::setprecision(3) << std::fixed; json << ",{"; json << "\"cat\":\"function\","; json << "\"dur\":" << (result.ElapsedTime.count()) << ','; @@ -83,7 +84,7 @@ class Instrumentor { json << "\"ts\":" << result.Start.count(); json << "}"; - lock_guard lock(m_Mutex); + std::lock_guard lock(m_Mutex); if(m_CurrentSession){ m_OutputStream << json.str(); m_OutputStream.flush(); @@ -123,7 +124,7 @@ class InstrumentationTimer { public: InstrumentationTimer(const char * name) : m_Name(name), m_Stopped(false){ - m_StartTimepoint = chrono::steady_clock::now(); + m_StartTimepoint = std::chrono::steady_clock::now(); } ~InstrumentationTimer(){ @@ -133,17 +134,17 @@ class InstrumentationTimer { } void Stop(){ - auto endTimepoint = chrono::steady_clock::now(); + auto endTimepoint = std::chrono::steady_clock::now(); auto highResStart = FloatingPointMicroseconds{m_StartTimepoint.time_since_epoch()}; - auto elapsedTime = chrono::time_point_cast (endTimepoint).time_since_epoch() - chrono::time_point_cast (m_StartTimepoint).time_since_epoch(); + auto elapsedTime = std::chrono::time_point_cast (endTimepoint).time_since_epoch() - std::chrono::time_point_cast (m_StartTimepoint).time_since_epoch(); - Instrumentor::Get().WriteProfile({m_Name, highResStart, elapsedTime, this_thread::get_id()}); + Instrumentor::Get().WriteProfile({m_Name, highResStart, elapsedTime, std::this_thread::get_id()}); m_Stopped = true; } private: const char * m_Name; - chrono::time_point m_StartTimepoint; + std::chrono::time_point m_StartTimepoint; bool m_Stopped; }; }