mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 14:44:34 +00:00
Offload TSC -> time conversion to server.
This commit is contained in:
parent
27e1952cc5
commit
11a790a18f
@ -86,7 +86,7 @@ int64_t Profiler::GetTime()
|
||||
{
|
||||
#if defined _MSC_VER || defined __CYGWIN__
|
||||
unsigned int ui;
|
||||
return int64_t( __rdtscp( &ui ) * s_instance->m_timerMul );
|
||||
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
|
||||
@ -151,6 +151,7 @@ void Profiler::Worker()
|
||||
#else
|
||||
welcome.lz4 = 1;
|
||||
#endif
|
||||
welcome.timerMul = m_timerMul;
|
||||
welcome.timeBegin = m_timeBegin;
|
||||
welcome.delay = m_delay;
|
||||
|
||||
@ -282,6 +283,8 @@ void Profiler::CalibrateTimer()
|
||||
const auto dr = r1 - r0;
|
||||
|
||||
m_timerMul = double( dt ) / double( dr );
|
||||
#else
|
||||
m_timerMul = 1.;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ enum ServerQuery : uint8_t
|
||||
struct WelcomeMessage
|
||||
{
|
||||
uint8_t lz4;
|
||||
double timerMul;
|
||||
uint64_t timeBegin;
|
||||
uint64_t delay;
|
||||
};
|
||||
|
@ -84,8 +84,9 @@ void View::Worker()
|
||||
WelcomeMessage welcome;
|
||||
if( !m_sock.Read( &welcome, sizeof( welcome ), &tv, ShouldExit ) ) goto close;
|
||||
lz4 = welcome.lz4;
|
||||
m_frames.push_back( welcome.timeBegin );
|
||||
m_delay = welcome.delay;
|
||||
m_timerMul = welcome.timerMul;
|
||||
m_frames.push_back( welcome.timeBegin * m_timerMul );
|
||||
m_delay = welcome.delay * m_timerMul;
|
||||
}
|
||||
|
||||
m_hasData.store( true, std::memory_order_release );
|
||||
@ -232,7 +233,7 @@ void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev )
|
||||
CheckString( ev.filename );
|
||||
CheckString( ev.function );
|
||||
CheckThreadString( ev.thread );
|
||||
zone->start = ev.time;
|
||||
zone->start = ev.time * m_timerMul;
|
||||
zone->color = ev.color;
|
||||
|
||||
SourceLocation srcloc { ev.filename, ev.function, ev.line };
|
||||
@ -260,8 +261,8 @@ void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev )
|
||||
}
|
||||
else
|
||||
{
|
||||
assert( ev.time <= it->second.time );
|
||||
zone->end = it->second.time;
|
||||
zone->end = it->second.time * m_timerMul;
|
||||
assert( zone->start <= zone->end );
|
||||
NewZone( zone, ev.thread );
|
||||
lock.unlock();
|
||||
m_pendingEndZone.erase( it );
|
||||
@ -279,8 +280,9 @@ void View::ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev )
|
||||
{
|
||||
auto zone = it->second;
|
||||
std::unique_lock<std::mutex> lock( m_lock );
|
||||
assert( ev.time >= zone->start );
|
||||
zone->end = ev.time;
|
||||
assert( zone->end == -1 );
|
||||
zone->end = ev.time * m_timerMul;
|
||||
assert( zone->end >= zone->start );
|
||||
UpdateZone( zone );
|
||||
lock.unlock();
|
||||
m_openZones.erase( it );
|
||||
@ -291,16 +293,17 @@ void View::ProcessFrameMark( uint64_t id )
|
||||
{
|
||||
assert( !m_frames.empty() );
|
||||
const auto lastframe = m_frames.back();
|
||||
if( lastframe < id )
|
||||
const auto time = id * m_timerMul;
|
||||
if( lastframe < time )
|
||||
{
|
||||
std::unique_lock<std::mutex> lock( m_lock );
|
||||
m_frames.push_back( id );
|
||||
m_frames.push_back( time );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto it = std::lower_bound( m_frames.begin(), m_frames.end(), id );
|
||||
auto it = std::lower_bound( m_frames.begin(), m_frames.end(), time );
|
||||
std::unique_lock<std::mutex> lock( m_lock );
|
||||
m_frames.insert( it, id );
|
||||
m_frames.insert( it, time );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,6 +118,7 @@ private:
|
||||
int64_t m_zvEnd;
|
||||
|
||||
uint64_t m_delay;
|
||||
double m_timerMul;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user