Process power usage messages.

This commit is contained in:
Bartosz Taudul 2023-03-10 01:02:41 +01:00
parent 2971db21e3
commit 69855c671f
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 41 additions and 0 deletions

View File

@ -4744,6 +4744,9 @@ bool Worker::Process( const QueueItem& ev )
case QueueType::SysTimeReport:
ProcessSysTime( ev.sysTime );
break;
case QueueType::SysPowerReport:
ProcessSysPower( ev.sysPower );
break;
case QueueType::ContextSwitch:
ProcessContextSwitch( ev.contextSwitch );
break;
@ -6686,6 +6689,35 @@ void Worker::ProcessSysTime( const QueueSysTime& ev )
}
}
void Worker::ProcessSysPower( const QueueSysPower& ev )
{
const auto time = TscTime( ev.time );
auto it = m_powerData.find( ev.name );
if( it == m_powerData.end() )
{
CheckString( ev.name );
PlotData* plot = m_slab.AllocInit<PlotData>();
plot->name = ev.name;
plot->type = PlotType::User;
plot->format = PlotValueFormatting::Number;
plot->showSteps = false;
plot->fill = true;
plot->color = 0;
m_data.plots.Data().push_back( plot );
m_powerData.emplace( ev.name, PowerData { time, plot } );
}
else
{
const auto dt = time - it->second.lastTime;
it->second.lastTime = time;
if( m_data.lastTime < time ) m_data.lastTime = time;
// ev.delta is Microjoule, dt is nanoseconds
// power is Watt = J / s
const auto power = ev.delta * 1000. / dt;
InsertPlot( it->second.plot, time, power );
}
}
void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
{
#ifndef TRACY_NO_STATISTICS

View File

@ -158,6 +158,12 @@ public:
uint8_t inlineFrame;
};
struct PowerData
{
int64_t lastTime;
PlotData* plot;
};
#pragma pack( push, 1 )
struct GhostKey
{
@ -735,6 +741,7 @@ private:
tracy_force_inline void ProcessSymbolInformation( const QueueSymbolInformation& ev );
tracy_force_inline void ProcessCrashReport( const QueueCrashReport& ev );
tracy_force_inline void ProcessSysTime( const QueueSysTime& ev );
tracy_force_inline void ProcessSysPower( const QueueSysPower& ev );
tracy_force_inline void ProcessContextSwitch( const QueueContextSwitch& ev );
tracy_force_inline void ProcessThreadWakeup( const QueueThreadWakeup& ev );
tracy_force_inline void ProcessTidToPid( const QueueTidToPid& ev );
@ -1066,6 +1073,8 @@ private:
unordered_flat_map<uint64_t, uint32_t> m_nextCallstack;
unordered_flat_map<uint32_t, const char*> m_sourceCodeQuery;
uint32_t m_nextSourceCodeQuery = 0;
unordered_flat_map<uint64_t, PowerData> m_powerData;
};
}