mirror of
https://github.com/libretro/Play-.git
synced 2024-11-28 03:00:49 +00:00
60 lines
999 B
C++
60 lines
999 B
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <stack>
|
|
#include <thread>
|
|
#include <vector>
|
|
#include <chrono>
|
|
#include "Singleton.h"
|
|
#include "Types.h"
|
|
|
|
class CProfiler : public CSingleton<CProfiler>
|
|
{
|
|
public:
|
|
typedef uint32 ZoneHandle;
|
|
|
|
struct ZONE
|
|
{
|
|
std::string name;
|
|
uint64 totalTime = 0;
|
|
};
|
|
|
|
typedef std::vector<ZONE> ZoneArray;
|
|
typedef std::chrono::high_resolution_clock::time_point TimePoint;
|
|
|
|
CProfiler();
|
|
virtual ~CProfiler();
|
|
|
|
ZoneHandle RegisterZone(const char*);
|
|
|
|
void CountCurrentZone();
|
|
|
|
void EnterZone(ZoneHandle);
|
|
void ExitZone();
|
|
|
|
ZoneArray GetStats() const;
|
|
void Reset();
|
|
|
|
void SetWorkThread();
|
|
|
|
private:
|
|
typedef std::stack<ZoneHandle> ZoneStack;
|
|
|
|
void AddTimeToZone(ZoneHandle, uint64);
|
|
|
|
ZoneArray m_zones;
|
|
ZoneStack m_zoneStack;
|
|
TimePoint m_currentTime;
|
|
|
|
#ifdef _DEBUG
|
|
std::thread::id m_workThreadId;
|
|
#endif
|
|
};
|
|
|
|
class CProfilerZone
|
|
{
|
|
public:
|
|
CProfilerZone(CProfiler::ZoneHandle);
|
|
~CProfilerZone();
|
|
};
|