From cfb6d0d2ae80892be177bef59a2115f941428d12 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 23 May 2021 20:32:09 +0200 Subject: [PATCH] Timestamp conversion might be temporarily unavailable. --- client/TracyRingBuffer.hpp | 2 +- client/TracySysTrace.cpp | 90 +++++++++++++++++++------------------- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/client/TracyRingBuffer.hpp b/client/TracyRingBuffer.hpp index 32532bae..852a2025 100644 --- a/client/TracyRingBuffer.hpp +++ b/client/TracyRingBuffer.hpp @@ -90,7 +90,7 @@ public: int64_t ConvertTimeToTsc( int64_t timestamp ) const { - assert( m_metadata->cap_user_time_zero ); + if( !m_metadata->cap_user_time_zero ) return 0; const auto time = timestamp - m_metadata->time_zero; const auto quot = time / m_metadata->time_mult; const auto rem = time % m_metadata->time_mult; diff --git a/client/TracySysTrace.cpp b/client/TracySysTrace.cpp index e3c4ff02..f1c73f08 100644 --- a/client/TracySysTrace.cpp +++ b/client/TracySysTrace.cpp @@ -959,56 +959,58 @@ static void SetupSampling( int64_t& samplingPeriod ) if( cnt > 0 ) { - auto trace = (uint64_t*)tracy_malloc( ( 1 + cnt ) * sizeof( uint64_t ) ); - s_ring[i].Read( trace+1, offset, sizeof( uint64_t ) * cnt ); +#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) + t0 = s_ring[i].ConvertTimeToTsc( t0 ); + if( t0 != 0 ) +#endif + { + auto trace = (uint64_t*)tracy_malloc( ( 1 + cnt ) * sizeof( uint64_t ) ); + s_ring[i].Read( trace+1, offset, sizeof( uint64_t ) * cnt ); #if defined __x86_64__ || defined _M_X64 - // remove non-canonical pointers - do - { - const auto test = (int64_t)trace[cnt]; - const auto m1 = test >> 63; - const auto m2 = test >> 47; - if( m1 == m2 ) break; - } - while( --cnt > 0 ); - for( uint64_t j=1; j> 63; - const auto m2 = test >> 47; - if( m1 != m2 ) trace[j] = 0; - } -#endif - - // skip kernel frames - uint64_t j; - for( j=0; j= 0 ) break; - } - if( j == cnt ) - { - tracy_free( trace ); - } - else - { - if( j > 0 ) + // remove non-canonical pointers + do { - cnt -= j; - memmove( trace+1, trace+1+j, sizeof( uint64_t ) * cnt ); + const auto test = (int64_t)trace[cnt]; + const auto m1 = test >> 63; + const auto m2 = test >> 47; + if( m1 == m2 ) break; + } + while( --cnt > 0 ); + for( uint64_t j=1; j> 63; + const auto m2 = test >> 47; + if( m1 != m2 ) trace[j] = 0; } - memcpy( trace, &cnt, sizeof( uint64_t ) ); - -#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) - t0 = s_ring[i].ConvertTimeToTsc( t0 ); #endif - TracyLfqPrepare( QueueType::CallstackSample ); - MemWrite( &item->callstackSampleFat.time, t0 ); - MemWrite( &item->callstackSampleFat.thread, (uint64_t)tid ); - MemWrite( &item->callstackSampleFat.ptr, (uint64_t)trace ); - TracyLfqCommit; + // skip kernel frames + uint64_t j; + for( j=0; j= 0 ) break; + } + if( j == cnt ) + { + tracy_free( trace ); + } + else + { + if( j > 0 ) + { + cnt -= j; + memmove( trace+1, trace+1+j, sizeof( uint64_t ) * cnt ); + } + memcpy( trace, &cnt, sizeof( uint64_t ) ); + + TracyLfqPrepare( QueueType::CallstackSample ); + MemWrite( &item->callstackSampleFat.time, t0 ); + MemWrite( &item->callstackSampleFat.thread, (uint64_t)tid ); + MemWrite( &item->callstackSampleFat.ptr, (uint64_t)trace ); + TracyLfqCommit; + } } } }