1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Cache zone time distribution data.

This commit is contained in:
Bartosz Taudul 2019-10-20 03:24:58 +02:00
parent 4d761def61
commit ccdc102d5a
2 changed files with 35 additions and 28 deletions

View File

@ -5403,12 +5403,6 @@ void DrawZoneTrace( T zone, const std::vector<T>& trace, const Worker& worker, B
ImGui::TreePop(); ImGui::TreePop();
} }
struct ZoneTimeData
{
int64_t time;
uint64_t count;
};
void View::CalcZoneTimeData( flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>& data, flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>::iterator zit, const ZoneEvent& zone ) void View::CalcZoneTimeData( flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>& data, flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>::iterator zit, const ZoneEvent& zone )
{ {
assert( zone.Child() >= 0 ); assert( zone.Child() >= 0 );
@ -6278,10 +6272,13 @@ void View::DrawZoneInfoWindow()
if( ctx ) if( ctx )
{ {
ImGui::SameLine(); ImGui::SameLine();
SmallCheckbox( "Running time", &m_timeDist.runningTime ); if( SmallCheckbox( "Running time", &m_timeDist.runningTime ) ) m_timeDist.dataValidFor = nullptr;
} }
flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>> data; if( m_timeDist.dataValidFor != &ev )
float fztime; {
m_timeDist.data.clear();
if( ev.End() >= 0 ) m_timeDist.dataValidFor = &ev;
if( m_timeDist.runningTime ) if( m_timeDist.runningTime )
{ {
assert( ctx ); assert( ctx );
@ -6293,22 +6290,23 @@ void View::DrawZoneInfoWindow()
} }
else else
{ {
auto it = data.emplace( ev.SrcLoc(), ZoneTimeData{ time, 1 } ).first; auto it = m_timeDist.data.emplace( ev.SrcLoc(), ZoneTimeData{ time, 1 } ).first;
CalcZoneTimeData( ctx, data, it, ev ); CalcZoneTimeData( ctx, m_timeDist.data, it, ev );
} }
fztime = 100.f / time; m_timeDist.fztime = 100.f / time;
} }
else else
{ {
auto it = data.emplace( ev.SrcLoc(), ZoneTimeData{ ztime, 1 } ).first; auto it = m_timeDist.data.emplace( ev.SrcLoc(), ZoneTimeData{ ztime, 1 } ).first;
CalcZoneTimeData( data, it, ev ); CalcZoneTimeData( m_timeDist.data, it, ev );
fztime = 100.f / ztime; m_timeDist.fztime = 100.f / ztime;
} }
if( !data.empty() ) }
if( !m_timeDist.data.empty() )
{ {
std::vector<flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>::const_iterator> vec; std::vector<flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>>::const_iterator> vec;
vec.reserve( data.size() ); vec.reserve( m_timeDist.data.size() );
for( auto it = data.cbegin(); it != data.cend(); ++it ) vec.emplace_back( it ); for( auto it = m_timeDist.data.cbegin(); it != m_timeDist.data.cend(); ++it ) vec.emplace_back( it );
static bool widthSet = false; static bool widthSet = false;
ImGui::Columns( 3 ); ImGui::Columns( 3 );
if( !widthSet ) if( !widthSet )
@ -6349,7 +6347,7 @@ void View::DrawZoneInfoWindow()
ImGui::NextColumn(); ImGui::NextColumn();
ImGui::TextUnformatted( TimeToString( v->second.time ) ); ImGui::TextUnformatted( TimeToString( v->second.time ) );
ImGui::SameLine(); ImGui::SameLine();
ImGui::TextDisabled( "(%.2f%%)", v->second.time * fztime ); ImGui::TextDisabled( "(%.2f%%)", v->second.time * m_timeDist.fztime );
ImGui::NextColumn(); ImGui::NextColumn();
ImGui::TextUnformatted( TimeToString( v->second.time / v->second.count ) ); ImGui::TextUnformatted( TimeToString( v->second.time / v->second.count ) );
ImGui::NextColumn(); ImGui::NextColumn();

View File

@ -47,6 +47,12 @@ class View
int64_t end; int64_t end;
}; };
struct ZoneTimeData
{
int64_t time;
uint64_t count;
};
public: public:
struct VisData struct VisData
{ {
@ -575,6 +581,9 @@ private:
enum class SortBy : int { Count, Time, Mtpc }; enum class SortBy : int { Count, Time, Mtpc };
SortBy sortBy = SortBy::Time; SortBy sortBy = SortBy::Time;
bool runningTime = false; bool runningTime = false;
flat_hash_map<int16_t, ZoneTimeData, nohash<uint16_t>> data;
const ZoneEvent* dataValidFor = nullptr;
float fztime;
} m_timeDist; } m_timeDist;
}; };