Play-/Source/Profiler.h

60 lines
999 B
C
Raw Permalink Normal View History

#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
{
2018-04-30 21:01:23 +01:00
std::string name;
uint64 totalTime = 0;
};
typedef std::vector<ZONE> ZoneArray;
typedef std::chrono::high_resolution_clock::time_point TimePoint;
2018-04-30 21:01:23 +01:00
CProfiler();
virtual ~CProfiler();
2018-04-30 21:01:23 +01:00
ZoneHandle RegisterZone(const char*);
2018-04-30 21:01:23 +01:00
void CountCurrentZone();
2018-04-30 21:01:23 +01:00
void EnterZone(ZoneHandle);
void ExitZone();
2018-04-30 21:01:23 +01:00
ZoneArray GetStats() const;
void Reset();
void SetWorkThread();
private:
typedef std::stack<ZoneHandle> ZoneStack;
2018-04-30 21:01:23 +01:00
void AddTimeToZone(ZoneHandle, uint64);
ZoneArray m_zones;
ZoneStack m_zoneStack;
TimePoint m_currentTime;
#ifdef _DEBUG
2018-04-30 21:01:23 +01:00
std::thread::id m_workThreadId;
#endif
};
class CProfilerZone
{
public:
2018-04-30 21:01:23 +01:00
CProfilerZone(CProfiler::ZoneHandle);
~CProfilerZone();
};