mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Exchange time and id in queue header and data structs.
This commit is contained in:
parent
3e1b736b34
commit
d999f35dfa
@ -1,5 +1,4 @@
|
||||
#include <assert.h>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
|
||||
#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::nanoseconds>( 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 ) );
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define __TRACYPROFILER_HPP__
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <stdint.h>
|
||||
#include <thread>
|
||||
|
||||
@ -11,6 +12,11 @@
|
||||
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
|
||||
{
|
||||
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();
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user