From 51f5ae4796fb2d1b47180c963f8f1d727c44e266 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 17 Oct 2017 01:07:54 +0200 Subject: [PATCH] More precise profiler init end time measurement. --- client/TracyProfiler.cpp | 10 +++++++--- client/TracyProfiler.hpp | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index b2f4bb15..b9ce909b 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -102,7 +102,8 @@ static Profiler init_order(104) s_profiler; Profiler::Profiler() - : m_mainThread( GetThreadHandle() ) + : m_timeBegin( 0 ) + , m_mainThread( GetThreadHandle() ) , m_epoch( std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch() ).count() ) , m_shutdown( false ) , m_stream( LZ4_createStream() ) @@ -120,12 +121,13 @@ Profiler::Profiler() CalibrateTimer(); CalibrateDelay(); - uint32_t cpu; - m_timeBegin = GetTime( cpu ); s_thread = (Thread*)tracy_malloc( sizeof( Thread ) ); new(s_thread) Thread( LaunchWorker, this ); SetThreadName( s_thread->Handle(), "Tracy Profiler" ); + + uint32_t cpu; + m_timeBegin.store( GetTime( cpu ), std::memory_order_relaxed ); } Profiler::~Profiler() @@ -155,6 +157,8 @@ void Profiler::Worker() ListenSocket listen; listen.Listen( "8086", 8 ); + while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); + for(;;) { for(;;) diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index b4d4d293..ae8790af 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -177,7 +177,7 @@ private: double m_timerMul; uint64_t m_resolution; uint64_t m_delay; - int64_t m_timeBegin; + std::atomic m_timeBegin; uint64_t m_mainThread; uint64_t m_epoch; std::atomic m_shutdown;