Pack start time and srcloc together in ZoneEvent.

This reduces ZoneEvent struct size by 2 bytes. Memory savings on various
captures:

10.62 GB -> 10.29 GB
 2342 MB ->  2276 MB
 1706 MB ->  1635 MB
 6277 MB ->  6085 MB
This commit is contained in:
Bartosz Taudul 2019-08-15 20:12:09 +02:00
parent 3e06daef31
commit bf3ad57456
4 changed files with 142 additions and 109 deletions

View File

@ -1,6 +1,7 @@
#ifndef __TRACYEVENT_HPP__ #ifndef __TRACYEVENT_HPP__
#define __TRACYEVENT_HPP__ #define __TRACYEVENT_HPP__
#include <assert.h>
#include <limits> #include <limits>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@ -75,9 +76,26 @@ enum { SourceLocationSize = sizeof( SourceLocation ) };
struct ZoneEvent struct ZoneEvent
{ {
int64_t start; int64_t Start() const
{
return int64_t( _start_srcloc ) >> 16;
}
void SetStart( int64_t start )
{
assert( start < ( 1ll << 47 ) );
_start_srcloc = ( _start_srcloc & 0xFFFF ) | ( start << 16 );
}
int16_t SrcLoc() const
{
return int16_t( _start_srcloc & 0xFFFF );
}
void SetSrcLoc( int16_t srcloc )
{
_start_srcloc = ( _start_srcloc & 0xFFFFFFFFFFFF0000 ) | srcloc;
}
uint64_t _start_srcloc;
int64_t end; int64_t end;
int16_t srcloc;
StringIdx text; StringIdx text;
uint32_t callstack; uint32_t callstack;
StringIdx name; StringIdx name;

View File

@ -2074,7 +2074,7 @@ void View::DrawZones()
} }
if( !v->timeline.empty() ) if( !v->timeline.empty() )
{ {
first = std::min( first, v->timeline.front()->start ); first = std::min( first, v->timeline.front()->Start() );
last = std::max( last, m_worker.GetZoneEnd( *v->timeline.back() ) ); last = std::max( last, m_worker.GetZoneEnd( *v->timeline.back() ) );
} }
if( !v->messages.empty() ) if( !v->messages.empty() )
@ -2516,7 +2516,7 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
auto it = std::lower_bound( vec.begin(), vec.end(), std::max<int64_t>( 0, m_zvStart - delay ), [] ( const auto& l, const auto& r ) { return (uint64_t)l->end < (uint64_t)r; } ); auto it = std::lower_bound( vec.begin(), vec.end(), std::max<int64_t>( 0, m_zvStart - delay ), [] ( const auto& l, const auto& r ) { return (uint64_t)l->end < (uint64_t)r; } );
if( it == vec.end() ) return depth; if( it == vec.end() ) return depth;
const auto zitend = std::lower_bound( it, vec.end(), m_zvEnd + resolution, [] ( const auto& l, const auto& r ) { return l->start < r; } ); const auto zitend = std::lower_bound( it, vec.end(), m_zvEnd + resolution, [] ( const auto& l, const auto& r ) { return l->Start() < r; } );
if( it == zitend ) return depth; if( it == zitend ) return depth;
if( (*it)->end < 0 && m_worker.GetZoneEnd( **it ) < m_zvStart ) return depth; if( (*it)->end < 0 && m_worker.GetZoneEnd( **it ) < m_zvStart ) return depth;
@ -2536,11 +2536,11 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
auto& ev = **it; auto& ev = **it;
const auto color = GetZoneColor( ev ); const auto color = GetZoneColor( ev );
const auto end = m_worker.GetZoneEnd( ev ); const auto end = m_worker.GetZoneEnd( ev );
const auto zsz = std::max( ( end - ev.start ) * pxns, pxns * 0.5 ); const auto zsz = std::max( ( end - ev.Start() ) * pxns, pxns * 0.5 );
if( zsz < MinVisSize ) if( zsz < MinVisSize )
{ {
int num = 0; int num = 0;
const auto px0 = ( ev.start - m_zvStart ) * pxns; const auto px0 = ( ev.Start() - m_zvStart ) * pxns;
auto px1 = ( end - m_zvStart ) * pxns; auto px1 = ( end - m_zvStart ) * pxns;
auto rend = end; auto rend = end;
auto nextTime = end + MinVisSize; auto nextTime = end + MinVisSize;
@ -2567,19 +2567,19 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
ImGui::BeginTooltip(); ImGui::BeginTooltip();
TextFocused( "Zones too small to display:", RealToString( num, true ) ); TextFocused( "Zones too small to display:", RealToString( num, true ) );
ImGui::Separator(); ImGui::Separator();
TextFocused( "Execution time:", TimeToString( rend - ev.start ) ); TextFocused( "Execution time:", TimeToString( rend - ev.Start() ) );
ImGui::EndTooltip(); ImGui::EndTooltip();
if( ImGui::IsMouseClicked( 2 ) && rend - ev.start > 0 ) if( ImGui::IsMouseClicked( 2 ) && rend - ev.Start() > 0 )
{ {
ZoomToRange( ev.start, rend ); ZoomToRange( ev.Start(), rend );
} }
} }
else else
{ {
ZoneTooltip( ev ); ZoneTooltip( ev );
if( ImGui::IsMouseClicked( 2 ) && rend - ev.start > 0 ) if( ImGui::IsMouseClicked( 2 ) && rend - ev.Start() > 0 )
{ {
ZoomToZone( ev ); ZoomToZone( ev );
} }
@ -2587,8 +2587,8 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
{ {
if( ImGui::GetIO().KeyCtrl ) if( ImGui::GetIO().KeyCtrl )
{ {
auto& srcloc = m_worker.GetSourceLocation( ev.srcloc ); auto& srcloc = m_worker.GetSourceLocation( ev.SrcLoc() );
m_findZone.ShowZone( ev.srcloc, m_worker.GetString( srcloc.name.active ? srcloc.name : srcloc.function ) ); m_findZone.ShowZone( ev.SrcLoc(), m_worker.GetString( srcloc.name.active ? srcloc.name : srcloc.function ) );
} }
else else
{ {
@ -2596,7 +2596,7 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
} }
} }
m_zoneSrcLocHighlight = ev.srcloc; m_zoneSrcLocHighlight = ev.SrcLoc();
m_zoneHover = &ev; m_zoneHover = &ev;
} }
} }
@ -2627,7 +2627,7 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
tsz = ImGui::CalcTextSize( zoneName ); tsz = ImGui::CalcTextSize( zoneName );
} }
const auto pr0 = ( ev.start - m_zvStart ) * pxns; const auto pr0 = ( ev.Start() - m_zvStart ) * pxns;
const auto pr1 = ( end - m_zvStart ) * pxns; const auto pr1 = ( end - m_zvStart ) * pxns;
const auto px0 = std::max( pr0, -10.0 ); const auto px0 = std::max( pr0, -10.0 );
const auto px1 = std::max( { std::min( pr1, double( w + 10 ) ), px0 + pxns * 0.5, px0 + MinVisSize } ); const auto px1 = std::max( { std::min( pr1, double( w + 10 ) ), px0 + pxns * 0.5, px0 + MinVisSize } );
@ -2672,14 +2672,14 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
} }
if( tsz.x < zsz ) if( tsz.x < zsz )
{ {
const auto x = ( ev.start - m_zvStart ) * pxns + ( ( end - ev.start ) * pxns - tsz.x ) / 2; const auto x = ( ev.Start() - m_zvStart ) * pxns + ( ( end - ev.Start() ) * pxns - tsz.x ) / 2;
if( x < 0 || x > w - tsz.x ) if( x < 0 || x > w - tsz.x )
{ {
ImGui::PushClipRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y * 2 ), true ); ImGui::PushClipRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y * 2 ), true );
DrawTextContrast( draw, wpos + ImVec2( std::max( std::max( 0., px0 ), std::min( double( w - tsz.x ), x ) ), offset ), 0xFFFFFFFF, zoneName ); DrawTextContrast( draw, wpos + ImVec2( std::max( std::max( 0., px0 ), std::min( double( w - tsz.x ), x ) ), offset ), 0xFFFFFFFF, zoneName );
ImGui::PopClipRect(); ImGui::PopClipRect();
} }
else if( ev.start == ev.end ) else if( ev.Start() == ev.end )
{ {
DrawTextContrast( draw, wpos + ImVec2( px0 + ( px1 - px0 - tsz.x ) * 0.5, offset ), 0xFFFFFFFF, zoneName ); DrawTextContrast( draw, wpos + ImVec2( px0 + ( px1 - px0 - tsz.x ) * 0.5, offset ), 0xFFFFFFFF, zoneName );
} }
@ -2691,7 +2691,7 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
else else
{ {
ImGui::PushClipRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y * 2 ), true ); ImGui::PushClipRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y * 2 ), true );
DrawTextContrast( draw, wpos + ImVec2( ( ev.start - m_zvStart ) * pxns, offset ), 0xFFFFFFFF, zoneName ); DrawTextContrast( draw, wpos + ImVec2( ( ev.Start() - m_zvStart ) * pxns, offset ), 0xFFFFFFFF, zoneName );
ImGui::PopClipRect(); ImGui::PopClipRect();
} }
@ -2707,8 +2707,8 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
{ {
if( ImGui::GetIO().KeyCtrl ) if( ImGui::GetIO().KeyCtrl )
{ {
auto& srcloc = m_worker.GetSourceLocation( ev.srcloc ); auto& srcloc = m_worker.GetSourceLocation( ev.SrcLoc() );
m_findZone.ShowZone( ev.srcloc, m_worker.GetString( srcloc.name.active ? srcloc.name : srcloc.function ) ); m_findZone.ShowZone( ev.SrcLoc(), m_worker.GetString( srcloc.name.active ? srcloc.name : srcloc.function ) );
} }
else else
{ {
@ -2716,7 +2716,7 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
} }
} }
m_zoneSrcLocHighlight = ev.srcloc; m_zoneSrcLocHighlight = ev.SrcLoc();
m_zoneHover = &ev; m_zoneHover = &ev;
} }
@ -2734,7 +2734,7 @@ int View::SkipZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
auto it = std::lower_bound( vec.begin(), vec.end(), m_zvStart - delay, [] ( const auto& l, const auto& r ) { return (uint64_t)l->end < (uint64_t)r; } ); auto it = std::lower_bound( vec.begin(), vec.end(), m_zvStart - delay, [] ( const auto& l, const auto& r ) { return (uint64_t)l->end < (uint64_t)r; } );
if( it == vec.end() ) return depth; if( it == vec.end() ) return depth;
const auto zitend = std::lower_bound( it, vec.end(), m_zvEnd + resolution, [] ( const auto& l, const auto& r ) { return l->start < r; } ); const auto zitend = std::lower_bound( it, vec.end(), m_zvEnd + resolution, [] ( const auto& l, const auto& r ) { return l->Start() < r; } );
if( it == zitend ) return depth; if( it == zitend ) return depth;
depth++; depth++;
@ -2744,7 +2744,7 @@ int View::SkipZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
{ {
auto& ev = **it; auto& ev = **it;
const auto end = m_worker.GetZoneEnd( ev ); const auto end = m_worker.GetZoneEnd( ev );
const auto zsz = std::max( ( end - ev.start ) * pxns, pxns * 0.5 ); const auto zsz = std::max( ( end - ev.Start() ) * pxns, pxns * 0.5 );
if( zsz < MinVisSize ) if( zsz < MinVisSize )
{ {
auto px1 = ( end - m_zvStart ) * pxns; auto px1 = ( end - m_zvStart ) * pxns;
@ -4531,7 +4531,7 @@ void View::DrawZoneInfoWindow()
auto& ev = *m_zoneInfoWindow; auto& ev = *m_zoneInfoWindow;
int dmul = 1; int dmul = 1;
const auto& srcloc = m_worker.GetSourceLocation( ev.srcloc ); const auto& srcloc = m_worker.GetSourceLocation( ev.SrcLoc() );
ImGui::SetNextWindowSize( ImVec2( 500, 400 ), ImGuiCond_FirstUseEver ); ImGui::SetNextWindowSize( ImVec2( 500, 400 ), ImGuiCond_FirstUseEver );
bool show = true; bool show = true;
@ -4565,7 +4565,7 @@ void View::DrawZoneInfoWindow()
if( ImGui::Button( "Statistics" ) ) if( ImGui::Button( "Statistics" ) )
#endif #endif
{ {
m_findZone.ShowZone( ev.srcloc, m_worker.GetString( srcloc.name.active ? srcloc.name : srcloc.function ) ); m_findZone.ShowZone( ev.SrcLoc(), m_worker.GetString( srcloc.name.active ? srcloc.name : srcloc.function ) );
} }
if( ev.callstack != 0 ) if( ev.callstack != 0 )
{ {
@ -4669,12 +4669,12 @@ void View::DrawZoneInfoWindow()
ImGui::BeginChild( "##zoneinfo" ); ImGui::BeginChild( "##zoneinfo" );
const auto end = m_worker.GetZoneEnd( ev ); const auto end = m_worker.GetZoneEnd( ev );
const auto ztime = end - ev.start; const auto ztime = end - ev.Start();
const auto selftime = GetZoneSelfTime( ev ); const auto selftime = GetZoneSelfTime( ev );
TextFocused( "Time from start of program:", TimeToString( ev.start - m_worker.GetTimeBegin() ) ); TextFocused( "Time from start of program:", TimeToString( ev.Start() - m_worker.GetTimeBegin() ) );
TextFocused( "Execution time:", TimeToString( ztime ) ); TextFocused( "Execution time:", TimeToString( ztime ) );
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
auto& zoneData = m_worker.GetZonesForSourceLocation( ev.srcloc ); auto& zoneData = m_worker.GetZonesForSourceLocation( ev.SrcLoc() );
ImGui::SameLine(); ImGui::SameLine();
ImGui::TextDisabled( "(%.2f%% of average time)", float( ztime ) / zoneData.total * zoneData.zones.size() * 100 ); ImGui::TextDisabled( "(%.2f%% of average time)", float( ztime ) / zoneData.total * zoneData.zones.size() * 100 );
#endif #endif
@ -4687,7 +4687,7 @@ void View::DrawZoneInfoWindow()
const auto ctx = m_worker.GetContextSwitchData( tid ); const auto ctx = m_worker.GetContextSwitchData( tid );
if( ctx ) if( ctx )
{ {
auto it = std::lower_bound( ctx->v.begin(), ctx->v.end(), ev.start, [] ( const auto& l, const auto& r ) { return (uint64_t)l.end < (uint64_t)r; } ); auto it = std::lower_bound( ctx->v.begin(), ctx->v.end(), ev.Start(), [] ( const auto& l, const auto& r ) { return (uint64_t)l.end < (uint64_t)r; } );
if( it != ctx->v.end() ) if( it != ctx->v.end() )
{ {
const auto end = m_worker.GetZoneEnd( ev ); const auto end = m_worker.GetZoneEnd( ev );
@ -4710,7 +4710,7 @@ void View::DrawZoneInfoWindow()
{ {
uint8_t cpus[256] = {}; uint8_t cpus[256] = {};
auto bit = it; auto bit = it;
int64_t running = it->end - ev.start; int64_t running = it->end - ev.Start();
cpus[it->cpu] = 1; cpus[it->cpu] = 1;
++it; ++it;
for( int64_t i=0; i<cnt-2; i++ ) for( int64_t i=0; i<cnt-2; i++ )
@ -4766,7 +4766,7 @@ void View::DrawZoneInfoWindow()
if( ImGui::TreeNode( "Wait regions" ) ) if( ImGui::TreeNode( "Wait regions" ) )
{ {
SmallCheckbox( "Time relative to zone start", &m_ctxSwitchTimeRelativeToZone ); SmallCheckbox( "Time relative to zone start", &m_ctxSwitchTimeRelativeToZone );
const int64_t adjust = m_ctxSwitchTimeRelativeToZone ? ev.start : m_worker.GetTimeBegin(); const int64_t adjust = m_ctxSwitchTimeRelativeToZone ? ev.Start() : m_worker.GetTimeBegin();
ImGui::Columns( 5 ); ImGui::Columns( 5 );
ImGui::Text( "Begin" ); ImGui::Text( "Begin" );
@ -4853,10 +4853,10 @@ void View::DrawZoneInfoWindow()
{ {
const auto thread = m_worker.CompressThread( tid ); const auto thread = m_worker.CompressThread( tid );
auto ait = std::lower_bound( mem.data.begin(), mem.data.end(), ev.start, [] ( const auto& l, const auto& r ) { return l.timeAlloc < r; } ); auto ait = std::lower_bound( mem.data.begin(), mem.data.end(), ev.Start(), [] ( const auto& l, const auto& r ) { return l.timeAlloc < r; } );
const auto aend = std::upper_bound( mem.data.begin(), mem.data.end(), end, [] ( const auto& l, const auto& r ) { return l < r.timeAlloc; } ); const auto aend = std::upper_bound( mem.data.begin(), mem.data.end(), end, [] ( const auto& l, const auto& r ) { return l < r.timeAlloc; } );
auto fit = std::lower_bound( mem.frees.begin(), mem.frees.end(), ev.start, [&mem] ( const auto& l, const auto& r ) { return mem.data[l].timeFree < r; } ); auto fit = std::lower_bound( mem.frees.begin(), mem.frees.end(), ev.Start(), [&mem] ( const auto& l, const auto& r ) { return mem.data[l].timeFree < r; } );
const auto fend = std::upper_bound( mem.frees.begin(), mem.frees.end(), end, [&mem] ( const auto& l, const auto& r ) { return l < mem.data[r].timeFree; } ); const auto fend = std::upper_bound( mem.frees.begin(), mem.frees.end(), end, [&mem] ( const auto& l, const auto& r ) { return l < mem.data[r].timeFree; } );
const auto aDist = std::distance( ait, aend ); const auto aDist = std::distance( ait, aend );
@ -4945,7 +4945,7 @@ void View::DrawZoneInfoWindow()
ListMemData<decltype( v.begin() )>( v.begin(), v.end(), []( auto& v ) { ListMemData<decltype( v.begin() )>( v.begin(), v.end(), []( auto& v ) {
ImGui::Text( "0x%" PRIx64, (*v)->ptr ); ImGui::Text( "0x%" PRIx64, (*v)->ptr );
}, nullptr, m_allocTimeRelativeToZone ? ev.start : -1 ); }, nullptr, m_allocTimeRelativeToZone ? ev.Start() : -1 );
ImGui::TreePop(); ImGui::TreePop();
} }
} }
@ -4961,7 +4961,7 @@ void View::DrawZoneInfoWindow()
} }
else else
{ {
auto msgit = std::lower_bound( threadData->messages.begin(), threadData->messages.end(), ev.start, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } ); auto msgit = std::lower_bound( threadData->messages.begin(), threadData->messages.end(), ev.Start(), [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } );
auto msgend = std::lower_bound( msgit, threadData->messages.end(), end+1, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } ); auto msgend = std::lower_bound( msgit, threadData->messages.end(), end+1, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } );
const auto dist = std::distance( msgit, msgend ); const auto dist = std::distance( msgit, msgend );
@ -4993,7 +4993,7 @@ void View::DrawZoneInfoWindow()
do do
{ {
ImGui::PushID( *msgit ); ImGui::PushID( *msgit );
if( ImGui::Selectable( TimeToString( (*msgit)->time - ev.start ), m_msgHighlight == *msgit, ImGuiSelectableFlags_SpanAllColumns ) ) if( ImGui::Selectable( TimeToString( (*msgit)->time - ev.Start() ), m_msgHighlight == *msgit, ImGuiSelectableFlags_SpanAllColumns ) )
{ {
CenterAtTime( (*msgit)->time ); CenterAtTime( (*msgit)->time );
} }
@ -5029,7 +5029,7 @@ void View::DrawZoneInfoWindow()
DrawZoneTrace<const ZoneEvent*>( &ev, zoneTrace, m_worker, m_zoneinfoBuzzAnim, *this, m_showUnknownFrames, [&idx, this] ( const ZoneEvent* v, int& fidx ) { DrawZoneTrace<const ZoneEvent*>( &ev, zoneTrace, m_worker, m_zoneinfoBuzzAnim, *this, m_showUnknownFrames, [&idx, this] ( const ZoneEvent* v, int& fidx ) {
ImGui::TextDisabled( "%i.", fidx++ ); ImGui::TextDisabled( "%i.", fidx++ );
ImGui::SameLine(); ImGui::SameLine();
const auto& srcloc = m_worker.GetSourceLocation( v->srcloc ); const auto& srcloc = m_worker.GetSourceLocation( v->SrcLoc() );
const auto txt = m_worker.GetZoneName( *v, srcloc ); const auto txt = m_worker.GetZoneName( *v, srcloc );
ImGui::PushID( idx++ ); ImGui::PushID( idx++ );
auto sel = ImGui::Selectable( txt, false ); auto sel = ImGui::Selectable( txt, false );
@ -5045,7 +5045,7 @@ void View::DrawZoneInfoWindow()
{ {
ImGui::SameLine(); ImGui::SameLine();
} }
ImGui::TextDisabled( "(%s) %s:%i", TimeToString( m_worker.GetZoneEnd( *v ) - v->start ), fileName, srcloc.line ); ImGui::TextDisabled( "(%s) %s:%i", TimeToString( m_worker.GetZoneEnd( *v ) - v->Start() ), fileName, srcloc.line );
ImGui::PopID(); ImGui::PopID();
if( ImGui::IsItemClicked( 1 ) ) if( ImGui::IsItemClicked( 1 ) )
{ {
@ -5102,8 +5102,8 @@ void View::DrawZoneInfoWindow()
{ {
const auto& child = *children[i]; const auto& child = *children[i];
const auto cend = m_worker.GetZoneEnd( child ); const auto cend = m_worker.GetZoneEnd( child );
const auto ct = cend - child.start; const auto ct = cend - child.Start();
const auto srcloc = child.srcloc; const auto srcloc = child.SrcLoc();
ctime += ct; ctime += ct;
auto it = cmap.find( srcloc ); auto it = cmap.find( srcloc );
@ -5192,7 +5192,7 @@ void View::DrawZoneInfoWindow()
{ {
const auto& child = *children[cgr.v[i]]; const auto& child = *children[cgr.v[i]];
const auto cend = m_worker.GetZoneEnd( child ); const auto cend = m_worker.GetZoneEnd( child );
const auto ct = cend - child.start; const auto ct = cend - child.Start();
ctt[i] = ct; ctt[i] = ct;
cti[i] = uint32_t( i ); cti[i] = uint32_t( i );
} }
@ -5242,7 +5242,7 @@ void View::DrawZoneInfoWindow()
{ {
const auto& child = *children[i]; const auto& child = *children[i];
const auto cend = m_worker.GetZoneEnd( child ); const auto cend = m_worker.GetZoneEnd( child );
const auto ct = cend - child.start; const auto ct = cend - child.Start();
ctime += ct; ctime += ct;
ctt[i] = ct; ctt[i] = ct;
cti[i] = uint32_t( i ); cti[i] = uint32_t( i );
@ -6623,7 +6623,7 @@ void View::DrawFindZone()
{ {
auto& zone = *zones[i].zone; auto& zone = *zones[i].zone;
if( zone.end < 0 ) break; if( zone.end < 0 ) break;
const auto t = zone.end - zone.start - GetZoneChildTimeFast( zone ); const auto t = zone.end - zone.Start() - GetZoneChildTimeFast( zone );
vec.emplace_back( t ); vec.emplace_back( t );
total += t; total += t;
} }
@ -6636,7 +6636,7 @@ void View::DrawFindZone()
{ {
auto& zone = *zones[i].zone; auto& zone = *zones[i].zone;
if( zone.end < 0 ) break; if( zone.end < 0 ) break;
const auto t = zone.end - zone.start; const auto t = zone.end - zone.Start();
vec.emplace_back( t ); vec.emplace_back( t );
total += t; total += t;
} }
@ -6689,7 +6689,7 @@ void View::DrawFindZone()
auto& ev = zones[i]; auto& ev = zones[i];
if( selGroup == GetSelectionTarget( ev, groupBy ) ) if( selGroup == GetSelectionTarget( ev, groupBy ) )
{ {
const auto t = ev.zone->end - ev.zone->start - GetZoneChildTimeFast( *ev.zone ); const auto t = ev.zone->end - ev.zone->Start() - GetZoneChildTimeFast( *ev.zone );
vec.emplace_back( t ); vec.emplace_back( t );
act++; act++;
total += t; total += t;
@ -6703,7 +6703,7 @@ void View::DrawFindZone()
auto& ev = zones[i]; auto& ev = zones[i];
if( selGroup == GetSelectionTarget( ev, groupBy ) ) if( selGroup == GetSelectionTarget( ev, groupBy ) )
{ {
const auto t = ev.zone->end - ev.zone->start; const auto t = ev.zone->end - ev.zone->Start();
vec.emplace_back( t ); vec.emplace_back( t );
act++; act++;
total += t; total += t;
@ -7364,9 +7364,9 @@ void View::DrawFindZone()
draw->PopClipRect(); draw->PopClipRect();
} }
if( m_zoneHover && m_findZone.match[m_findZone.selMatch] == m_zoneHover->srcloc ) if( m_zoneHover && m_findZone.match[m_findZone.selMatch] == m_zoneHover->SrcLoc() )
{ {
const auto zoneTime = m_worker.GetZoneEnd( *m_zoneHover ) - m_zoneHover->start; const auto zoneTime = m_worker.GetZoneEnd( *m_zoneHover ) - m_zoneHover->Start();
float zonePos; float zonePos;
if( m_findZone.logTime ) if( m_findZone.logTime )
{ {
@ -7433,7 +7433,7 @@ void View::DrawFindZone()
if( ev.zone->end < 0 ) break; if( ev.zone->end < 0 ) break;
const auto end = m_worker.GetZoneEndDirect( *ev.zone ); const auto end = m_worker.GetZoneEndDirect( *ev.zone );
auto timespan = end - ev.zone->start; auto timespan = end - ev.zone->Start();
if( timespan == 0 ) if( timespan == 0 )
{ {
processed++; processed++;
@ -7722,8 +7722,8 @@ void View::DrawZoneList( const Vector<ZoneEvent*>& zones )
if( m_findZone.selfTime ) if( m_findZone.selfTime )
{ {
pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) {
return m_worker.GetZoneEndDirect( *lhs ) - lhs->start - this->GetZoneChildTimeFast( *lhs ) > return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() - this->GetZoneChildTimeFast( *lhs ) >
m_worker.GetZoneEndDirect( *rhs ) - rhs->start - this->GetZoneChildTimeFast( *rhs ); m_worker.GetZoneEndDirect( *rhs ) - rhs->Start() - this->GetZoneChildTimeFast( *rhs );
} ); } );
} }
else if( m_findZone.runningTime ) else if( m_findZone.runningTime )
@ -7741,7 +7741,7 @@ void View::DrawZoneList( const Vector<ZoneEvent*>& zones )
else else
{ {
pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) { pdqsort_branchless( sortedZones.begin(), sortedZones.end(), [this]( const auto& lhs, const auto& rhs ) {
return m_worker.GetZoneEndDirect( *lhs ) - lhs->start > m_worker.GetZoneEndDirect( *rhs ) - rhs->start; return m_worker.GetZoneEndDirect( *lhs ) - lhs->Start() > m_worker.GetZoneEndDirect( *rhs ) - rhs->Start();
} ); } );
} }
break; break;
@ -7769,12 +7769,12 @@ void View::DrawZoneList( const Vector<ZoneEvent*>& zones )
} }
else else
{ {
timespan = end - ev->start; timespan = end - ev->Start();
if( m_findZone.selfTime ) timespan -= GetZoneChildTimeFast( *ev ); if( m_findZone.selfTime ) timespan -= GetZoneChildTimeFast( *ev );
} }
ImGui::PushID( ev ); ImGui::PushID( ev );
if( ImGui::Selectable( TimeToString( ev->start - m_worker.GetTimeBegin() ), m_zoneInfoWindow == ev, ImGuiSelectableFlags_SpanAllColumns ) ) if( ImGui::Selectable( TimeToString( ev->Start() - m_worker.GetTimeBegin() ), m_zoneInfoWindow == ev, ImGuiSelectableFlags_SpanAllColumns ) )
{ {
ShowZoneInfo( *ev ); ShowZoneInfo( *ev );
} }
@ -8099,7 +8099,7 @@ void View::DrawCompare()
{ {
auto& zone = *zones[i].zone; auto& zone = *zones[i].zone;
if( zone.end < 0 ) break; if( zone.end < 0 ) break;
const auto t = zone.end - zone.start; const auto t = zone.end - zone.Start();
vec.emplace_back( t ); vec.emplace_back( t );
total += t; total += t;
} }
@ -9036,7 +9036,7 @@ void View::DrawMemoryAllocWindow()
auto zoneAlloc = FindZoneAtTime( tidAlloc, ev.timeAlloc ); auto zoneAlloc = FindZoneAtTime( tidAlloc, ev.timeAlloc );
if( zoneAlloc ) if( zoneAlloc )
{ {
const auto& srcloc = m_worker.GetSourceLocation( zoneAlloc->srcloc ); const auto& srcloc = m_worker.GetSourceLocation( zoneAlloc->SrcLoc() );
const auto txt = srcloc.name.active ? m_worker.GetString( srcloc.name ) : m_worker.GetString( srcloc.function ); const auto txt = srcloc.name.active ? m_worker.GetString( srcloc.name ) : m_worker.GetString( srcloc.function );
ImGui::PushID( idx++ ); ImGui::PushID( idx++ );
TextFocused( "Zone alloc:", txt ); TextFocused( "Zone alloc:", txt );
@ -9062,7 +9062,7 @@ void View::DrawMemoryAllocWindow()
auto zoneFree = FindZoneAtTime( tidFree, ev.timeFree ); auto zoneFree = FindZoneAtTime( tidFree, ev.timeFree );
if( zoneFree ) if( zoneFree )
{ {
const auto& srcloc = m_worker.GetSourceLocation( zoneFree->srcloc ); const auto& srcloc = m_worker.GetSourceLocation( zoneFree->SrcLoc() );
const auto txt = srcloc.name.active ? m_worker.GetString( srcloc.name ) : m_worker.GetString( srcloc.function ); const auto txt = srcloc.name.active ? m_worker.GetString( srcloc.name ) : m_worker.GetString( srcloc.function );
TextFocused( "Zone free:", txt ); TextFocused( "Zone free:", txt );
auto hover = ImGui::IsItemHovered(); auto hover = ImGui::IsItemHovered();
@ -10216,7 +10216,7 @@ void View::ListMemData( T ptr, T end, std::function<void(T&)> DrawAddress, const
} }
else else
{ {
const auto& srcloc = m_worker.GetSourceLocation( zone->srcloc ); const auto& srcloc = m_worker.GetSourceLocation( zone->SrcLoc() );
const auto txt = srcloc.name.active ? m_worker.GetString( srcloc.name ) : m_worker.GetString( srcloc.function ); const auto txt = srcloc.name.active ? m_worker.GetString( srcloc.name ) : m_worker.GetString( srcloc.function );
ImGui::PushID( idx++ ); ImGui::PushID( idx++ );
auto sel = ImGui::Selectable( txt, m_zoneInfoWindow == zone ); auto sel = ImGui::Selectable( txt, m_zoneInfoWindow == zone );
@ -10250,7 +10250,7 @@ void View::ListMemData( T ptr, T end, std::function<void(T&)> DrawAddress, const
} }
else else
{ {
const auto& srcloc = m_worker.GetSourceLocation( zoneFree->srcloc ); const auto& srcloc = m_worker.GetSourceLocation( zoneFree->SrcLoc() );
const auto txt = srcloc.name.active ? m_worker.GetString( srcloc.name ) : m_worker.GetString( srcloc.function ); const auto txt = srcloc.name.active ? m_worker.GetString( srcloc.name ) : m_worker.GetString( srcloc.function );
ImGui::PushID( idx++ ); ImGui::PushID( idx++ );
bool sel; bool sel;
@ -11052,13 +11052,13 @@ const char* View::GetPlotName( const PlotData* plot ) const
uint32_t View::GetZoneColor( const ZoneEvent& ev ) uint32_t View::GetZoneColor( const ZoneEvent& ev )
{ {
if( m_findZone.show && !m_findZone.match.empty() && m_findZone.match[m_findZone.selMatch] == ev.srcloc ) if( m_findZone.show && !m_findZone.match.empty() && m_findZone.match[m_findZone.selMatch] == ev.SrcLoc() )
{ {
return 0xFF229999; return 0xFF229999;
} }
else else
{ {
const auto& srcloc = m_worker.GetSourceLocation( ev.srcloc ); const auto& srcloc = m_worker.GetSourceLocation( ev.SrcLoc() );
const auto color = srcloc.color; const auto color = srcloc.color;
return color != 0 ? ( color | 0xFF000000 ) : 0xFFCC5555; return color != 0 ? ( color | 0xFF000000 ) : 0xFFCC5555;
} }
@ -11081,7 +11081,7 @@ uint32_t View::GetZoneHighlight( const ZoneEvent& ev )
{ {
return 0xFF4444FF; return 0xFF4444FF;
} }
else if( m_zoneSrcLocHighlight == ev.srcloc ) else if( m_zoneSrcLocHighlight == ev.SrcLoc() )
{ {
return 0xFFEEEEEE; return 0xFFEEEEEE;
} }
@ -11117,7 +11117,7 @@ uint32_t View::GetZoneHighlight( const GpuEvent& ev )
float View::GetZoneThickness( const ZoneEvent& ev ) float View::GetZoneThickness( const ZoneEvent& ev )
{ {
if( m_zoneInfoWindow == &ev || m_zoneHighlight == &ev || ( m_findZone.show && !m_findZone.match.empty() && m_findZone.match[m_findZone.selMatch] == ev.srcloc ) ) if( m_zoneInfoWindow == &ev || m_zoneHighlight == &ev || ( m_findZone.show && !m_findZone.match.empty() && m_findZone.match[m_findZone.selMatch] == ev.SrcLoc() ) )
{ {
return 3.f; return 3.f;
} }
@ -11142,8 +11142,8 @@ float View::GetZoneThickness( const GpuEvent& ev )
void View::ZoomToZone( const ZoneEvent& ev ) void View::ZoomToZone( const ZoneEvent& ev )
{ {
const auto end = m_worker.GetZoneEnd( ev ); const auto end = m_worker.GetZoneEnd( ev );
if( end - ev.start <= 0 ) return; if( end - ev.Start() <= 0 ) return;
ZoomToRange( ev.start, end ); ZoomToRange( ev.Start(), end );
} }
void View::ZoomToZone( const GpuEvent& ev ) void View::ZoomToZone( const GpuEvent& ev )
@ -11273,9 +11273,9 @@ void View::ShowZoneInfo( const GpuEvent& ev, uint64_t thread )
void View::ZoneTooltip( const ZoneEvent& ev ) void View::ZoneTooltip( const ZoneEvent& ev )
{ {
const auto tid = GetZoneThread( ev ); const auto tid = GetZoneThread( ev );
auto& srcloc = m_worker.GetSourceLocation( ev.srcloc ); auto& srcloc = m_worker.GetSourceLocation( ev.SrcLoc() );
const auto end = m_worker.GetZoneEnd( ev ); const auto end = m_worker.GetZoneEnd( ev );
const auto ztime = end - ev.start; const auto ztime = end - ev.Start();
const auto selftime = GetZoneSelfTime( ev ); const auto selftime = GetZoneSelfTime( ev );
ImGui::BeginTooltip(); ImGui::BeginTooltip();
@ -11296,7 +11296,7 @@ void View::ZoneTooltip( const ZoneEvent& ev )
ImGui::Separator(); ImGui::Separator();
TextFocused( "Execution time:", TimeToString( ztime ) ); TextFocused( "Execution time:", TimeToString( ztime ) );
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
auto& zoneData = m_worker.GetZonesForSourceLocation( ev.srcloc ); auto& zoneData = m_worker.GetZonesForSourceLocation( ev.SrcLoc() );
ImGui::SameLine(); ImGui::SameLine();
ImGui::TextDisabled( "(%.2f%% of average time)", float( ztime ) / zoneData.total * zoneData.zones.size() * 100 ); ImGui::TextDisabled( "(%.2f%% of average time)", float( ztime ) / zoneData.total * zoneData.zones.size() * 100 );
#endif #endif
@ -11442,9 +11442,9 @@ const ZoneEvent* View::GetZoneParent( const ZoneEvent& zone ) const
if( timeline->empty() ) continue; if( timeline->empty() ) continue;
for(;;) for(;;)
{ {
auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.start, [] ( const auto& l, const auto& r ) { return l < r->start; } ); auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r->Start(); } );
if( it != timeline->begin() ) --it; if( it != timeline->begin() ) --it;
if( zone.end >= 0 && (*it)->start > zone.end ) break; if( zone.end >= 0 && (*it)->Start() > zone.end ) break;
if( *it == &zone ) return parent; if( *it == &zone ) return parent;
if( (*it)->child < 0 ) break; if( (*it)->child < 0 ) break;
parent = *it; parent = *it;
@ -11483,9 +11483,9 @@ const ThreadData* View::GetZoneThreadData( const ZoneEvent& zone ) const
if( timeline->empty() ) continue; if( timeline->empty() ) continue;
for(;;) for(;;)
{ {
auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.start, [] ( const auto& l, const auto& r ) { return l < r->start; } ); auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r->Start(); } );
if( it != timeline->begin() ) --it; if( it != timeline->begin() ) --it;
if( zone.end >= 0 && (*it)->start > zone.end ) break; if( zone.end >= 0 && (*it)->Start() > zone.end ) break;
if( *it == &zone ) return thread; if( *it == &zone ) return thread;
if( (*it)->child < 0 ) break; if( (*it)->child < 0 ) break;
timeline = &m_worker.GetZoneChildren( (*it)->child ); timeline = &m_worker.GetZoneChildren( (*it)->child );
@ -11564,9 +11564,9 @@ const ZoneEvent* View::FindZoneAtTime( uint64_t thread, int64_t time ) const
ZoneEvent* ret = nullptr; ZoneEvent* ret = nullptr;
for(;;) for(;;)
{ {
auto it = std::upper_bound( timeline->begin(), timeline->end(), time, [] ( const auto& l, const auto& r ) { return l < r->start; } ); auto it = std::upper_bound( timeline->begin(), timeline->end(), time, [] ( const auto& l, const auto& r ) { return l < r->Start(); } );
if( it != timeline->begin() ) --it; if( it != timeline->begin() ) --it;
if( (*it)->start > time || ( (*it)->end >= 0 && (*it)->end < time ) ) return ret; if( (*it)->Start() > time || ( (*it)->end >= 0 && (*it)->end < time ) ) return ret;
ret = *it; ret = *it;
if( (*it)->child < 0 ) return ret; if( (*it)->child < 0 ) return ret;
timeline = &m_worker.GetZoneChildren( (*it)->child ); timeline = &m_worker.GetZoneChildren( (*it)->child );
@ -11676,7 +11676,7 @@ int64_t View::GetZoneChildTime( const ZoneEvent& zone )
{ {
for( auto& v : m_worker.GetZoneChildren( zone.child ) ) for( auto& v : m_worker.GetZoneChildren( zone.child ) )
{ {
const auto childSpan = std::max( int64_t( 0 ), v->end - v->start ); const auto childSpan = std::max( int64_t( 0 ), v->end - v->Start() );
time += childSpan; time += childSpan;
} }
} }
@ -11705,7 +11705,7 @@ int64_t View::GetZoneChildTimeFast( const ZoneEvent& zone )
for( auto& v : m_worker.GetZoneChildren( zone.child ) ) for( auto& v : m_worker.GetZoneChildren( zone.child ) )
{ {
assert( v->end >= 0 ); assert( v->end >= 0 );
time += v->end - v->start; time += v->end - v->Start();
} }
} }
return time; return time;
@ -11715,7 +11715,7 @@ int64_t View::GetZoneSelfTime( const ZoneEvent& zone )
{ {
if( m_cache.zoneSelfTime.first == &zone ) return m_cache.zoneSelfTime.second; if( m_cache.zoneSelfTime.first == &zone ) return m_cache.zoneSelfTime.second;
if( m_cache.zoneSelfTime2.first == &zone ) return m_cache.zoneSelfTime2.second; if( m_cache.zoneSelfTime2.first == &zone ) return m_cache.zoneSelfTime2.second;
const auto ztime = m_worker.GetZoneEnd( zone ) - zone.start; const auto ztime = m_worker.GetZoneEnd( zone ) - zone.Start();
const auto selftime = ztime - GetZoneChildTime( zone ); const auto selftime = ztime - GetZoneChildTime( zone );
if( zone.end >= 0 ) if( zone.end >= 0 )
{ {
@ -11741,7 +11741,7 @@ int64_t View::GetZoneSelfTime( const GpuEvent& zone )
bool View::GetZoneRunningTime( const ContextSwitch* ctx, const ZoneEvent& ev, int64_t& time, uint64_t& cnt ) bool View::GetZoneRunningTime( const ContextSwitch* ctx, const ZoneEvent& ev, int64_t& time, uint64_t& cnt )
{ {
auto it = std::lower_bound( ctx->v.begin(), ctx->v.end(), ev.start, [] ( const auto& l, const auto& r ) { return (uint64_t)l.end < (uint64_t)r; } ); auto it = std::lower_bound( ctx->v.begin(), ctx->v.end(), ev.Start(), [] ( const auto& l, const auto& r ) { return (uint64_t)l.end < (uint64_t)r; } );
if( it == ctx->v.end() ) return false; if( it == ctx->v.end() ) return false;
const auto end = m_worker.GetZoneEnd( ev ); const auto end = m_worker.GetZoneEnd( ev );
const auto eit = std::upper_bound( it, ctx->v.end(), end, [] ( const auto& l, const auto& r ) { return l < r.start; } ); const auto eit = std::upper_bound( it, ctx->v.end(), end, [] ( const auto& l, const auto& r ) { return l < r.start; } );
@ -11750,11 +11750,11 @@ bool View::GetZoneRunningTime( const ContextSwitch* ctx, const ZoneEvent& ev, in
if( cnt == 0 ) return false; if( cnt == 0 ) return false;
if( cnt == 1 ) if( cnt == 1 )
{ {
time = end - ev.start; time = end - ev.Start();
} }
else else
{ {
int64_t running = it->end - ev.start; int64_t running = it->end - ev.Start();
++it; ++it;
for( int64_t i=0; i<cnt-2; i++ ) for( int64_t i=0; i<cnt-2; i++ )
{ {

View File

@ -1386,9 +1386,9 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
{ {
auto& zones = v.second.zones; auto& zones = v.second.zones;
#ifdef MY_LIBCPP_SUCKS #ifdef MY_LIBCPP_SUCKS
pdqsort_branchless( zones.begin(), zones.end(), []( const auto& lhs, const auto& rhs ) { return lhs.zone->start < rhs.zone->start; } ); pdqsort_branchless( zones.begin(), zones.end(), []( const auto& lhs, const auto& rhs ) { return lhs.zone->Start() < rhs.zone->Start(); } );
#else #else
std::sort( std::execution::par_unseq, zones.begin(), zones.end(), []( const auto& lhs, const auto& rhs ) { return lhs.zone->start < rhs.zone->start; } ); std::sort( std::execution::par_unseq, zones.begin(), zones.end(), []( const auto& lhs, const auto& rhs ) { return lhs.zone->Start() < rhs.zone->Start(); } );
#endif #endif
} }
{ {
@ -1623,7 +1623,7 @@ int64_t Worker::GetZoneEnd( const ZoneEvent& ev )
for(;;) for(;;)
{ {
if( ptr->end >= 0 ) return ptr->end; if( ptr->end >= 0 ) return ptr->end;
if( ptr->child < 0 ) return ptr->start; if( ptr->child < 0 ) return ptr->Start();
ptr = GetZoneChildren( ptr->child ).back(); ptr = GetZoneChildren( ptr->child ).back();
} }
} }
@ -1719,7 +1719,7 @@ const char* Worker::GetZoneName( const SourceLocation& srcloc ) const
const char* Worker::GetZoneName( const ZoneEvent& ev ) const const char* Worker::GetZoneName( const ZoneEvent& ev ) const
{ {
auto& srcloc = GetSourceLocation( ev.srcloc ); auto& srcloc = GetSourceLocation( ev.SrcLoc() );
return GetZoneName( ev, srcloc ); return GetZoneName( ev, srcloc );
} }
@ -2249,11 +2249,11 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread )
m_data.zonesCnt++; m_data.zonesCnt++;
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
auto it = m_data.sourceLocationZones.find( zone->srcloc ); auto it = m_data.sourceLocationZones.find( zone->SrcLoc() );
assert( it != m_data.sourceLocationZones.end() ); assert( it != m_data.sourceLocationZones.end() );
it->second.zones.push_back( ZoneThreadData { zone, CompressThread( thread ) } ); it->second.zones.push_back( ZoneThreadData { zone, CompressThread( thread ) } );
#else #else
auto it = m_data.sourceLocationZonesCnt.find( zone->srcloc ); auto it = m_data.sourceLocationZonesCnt.find( zone->SrcLoc() );
assert( it != m_data.sourceLocationZonesCnt.end() ); assert( it != m_data.sourceLocationZonesCnt.end() );
it->second++; it->second++;
#endif #endif
@ -2879,13 +2879,14 @@ void Worker::ProcessZoneBeginImpl( ZoneEvent* zone, const QueueZoneBegin& ev )
{ {
CheckSourceLocation( ev.srcloc ); CheckSourceLocation( ev.srcloc );
zone->start = TscTime( ev.time - m_data.baseTime ); const auto start = TscTime( ev.time - m_data.baseTime );
zone->SetStart( start );
zone->end = -1; zone->end = -1;
zone->srcloc = ShrinkSourceLocation( ev.srcloc ); zone->SetSrcLoc( ShrinkSourceLocation( ev.srcloc ) );
zone->callstack = 0; zone->callstack = 0;
zone->child = -1; zone->child = -1;
m_data.lastTime = std::max( m_data.lastTime, zone->start ); m_data.lastTime = std::max( m_data.lastTime, start );
NewZone( zone, m_threadCtx ); NewZone( zone, m_threadCtx );
} }
@ -2911,13 +2912,14 @@ void Worker::ProcessZoneBeginAllocSrcLocImpl( ZoneEvent* zone, const QueueZoneBe
auto it = m_pendingSourceLocationPayload.find( ev.srcloc ); auto it = m_pendingSourceLocationPayload.find( ev.srcloc );
assert( it != m_pendingSourceLocationPayload.end() ); assert( it != m_pendingSourceLocationPayload.end() );
zone->start = TscTime( ev.time - m_data.baseTime ); const auto start = TscTime( ev.time - m_data.baseTime );
zone->SetStart( start );
zone->end = -1; zone->end = -1;
zone->srcloc = it->second; zone->SetSrcLoc( it->second );
zone->callstack = 0; zone->callstack = 0;
zone->child = -1; zone->child = -1;
m_data.lastTime = std::max( m_data.lastTime, zone->start ); m_data.lastTime = std::max( m_data.lastTime, start );
NewZone( zone, m_threadCtx ); NewZone( zone, m_threadCtx );
@ -2963,7 +2965,7 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev )
auto zone = stack.back_and_pop(); auto zone = stack.back_and_pop();
assert( zone->end == -1 ); assert( zone->end == -1 );
zone->end = TscTime( ev.time - m_data.baseTime ); zone->end = TscTime( ev.time - m_data.baseTime );
assert( zone->end >= zone->start ); assert( zone->end >= zone->Start() );
m_data.lastTime = std::max( m_data.lastTime, zone->end ); m_data.lastTime = std::max( m_data.lastTime, zone->end );
@ -2982,10 +2984,10 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev )
} }
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
auto timeSpan = zone->end - zone->start; auto timeSpan = zone->end - zone->Start();
if( timeSpan > 0 ) if( timeSpan > 0 )
{ {
auto it = m_data.sourceLocationZones.find( zone->srcloc ); auto it = m_data.sourceLocationZones.find( zone->SrcLoc() );
assert( it != m_data.sourceLocationZones.end() ); assert( it != m_data.sourceLocationZones.end() );
auto& slz = it->second; auto& slz = it->second;
slz.min = std::min( slz.min, timeSpan ); slz.min = std::min( slz.min, timeSpan );
@ -2996,7 +2998,7 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev )
{ {
for( auto& v : GetZoneChildren( zone->child ) ) for( auto& v : GetZoneChildren( zone->child ) )
{ {
const auto childSpan = std::max( int64_t( 0 ), v->end - v->start ); const auto childSpan = std::max( int64_t( 0 ), v->end - v->Start() );
timeSpan -= childSpan; timeSpan -= childSpan;
} }
} }
@ -3011,7 +3013,7 @@ void Worker::ZoneStackFailure( uint64_t thread, const ZoneEvent* ev )
{ {
m_failure = Failure::ZoneStack; m_failure = Failure::ZoneStack;
m_failureData.thread = thread; m_failureData.thread = thread;
m_failureData.srcloc = ev->srcloc; m_failureData.srcloc = ev->SrcLoc();
} }
void Worker::ZoneEndFailure( uint64_t thread ) void Worker::ZoneEndFailure( uint64_t thread )
@ -4147,7 +4149,7 @@ void Worker::ReadTimelinePre052( FileRead& f, GpuEvent* zone, int64_t& refTime,
void Worker::ReadTimelineUpdateStatistics( ZoneEvent* zone, uint16_t thread ) void Worker::ReadTimelineUpdateStatistics( ZoneEvent* zone, uint16_t thread )
{ {
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
auto it = m_data.sourceLocationZones.find( zone->srcloc ); auto it = m_data.sourceLocationZones.find( zone->SrcLoc() );
assert( it != m_data.sourceLocationZones.end() ); assert( it != m_data.sourceLocationZones.end() );
auto& slz = it->second; auto& slz = it->second;
auto& ztd = slz.zones.push_next(); auto& ztd = slz.zones.push_next();
@ -4156,7 +4158,7 @@ void Worker::ReadTimelineUpdateStatistics( ZoneEvent* zone, uint16_t thread )
if( zone->end >= 0 ) if( zone->end >= 0 )
{ {
auto timeSpan = zone->end - zone->start; auto timeSpan = zone->end - zone->Start();
if( timeSpan > 0 ) if( timeSpan > 0 )
{ {
slz.min = std::min( slz.min, timeSpan ); slz.min = std::min( slz.min, timeSpan );
@ -4167,7 +4169,7 @@ void Worker::ReadTimelineUpdateStatistics( ZoneEvent* zone, uint16_t thread )
{ {
for( auto& v : GetZoneChildren( zone->child ) ) for( auto& v : GetZoneChildren( zone->child ) )
{ {
const auto childSpan = std::max( int64_t( 0 ), v->end - v->start ); const auto childSpan = std::max( int64_t( 0 ), v->end - v->Start() );
timeSpan -= childSpan; timeSpan -= childSpan;
} }
} }
@ -4177,7 +4179,7 @@ void Worker::ReadTimelineUpdateStatistics( ZoneEvent* zone, uint16_t thread )
} }
} }
#else #else
auto it = m_data.sourceLocationZonesCnt.find( zone->srcloc ); auto it = m_data.sourceLocationZonesCnt.find( zone->SrcLoc() );
assert( it != m_data.sourceLocationZonesCnt.end() ); assert( it != m_data.sourceLocationZonesCnt.end() );
it->second++; it->second++;
#endif #endif
@ -4198,10 +4200,13 @@ void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread
do do
{ {
s_loadProgress.subProgress.fetch_add( 1, std::memory_order_relaxed ); s_loadProgress.subProgress.fetch_add( 1, std::memory_order_relaxed );
uint16_t srcloc;
f.Read( srcloc );
zone->SetSrcLoc( srcloc );
// Use zone->end as scratch buffer for zone start time offset. // Use zone->end as scratch buffer for zone start time offset.
f.Read( &zone->end, sizeof( zone->end ) + sizeof( zone->srcloc ) + sizeof( zone->text ) + sizeof( zone->callstack ) + sizeof( zone->name ) ); f.Read( &zone->end, sizeof( zone->end ) + sizeof( zone->text ) + sizeof( zone->callstack ) + sizeof( zone->name ) );
refTime += zone->end; refTime += zone->end;
zone->start = refTime; zone->SetStart( refTime );
ReadTimeline( f, zone, thread, refTime ); ReadTimeline( f, zone, thread, refTime );
zone->end = ReadTimeOffset( f, refTime ); zone->end = ReadTimeOffset( f, refTime );
#ifdef TRACY_NO_STATISTICS #ifdef TRACY_NO_STATISTICS
@ -4223,9 +4228,15 @@ void Worker::ReadTimelinePre042( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t
s_loadProgress.subProgress.fetch_add( 1, std::memory_order_relaxed ); s_loadProgress.subProgress.fetch_add( 1, std::memory_order_relaxed );
auto zone = m_slab.Alloc<ZoneEvent>(); auto zone = m_slab.Alloc<ZoneEvent>();
vec[i] = zone; vec[i] = zone;
f.Read( &zone->start, sizeof( zone->start ) + sizeof( zone->end ) + sizeof( zone->srcloc ) ); int64_t start;
zone->start -= m_data.baseTime; f.Read( start );
start -= m_data.baseTime;
zone->SetStart( start );
f.Read( zone->end );
zone->end -= m_data.baseTime; zone->end -= m_data.baseTime;
int16_t srcloc;
f.Read( srcloc );
zone->SetSrcLoc( srcloc );
f.Skip( 4 ); f.Skip( 4 );
f.Read( &zone->text, sizeof( zone->text ) + sizeof( zone->callstack ) + sizeof( zone->name ) ); f.Read( &zone->text, sizeof( zone->text ) + sizeof( zone->callstack ) + sizeof( zone->name ) );
ReadTimelinePre042( f, zone, thread, fileVer ); ReadTimelinePre042( f, zone, thread, fileVer );
@ -4253,7 +4264,9 @@ void Worker::ReadTimelinePre052( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t
s_loadProgress.subProgress.fetch_add( 1, std::memory_order_relaxed ); s_loadProgress.subProgress.fetch_add( 1, std::memory_order_relaxed );
// Use zone->end as scratch buffer for zone start time offset. // Use zone->end as scratch buffer for zone start time offset.
f.Read( &zone->end, sizeof( zone->end ) ); f.Read( &zone->end, sizeof( zone->end ) );
f.Read( &zone->srcloc, sizeof( zone->srcloc ) ); int16_t srcloc;
f.Read( srcloc );
zone->SetSrcLoc( srcloc );
if( fileVer <= FileVersion( 0, 5, 0 ) ) if( fileVer <= FileVersion( 0, 5, 0 ) )
{ {
f.Skip( 4 ); f.Skip( 4 );
@ -4264,7 +4277,7 @@ void Worker::ReadTimelinePre052( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t
} }
f.Read( &zone->text, sizeof( zone->text ) + sizeof( zone->callstack ) + sizeof( zone->name ) ); f.Read( &zone->text, sizeof( zone->text ) + sizeof( zone->callstack ) + sizeof( zone->name ) );
refTime += zone->end; refTime += zone->end;
zone->start = refTime; zone->SetStart( refTime );
ReadTimelinePre052( f, zone, thread, refTime, fileVer ); ReadTimelinePre052( f, zone, thread, refTime, fileVer );
zone->end = ReadTimeOffset( f, refTime ); zone->end = ReadTimeOffset( f, refTime );
#ifdef TRACY_NO_STATISTICS #ifdef TRACY_NO_STATISTICS
@ -4710,8 +4723,10 @@ void Worker::WriteTimeline( FileWrite& f, const Vector<ZoneEvent*>& vec, int64_t
for( auto& v : vec ) for( auto& v : vec )
{ {
WriteTimeOffset( f, refTime, v->start ); int16_t srcloc = v->SrcLoc();
f.Write( &v->srcloc, sizeof( v->srcloc ) ); f.Write( &srcloc, sizeof( srcloc ) );
int64_t start = v->Start();
WriteTimeOffset( f, refTime, start );
f.Write( &v->text, sizeof( v->text ) ); f.Write( &v->text, sizeof( v->text ) );
f.Write( &v->callstack, sizeof( v->callstack ) ); f.Write( &v->callstack, sizeof( v->callstack ) );
f.Write( &v->name, sizeof( v->name ) ); f.Write( &v->name, sizeof( v->name ) );

View File

@ -321,7 +321,7 @@ public:
// GetZoneEndDirect() will only return zone's direct timing data, without looking at children. // GetZoneEndDirect() will only return zone's direct timing data, without looking at children.
int64_t GetZoneEnd( const ZoneEvent& ev ); int64_t GetZoneEnd( const ZoneEvent& ev );
int64_t GetZoneEnd( const GpuEvent& ev ); int64_t GetZoneEnd( const GpuEvent& ev );
static tracy_force_inline int64_t GetZoneEndDirect( const ZoneEvent& ev ) { return ev.end >= 0 ? ev.end : ev.start; } static tracy_force_inline int64_t GetZoneEndDirect( const ZoneEvent& ev ) { return ev.end >= 0 ? ev.end : ev.Start(); }
static tracy_force_inline int64_t GetZoneEndDirect( const GpuEvent& ev ) { return ev.gpuEnd >= 0 ? ev.gpuEnd : ev.gpuStart; } static tracy_force_inline int64_t GetZoneEndDirect( const GpuEvent& ev ) { return ev.gpuEnd >= 0 ? ev.gpuEnd : ev.gpuStart; }
const char* GetString( uint64_t ptr ) const; const char* GetString( uint64_t ptr ) const;