Files
SourMesen a33b8b2712 Debugger: GSU - Added profiler support (#261)
This is implemented by pretending every 16 bytes in ROM is a different function, allowing the profiler to display cycle counts for each individual "function" in the UI
Also fixes a missing call to ResetFlags for the merge opcode for FX3
2026-08-27 19:00:55 +09:00

58 lines
1.2 KiB
C++

#pragma once
#include "pch.h"
#include "Debugger/DebugTypes.h"
class Debugger;
class IDebugger;
struct ProfiledFunction
{
uint64_t ExclusiveCycles = 0;
uint64_t InclusiveCycles = 0;
uint64_t CallCount = 0;
uint64_t MinCycles = UINT64_MAX;
uint64_t MaxCycles = 0;
AddressInfo Address = {};
StackFrameFlags Flags = {};
};
class Profiler
{
private:
Debugger* _debugger = nullptr;
IDebugger* _cpuDebugger = nullptr;
unordered_map<int32_t, ProfiledFunction> _functions;
deque<int32_t> _functionStack;
deque<StackFrameFlags> _stackFlags;
deque<uint64_t> _cycleCountStack;
uint64_t _currentCycleCount = 0;
uint64_t _prevMasterClock = 0;
int32_t _currentFunction = -1;
uint64_t _prevUsageCycleCount = 0;
uint64_t _prevUsageHaltedCycles = 0;
uint32_t _prevCpuUsage = 0;
void InternalReset();
void UpdateCycles();
public:
Profiler(Debugger* debugger, IDebugger* cpuDebugger);
~Profiler();
void StackFunction(AddressInfo& addr, StackFrameFlags stackFlag);
void UnstackFunction();
void RecordSample(AddressInfo addr);
void UpdateCpuUsage();
void Reset();
void ResetState();
void GetProfilerData(ProfiledFunction* profilerData, uint32_t& functionCount);
uint32_t GetCpuUsage() { return _prevCpuUsage; }
};