Exchange time and id in queue header and data structs.

This commit is contained in:
Bartosz Taudul 2017-09-14 01:07:14 +02:00
parent 3e1b736b34
commit d999f35dfa
4 changed files with 19 additions and 18 deletions

View File

@ -1,5 +1,4 @@
#include <assert.h> #include <assert.h>
#include <chrono>
#include <memory> #include <memory>
#include "../common/tracy_lz4.hpp" #include "../common/tracy_lz4.hpp"
@ -14,11 +13,6 @@ namespace tracy
extern const char* PointerCheckA; extern const char* PointerCheckA;
const char* PointerCheckB = "tracy"; const char* PointerCheckB = "tracy";
static inline int64_t GetTime()
{
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
}
static Profiler* s_instance = nullptr; 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 ); 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; QueueItem item;
item.hdr.type = QueueType::ZoneBegin; item.hdr.type = QueueType::ZoneBegin;
item.hdr.time = GetTime(); item.hdr.id = id;
item.zoneBegin = std::move( data ); item.zoneBegin = std::move( data );
s_instance->m_queue.enqueue( GetToken(), std::move( item ) ); 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; QueueItem item;
item.hdr.type = QueueType::ZoneEnd; item.hdr.type = QueueType::ZoneEnd;
item.hdr.time = GetTime(); item.hdr.id = id;
item.zoneEnd = std::move( data ); item.zoneEnd = std::move( data );
s_instance->m_queue.enqueue( GetToken(), std::move( item ) ); s_instance->m_queue.enqueue( GetToken(), std::move( item ) );
} }

View File

@ -2,6 +2,7 @@
#define __TRACYPROFILER_HPP__ #define __TRACYPROFILER_HPP__
#include <atomic> #include <atomic>
#include <chrono>
#include <stdint.h> #include <stdint.h>
#include <thread> #include <thread>
@ -11,6 +12,11 @@
namespace tracy namespace tracy
{ {
static inline int64_t GetTime()
{
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
}
class Profiler class Profiler
{ {
public: public:
@ -19,8 +25,8 @@ public:
static uint64_t GetNewId(); static uint64_t GetNewId();
static void ZoneBegin( QueueZoneBegin&& data ); static uint64_t ZoneBegin( QueueZoneBegin&& data );
static void ZoneEnd( QueueZoneEnd&& data ); static void ZoneEnd( uint64_t id, QueueZoneEnd&& data );
private: private:
void Worker(); void Worker();

View File

@ -12,14 +12,13 @@ class ScopedZone
{ {
public: public:
ScopedZone( const char* file, const char* function, uint32_t line ) 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() ~ScopedZone()
{ {
Profiler::ZoneEnd( QueueZoneEnd { m_id } ); Profiler::ZoneEnd( m_id, QueueZoneEnd { GetTime() } );
} }
private: private:

View File

@ -17,7 +17,7 @@ enum class QueueType : uint8_t
struct QueueZoneBegin struct QueueZoneBegin
{ {
uint64_t id; int64_t time;
uint64_t filename; // ptr uint64_t filename; // ptr
uint64_t function; // ptr uint64_t function; // ptr
uint32_t line; uint32_t line;
@ -25,7 +25,7 @@ struct QueueZoneBegin
struct QueueZoneEnd struct QueueZoneEnd
{ {
uint64_t id; int64_t time;
}; };
struct QueueHeader struct QueueHeader
@ -35,7 +35,7 @@ struct QueueHeader
QueueType type; QueueType type;
uint8_t idx; uint8_t idx;
}; };
int64_t time; uint64_t id;
}; };
struct QueueItem struct QueueItem