GetTime() call can be now inlined.

No dependencies on either windows.h, or static instance of Profiler.
This commit is contained in:
Bartosz Taudul 2017-09-26 00:42:09 +02:00
parent 11a790a18f
commit e5ad7d9ac4
2 changed files with 14 additions and 15 deletions

View File

@ -4,10 +4,6 @@
# include <sys/time.h> # include <sys/time.h>
#endif #endif
#if defined _MSC_VER || defined __CYGWIN__
# include <intrin.h>
#endif
#include <atomic> #include <atomic>
#include <assert.h> #include <assert.h>
#include <chrono> #include <chrono>
@ -82,16 +78,6 @@ 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 );
} }
int64_t Profiler::GetTime()
{
#if defined _MSC_VER || defined __CYGWIN__
unsigned int ui;
return int64_t( __rdtscp( &ui ) );
#else
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
#endif
}
uint64_t Profiler::ZoneBegin( QueueZoneBegin&& data ) uint64_t Profiler::ZoneBegin( QueueZoneBegin&& data )
{ {
auto id = GetNewId(); auto id = GetNewId();

View File

@ -2,12 +2,17 @@
#define __TRACYPROFILER_HPP__ #define __TRACYPROFILER_HPP__
#include <atomic> #include <atomic>
#include <chrono>
#include <stdint.h> #include <stdint.h>
#include <thread> #include <thread>
#include "../common/tracy_lz4.hpp" #include "../common/tracy_lz4.hpp"
#include "../common/TracyQueue.hpp" #include "../common/TracyQueue.hpp"
#if defined _MSC_VER || defined __CYGWIN__
# include <intrin.h>
#endif
namespace tracy namespace tracy
{ {
@ -20,7 +25,15 @@ public:
~Profiler(); ~Profiler();
static uint64_t GetNewId(); static uint64_t GetNewId();
static int64_t GetTime(); static int64_t GetTime()
{
#if defined _MSC_VER || defined __CYGWIN__
unsigned int ui;
return int64_t( __rdtscp( &ui ) );
#else
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
#endif
}
static uint64_t ZoneBegin( QueueZoneBegin&& data ); static uint64_t ZoneBegin( QueueZoneBegin&& data );
static void ZoneEnd( uint64_t id, QueueZoneEnd&& data ); static void ZoneEnd( uint64_t id, QueueZoneEnd&& data );