tracy/client/TracyProfiler.cpp

50 lines
932 B
C++
Raw Normal View History

2017-09-10 15:43:56 +00:00
#include <assert.h>
2017-09-10 18:07:38 +00:00
#include <chrono>
2017-09-10 15:43:56 +00:00
#include "TracyProfiler.hpp"
2017-09-10 15:46:20 +00:00
#include "TracySystem.hpp"
2017-09-10 15:43:56 +00:00
namespace tracy
{
extern const char* PointerCheckA;
const char* PointerCheckB = "tracy";
2017-09-10 18:07:38 +00:00
static inline int64_t GetTime()
{
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
}
2017-09-10 15:43:56 +00:00
static Profiler* s_instance = nullptr;
Profiler::Profiler()
: m_shutdown( false )
{
assert( PointerCheckA == PointerCheckB );
2017-09-10 15:43:56 +00:00
assert( !s_instance );
s_instance = this;
m_thread = std::thread( [this] { Worker(); } );
2017-09-10 15:46:20 +00:00
SetThreadName( m_thread, "Tracy Profiler" );
2017-09-10 15:43:56 +00:00
}
Profiler::~Profiler()
{
assert( s_instance );
s_instance = nullptr;
m_shutdown.store( true, std::memory_order_relaxed );
m_thread.join();
}
void Profiler::Worker()
{
for(;;)
{
if( m_shutdown.load( std::memory_order_relaxed ) ) return;
}
}
}