From d999f35dfab4ea73576b88d7029ede15aefd6d85 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 14 Sep 2017 01:07:14 +0200 Subject: [PATCH] Exchange time and id in queue header and data structs. --- client/TracyProfiler.cpp | 16 ++++++---------- client/TracyProfiler.hpp | 10 ++++++++-- client/TracyScoped.hpp | 5 ++--- common/TracyQueue.hpp | 6 +++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 2ca2c343..02fc944f 100755 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -1,5 +1,4 @@ #include -#include #include #include "../common/tracy_lz4.hpp" @@ -14,11 +13,6 @@ namespace tracy extern const char* PointerCheckA; const char* PointerCheckB = "tracy"; -static inline int64_t GetTime() -{ - return std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); -} - static Profiler* s_instance = nullptr; @@ -50,20 +44,22 @@ uint64_t Profiler::GetNewId() return s_instance->m_id.fetch_add( 1, std::memory_order_relaxed ); } -void Profiler::ZoneBegin( QueueZoneBegin&& data ) +uint64_t Profiler::ZoneBegin( QueueZoneBegin&& data ) { + auto id = GetNewId(); QueueItem item; item.hdr.type = QueueType::ZoneBegin; - item.hdr.time = GetTime(); + item.hdr.id = id; item.zoneBegin = std::move( data ); s_instance->m_queue.enqueue( GetToken(), std::move( item ) ); + return id; } -void Profiler::ZoneEnd( QueueZoneEnd&& data ) +void Profiler::ZoneEnd( uint64_t id, QueueZoneEnd&& data ) { QueueItem item; item.hdr.type = QueueType::ZoneEnd; - item.hdr.time = GetTime(); + item.hdr.id = id; item.zoneEnd = std::move( data ); s_instance->m_queue.enqueue( GetToken(), std::move( item ) ); } diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index c95828f2..9777ffd4 100755 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -2,6 +2,7 @@ #define __TRACYPROFILER_HPP__ #include +#include #include #include @@ -11,6 +12,11 @@ namespace tracy { +static inline int64_t GetTime() +{ + return std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); +} + class Profiler { public: @@ -19,8 +25,8 @@ public: static uint64_t GetNewId(); - static void ZoneBegin( QueueZoneBegin&& data ); - static void ZoneEnd( QueueZoneEnd&& data ); + static uint64_t ZoneBegin( QueueZoneBegin&& data ); + static void ZoneEnd( uint64_t id, QueueZoneEnd&& data ); private: void Worker(); diff --git a/client/TracyScoped.hpp b/client/TracyScoped.hpp index f7b7210a..18c1cb72 100755 --- a/client/TracyScoped.hpp +++ b/client/TracyScoped.hpp @@ -12,14 +12,13 @@ class ScopedZone { public: ScopedZone( const char* file, const char* function, uint32_t line ) - : m_id( Profiler::GetNewId() ) + : m_id( Profiler::ZoneBegin( QueueZoneBegin { GetTime(), (uint64_t)file, (uint64_t)function, line } ) ) { - Profiler::ZoneBegin( QueueZoneBegin { m_id, (uint64_t)file, (uint64_t)function, line } ); } ~ScopedZone() { - Profiler::ZoneEnd( QueueZoneEnd { m_id } ); + Profiler::ZoneEnd( m_id, QueueZoneEnd { GetTime() } ); } private: diff --git a/common/TracyQueue.hpp b/common/TracyQueue.hpp index 4cbca18f..058c4c55 100755 --- a/common/TracyQueue.hpp +++ b/common/TracyQueue.hpp @@ -17,7 +17,7 @@ enum class QueueType : uint8_t struct QueueZoneBegin { - uint64_t id; + int64_t time; uint64_t filename; // ptr uint64_t function; // ptr uint32_t line; @@ -25,7 +25,7 @@ struct QueueZoneBegin struct QueueZoneEnd { - uint64_t id; + int64_t time; }; struct QueueHeader @@ -35,7 +35,7 @@ struct QueueHeader QueueType type; uint8_t idx; }; - int64_t time; + uint64_t id; }; struct QueueItem