Profiling delay calibration.

This commit is contained in:
Bartosz Taudul 2017-09-24 16:02:09 +02:00
parent bf12704b0f
commit fce04c6215
2 changed files with 50 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include "../common/TracySocket.hpp" #include "../common/TracySocket.hpp"
#include "../common/TracySystem.hpp" #include "../common/TracySystem.hpp"
#include "concurrentqueue.h" #include "concurrentqueue.h"
#include "TracyScoped.hpp"
#include "TracyProfiler.hpp" #include "TracyProfiler.hpp"
#include "TracyThread.hpp" #include "TracyThread.hpp"
@ -58,6 +59,7 @@ Profiler::Profiler()
s_instance = this; s_instance = this;
CalibrateTimer(); CalibrateTimer();
CalibrateDelay();
m_timeBegin = GetTime(); m_timeBegin = GetTime();
m_thread = std::thread( [this] { Worker(); } ); m_thread = std::thread( [this] { Worker(); } );
@ -280,4 +282,50 @@ void Profiler::CalibrateTimer()
#endif #endif
} }
class FakeZone
{
public:
FakeZone( const char* file, const char* function, uint32_t line ) {}
~FakeZone() {}
private:
uint64_t m_id;
};
void Profiler::CalibrateDelay()
{
enum { Iterations = 50000 };
enum { Events = Iterations * 2 }; // start + end
static_assert( Events * 2 < QueuePrealloc, "Delay calibration loop will allocate memory in queue" );
for( int i=0; i<Iterations; i++ )
{
ScopedZone ___tracy_scoped_zone( __FILE__, __FUNCTION__, __LINE__ );
}
const auto f0 = GetTime();
for( int i=0; i<Iterations; i++ )
{
FakeZone ___tracy_scoped_zone( __FILE__, __FUNCTION__, __LINE__ );
}
const auto t0 = GetTime();
for( int i=0; i<Iterations; i++ )
{
ScopedZone ___tracy_scoped_zone( __FILE__, __FUNCTION__, __LINE__ );
}
const auto t1 = GetTime();
const auto dt = t1 - t0;
const auto df = t0 - f0;
m_delay = ( dt - df ) / Events;
enum { Bulk = 1000 };
moodycamel::ConsumerToken token( s_queue );
int left = Events * 2;
QueueItem item[Bulk];
while( left != 0 )
{
const auto sz = s_queue.try_dequeue_bulk( token, item, std::min( left, (int)Bulk ) );
assert( sz > 0 );
left -= sz;
}
}
} }

View File

@ -37,8 +37,10 @@ private:
bool HandleServerQuery(); bool HandleServerQuery();
void CalibrateTimer(); void CalibrateTimer();
void CalibrateDelay();
double m_timerMul; double m_timerMul;
uint64_t m_delay;
int64_t m_timeBegin; int64_t m_timeBegin;
uint64_t m_mainThread; uint64_t m_mainThread;
std::thread m_thread; std::thread m_thread;