Fix samples order on save, not load.

Sorting samples during load was a major mistake, as three different background
processing threads were concurrently accessing the samples table, and it was
being sorted in one of them!
This commit is contained in:
Bartosz Taudul 2021-11-13 03:23:43 +01:00
parent 0ab73e2aa7
commit 81c66ad126
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 17 additions and 3 deletions

View File

@ -7,7 +7,7 @@ namespace Version
{ {
enum { Major = 0 }; enum { Major = 0 };
enum { Minor = 7 }; enum { Minor = 7 };
enum { Patch = 12 }; enum { Patch = 13 };
} }
} }

View File

@ -1898,6 +1898,14 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
{ {
m_backgroundDone.store( false, std::memory_order_relaxed ); m_backgroundDone.store( false, std::memory_order_relaxed );
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
if( fileVer < FileVersion( 0, 7, 13 ) )
{
for( auto& t : m_data.threads )
{
pdqsort_branchless( t->samples.begin(), t->samples.end(), [] ( const auto& lhs, const auto& rhs ) { return lhs.time.Val() < rhs.time.Val(); } );
}
}
m_threadBackground = std::thread( [this, eventMask] { m_threadBackground = std::thread( [this, eventMask] {
std::vector<std::thread> jobs; std::vector<std::thread> jobs;
@ -2022,8 +2030,6 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
for( auto& t : m_data.threads ) for( auto& t : m_data.threads )
{ {
if( m_shutdown.load( std::memory_order_relaxed ) ) return; if( m_shutdown.load( std::memory_order_relaxed ) ) return;
// TODO remove when proper sample order is achieved during capture
pdqsort_branchless( t->samples.begin(), t->samples.end(), [] ( const auto& lhs, const auto& rhs ) { return lhs.time.Val() < rhs.time.Val(); } );
for( auto& sd : t->samples ) for( auto& sd : t->samples )
{ {
gcnt += AddGhostZone( GetCallstack( sd.callstack.Val() ), &t->ghostZones, sd.time.Val() ); gcnt += AddGhostZone( GetCallstack( sd.callstack.Val() ), &t->ghostZones, sd.time.Val() );
@ -7882,6 +7888,14 @@ void Worker::Write( FileWrite& f, bool fiDict )
auto ptr = uint64_t( (MessageData*)v ); auto ptr = uint64_t( (MessageData*)v );
f.Write( &ptr, sizeof( ptr ) ); f.Write( &ptr, sizeof( ptr ) );
} }
if( m_inconsistentSamples )
{
#ifdef NO_PARALLEL_SORT
pdqsort_branchless( thread->samples.begin(), thread->samples.end(), [] ( const auto& lhs, const auto& rhs ) { return lhs.time.Val() < rhs.time.Val(); } );
#else
std::sort( std::execution::par_unseq, thread->samples.begin(), thread->samples.end(), [] ( const auto& lhs, const auto& rhs ) { return lhs.time.Val() < rhs.time.Val(); } );
#endif
}
sz = thread->samples.size(); sz = thread->samples.size();
f.Write( &sz, sizeof( sz ) ); f.Write( &sz, sizeof( sz ) );
refTime = 0; refTime = 0;