mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-25 15:34:36 +00:00
Read and report power usage.
This commit is contained in:
parent
c3e7157cd5
commit
2971db21e3
@ -4,11 +4,13 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <chrono>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "TracyDebug.hpp"
|
||||
#include "TracyProfiler.hpp"
|
||||
#include "../common/TracyAlloc.hpp"
|
||||
|
||||
namespace tracy
|
||||
@ -16,6 +18,7 @@ namespace tracy
|
||||
|
||||
SysPower::SysPower()
|
||||
: m_domains( 4 )
|
||||
, m_lastTime( 0 )
|
||||
{
|
||||
ScanDirectory( "/sys/devices/virtual/powercap/intel-rapl", -1 );
|
||||
}
|
||||
@ -31,6 +34,36 @@ SysPower::~SysPower()
|
||||
|
||||
void SysPower::Tick()
|
||||
{
|
||||
auto t = std::chrono::high_resolution_clock::now().time_since_epoch().count();
|
||||
if( t - m_lastTime > 10000000 ) // 10 ms
|
||||
{
|
||||
m_lastTime = t;
|
||||
for( auto& v : m_domains )
|
||||
{
|
||||
char tmp[32];
|
||||
if( fread( tmp, 1, 32, v.handle ) > 0 )
|
||||
{
|
||||
rewind( v.handle );
|
||||
auto p = (uint64_t)atoll( tmp );
|
||||
uint64_t delta;
|
||||
if( p >= v.value )
|
||||
{
|
||||
delta = p - v.value;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = v.overflow - v.value + p;
|
||||
}
|
||||
v.value = p;
|
||||
|
||||
TracyLfqPrepare( QueueType::SysPowerReport );
|
||||
MemWrite( &item->sysPower.time, Profiler::GetTime() );
|
||||
MemWrite( &item->sysPower.delta, delta );
|
||||
MemWrite( &item->sysPower.name, (uint64_t)v.name );
|
||||
TracyLfqCommit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SysPower::ScanDirectory( const char* path, int parent )
|
||||
|
@ -35,6 +35,7 @@ private:
|
||||
void ScanDirectory( const char* path, int parent );
|
||||
|
||||
FastVector<Domain> m_domains;
|
||||
uint64_t m_lastTime;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace tracy
|
||||
|
||||
constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
|
||||
|
||||
enum : uint32_t { ProtocolVersion = 63 };
|
||||
enum : uint32_t { ProtocolVersion = 64 };
|
||||
enum : uint16_t { BroadcastVersion = 3 };
|
||||
|
||||
using lz4sz_t = uint32_t;
|
||||
|
@ -90,6 +90,7 @@ enum class QueueType : uint8_t
|
||||
GpuNewContext,
|
||||
CallstackFrame,
|
||||
SysTimeReport,
|
||||
SysPowerReport,
|
||||
TidToPid,
|
||||
HwSampleCpuCycle,
|
||||
HwSampleInstructionRetired,
|
||||
@ -563,6 +564,13 @@ struct QueueSysTime
|
||||
float sysTime;
|
||||
};
|
||||
|
||||
struct QueueSysPower
|
||||
{
|
||||
int64_t time;
|
||||
uint64_t delta;
|
||||
uint64_t name; // ptr
|
||||
};
|
||||
|
||||
struct QueueContextSwitch
|
||||
{
|
||||
int64_t time;
|
||||
@ -729,6 +737,7 @@ struct QueueItem
|
||||
QueueCrashReport crashReport;
|
||||
QueueCrashReportThread crashReportThread;
|
||||
QueueSysTime sysTime;
|
||||
QueueSysPower sysPower;
|
||||
QueueContextSwitch contextSwitch;
|
||||
QueueThreadWakeup threadWakeup;
|
||||
QueueTidToPid tidToPid;
|
||||
@ -832,6 +841,7 @@ static constexpr size_t QueueDataSize[] = {
|
||||
sizeof( QueueHeader ) + sizeof( QueueGpuNewContext ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueCallstackFrame ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueSysTime ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueSysPower ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueTidToPid ),
|
||||
sizeof( QueueHeader ) + sizeof( QueueHwSample ), // cpu cycle
|
||||
sizeof( QueueHeader ) + sizeof( QueueHwSample ), // instruction retired
|
||||
|
Loading…
Reference in New Issue
Block a user