mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-26 16:04:34 +00:00
Each thread has its own timeline.
This commit is contained in:
parent
a557a3fb30
commit
55fdc47418
@ -233,7 +233,7 @@ void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev )
|
|||||||
if( it == m_pendingEndZone.end() )
|
if( it == m_pendingEndZone.end() )
|
||||||
{
|
{
|
||||||
zone->end = -1;
|
zone->end = -1;
|
||||||
NewZone( zone );
|
NewZone( zone, ev.thread );
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
m_openZones.emplace( id, zone );
|
m_openZones.emplace( id, zone );
|
||||||
}
|
}
|
||||||
@ -241,7 +241,7 @@ void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev )
|
|||||||
{
|
{
|
||||||
assert( ev.time <= it->second.time );
|
assert( ev.time <= it->second.time );
|
||||||
zone->end = it->second.time;
|
zone->end = it->second.time;
|
||||||
NewZone( zone );
|
NewZone( zone, ev.thread );
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
m_pendingEndZone.erase( it );
|
m_pendingEndZone.erase( it );
|
||||||
}
|
}
|
||||||
@ -302,14 +302,27 @@ void View::AddString( uint64_t ptr, std::string&& str )
|
|||||||
m_strings.emplace( ptr, std::move( str ) );
|
m_strings.emplace( ptr, std::move( str ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::NewZone( Event* zone )
|
void View::NewZone( Event* zone, uint64_t thread )
|
||||||
{
|
{
|
||||||
if( !m_timeline.empty() )
|
Vector<Event*>* timeline;
|
||||||
|
auto it = m_threadMap.find( thread );
|
||||||
|
if( it == m_threadMap.end() )
|
||||||
{
|
{
|
||||||
const auto lastend = m_timeline.back()->end;
|
m_threadMap.emplace( thread, m_threads.size() );
|
||||||
|
m_threads.emplace_back();
|
||||||
|
timeline = &m_threads.back().timeline;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
timeline = &m_threads[it->second].timeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !timeline->empty() )
|
||||||
|
{
|
||||||
|
const auto lastend = timeline->back()->end;
|
||||||
if( lastend != -1 && lastend < zone->start )
|
if( lastend != -1 && lastend < zone->start )
|
||||||
{
|
{
|
||||||
m_timeline.push_back( zone );
|
timeline->push_back( zone );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -318,7 +331,7 @@ void View::NewZone( Event* zone )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_timeline.push_back( zone );
|
timeline->push_back( zone );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,11 +375,14 @@ uint64_t View::GetLastTime() const
|
|||||||
{
|
{
|
||||||
uint64_t last = 0;
|
uint64_t last = 0;
|
||||||
if( !m_frames.empty() ) last = m_frames.back();
|
if( !m_frames.empty() ) last = m_frames.back();
|
||||||
if( !m_timeline.empty() )
|
for( auto& v : m_threads )
|
||||||
{
|
{
|
||||||
auto ev = m_timeline.back();
|
if( !v.timeline.empty() )
|
||||||
|
{
|
||||||
|
auto ev = v.timeline.back();
|
||||||
if( ev->end > (int64_t)last ) last = ev->end;
|
if( ev->end > (int64_t)last ) last = ev->end;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -783,11 +799,13 @@ void View::DrawZones()
|
|||||||
while( false );
|
while( false );
|
||||||
|
|
||||||
// zones
|
// zones
|
||||||
do
|
int offset = 20;
|
||||||
|
for( auto& v : m_threads )
|
||||||
{
|
{
|
||||||
auto it = std::lower_bound( m_timeline.begin(), m_timeline.end(), m_zvStart, [] ( const auto& l, const auto& r ) { return l->end < r; } );
|
auto& timeline = v.timeline;
|
||||||
if( it == m_timeline.end() ) break;
|
auto it = std::lower_bound( timeline.begin(), timeline.end(), m_zvStart, [] ( const auto& l, const auto& r ) { return l->end < r; } );
|
||||||
const auto zitend = std::lower_bound( m_timeline.begin(), m_timeline.end(), m_zvEnd, [] ( const auto& l, const auto& r ) { return l->start < r; } );
|
if( it == timeline.end() ) continue;
|
||||||
|
const auto zitend = std::lower_bound( timeline.begin(), timeline.end(), m_zvEnd, [] ( const auto& l, const auto& r ) { return l->start < r; } );
|
||||||
|
|
||||||
while( it < zitend )
|
while( it < zitend )
|
||||||
{
|
{
|
||||||
@ -796,20 +814,20 @@ void View::DrawZones()
|
|||||||
const char* func = GetString( srcFile.function );
|
const char* func = GetString( srcFile.function );
|
||||||
const auto zsz = ( ev.end - ev.start ) * pxns;
|
const auto zsz = ( ev.end - ev.start ) * pxns;
|
||||||
const auto tsz = ImGui::CalcTextSize( func );
|
const auto tsz = ImGui::CalcTextSize( func );
|
||||||
draw->AddRectFilled( wpos + ImVec2( ( ev.start - m_zvStart ) * pxns, 20 ), wpos + ImVec2( ( ev.end - m_zvStart ) * pxns, 20 + tsz.y ), 0xDDDD6666, 2.f );
|
draw->AddRectFilled( wpos + ImVec2( ( ev.start - m_zvStart ) * pxns, offset ), wpos + ImVec2( ( ev.end - m_zvStart ) * pxns, offset + tsz.y ), 0xDDDD6666, 2.f );
|
||||||
draw->AddRect( wpos + ImVec2( ( ev.start - m_zvStart ) * pxns, 20 ), wpos + ImVec2( ( ev.end - m_zvStart ) * pxns, 20 + tsz.y ), 0xAAAAAAAA, 2.f );
|
draw->AddRect( wpos + ImVec2( ( ev.start - m_zvStart ) * pxns, offset ), wpos + ImVec2( ( ev.end - m_zvStart ) * pxns, offset + tsz.y ), 0xAAAAAAAA, 2.f );
|
||||||
if( tsz.x < zsz )
|
if( tsz.x < zsz )
|
||||||
{
|
{
|
||||||
draw->AddText( wpos + ImVec2( ( ev.start - m_zvStart ) * pxns + ( ( ev.end - ev.start ) * pxns - tsz.x ) / 2, 20 ), 0xFFFFFFFF, func );
|
draw->AddText( wpos + ImVec2( ( ev.start - m_zvStart ) * pxns + ( ( ev.end - ev.start ) * pxns - tsz.x ) / 2, offset ), 0xFFFFFFFF, func );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImGui::PushClipRect( wpos + ImVec2( ( ev.start - m_zvStart ) * pxns, 20 ), wpos + ImVec2( ( ev.end - m_zvStart ) * pxns, 20 + tsz.y ), true );
|
ImGui::PushClipRect( wpos + ImVec2( ( ev.start - m_zvStart ) * pxns, offset ), wpos + ImVec2( ( ev.end - m_zvStart ) * pxns, offset + tsz.y ), true );
|
||||||
draw->AddText( wpos + ImVec2( ( ev.start - m_zvStart ) * pxns, 20 ), 0xFFFFFFFF, func );
|
draw->AddText( wpos + ImVec2( ( ev.start - m_zvStart ) * pxns, offset ), 0xFFFFFFFF, func );
|
||||||
ImGui::PopClipRect();
|
ImGui::PopClipRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( ( ev.start - m_zvStart ) * pxns, 20 ), wpos + ImVec2( ( ev.end - m_zvStart ) * pxns, 20 + tsz.y ) ) )
|
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( ( ev.start - m_zvStart ) * pxns, offset ), wpos + ImVec2( ( ev.end - m_zvStart ) * pxns, offset + tsz.y ) ) )
|
||||||
{
|
{
|
||||||
ImGui::BeginTooltip();
|
ImGui::BeginTooltip();
|
||||||
ImGui::Text( func );
|
ImGui::Text( func );
|
||||||
@ -820,8 +838,9 @@ void View::DrawZones()
|
|||||||
|
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
offset += 20;
|
||||||
}
|
}
|
||||||
while( false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,11 @@ public:
|
|||||||
static void Draw();
|
static void Draw();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct ThreadData
|
||||||
|
{
|
||||||
|
Vector<Event*> timeline;
|
||||||
|
};
|
||||||
|
|
||||||
void Worker();
|
void Worker();
|
||||||
|
|
||||||
void DispatchProcess( const QueueItem& ev );
|
void DispatchProcess( const QueueItem& ev );
|
||||||
@ -46,7 +51,7 @@ private:
|
|||||||
void CheckString( uint64_t ptr );
|
void CheckString( uint64_t ptr );
|
||||||
void AddString( uint64_t ptr, std::string&& str );
|
void AddString( uint64_t ptr, std::string&& str );
|
||||||
|
|
||||||
void NewZone( Event* zone );
|
void NewZone( Event* zone, uint64_t thread );
|
||||||
void UpdateZone( Event* zone );
|
void UpdateZone( Event* zone );
|
||||||
|
|
||||||
uint64_t GetFrameTime( size_t idx ) const;
|
uint64_t GetFrameTime( size_t idx ) const;
|
||||||
@ -70,9 +75,9 @@ private:
|
|||||||
|
|
||||||
// this block must be locked
|
// this block must be locked
|
||||||
std::mutex m_lock;
|
std::mutex m_lock;
|
||||||
Vector<Event*> m_timeline;
|
|
||||||
Vector<uint64_t> m_frames;
|
Vector<uint64_t> m_frames;
|
||||||
Vector<SourceLocation> m_srcFile;
|
Vector<SourceLocation> m_srcFile;
|
||||||
|
Vector<ThreadData> m_threads;
|
||||||
std::unordered_map<uint64_t, std::string> m_strings;
|
std::unordered_map<uint64_t, std::string> m_strings;
|
||||||
|
|
||||||
std::mutex m_mbpslock;
|
std::mutex m_mbpslock;
|
||||||
@ -83,6 +88,7 @@ private:
|
|||||||
std::unordered_map<uint64_t, Event*> m_openZones;
|
std::unordered_map<uint64_t, Event*> m_openZones;
|
||||||
std::unordered_set<uint64_t> m_pendingStrings;
|
std::unordered_set<uint64_t> m_pendingStrings;
|
||||||
std::unordered_map<SourceLocation, uint32_t, SourceLocation::Hasher, SourceLocation::Comparator> m_locationRef;
|
std::unordered_map<SourceLocation, uint32_t, SourceLocation::Hasher, SourceLocation::Comparator> m_locationRef;
|
||||||
|
std::unordered_map<uint64_t, uint32_t> m_threadMap;
|
||||||
|
|
||||||
Slab<EventSize*1024*1024> m_slab;
|
Slab<EventSize*1024*1024> m_slab;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user