74 lines
1.4 KiB
C++
74 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#include <vector>
|
|
#include <algorithm>
|
|
#include <sstream>
|
|
|
|
class PerformancerData
|
|
{
|
|
public:
|
|
PerformancerData(const std::string& name, const std::string& fullName);
|
|
void Add(long long duration);
|
|
|
|
std::string Name;
|
|
std::string FullName;
|
|
long long Calls;
|
|
long long Elapsed;
|
|
long long Max;
|
|
long long Min;
|
|
};
|
|
|
|
|
|
#include <chrono>
|
|
|
|
struct HighResClock
|
|
{
|
|
typedef long long rep;
|
|
typedef std::nano period;
|
|
typedef std::chrono::duration<rep, period> duration;
|
|
typedef std::chrono::time_point<HighResClock> time_point;
|
|
static const bool is_steady = true;
|
|
|
|
static time_point now();
|
|
};
|
|
|
|
|
|
class Performancer
|
|
{
|
|
public:
|
|
int RegisterMethod(const std::string& name, const std::string& fullName);
|
|
void AddData(int index, long long duration);
|
|
void Dump();
|
|
|
|
static Performancer Instance;
|
|
|
|
private:
|
|
std::vector<PerformancerData> data;
|
|
};
|
|
|
|
|
|
class PerformancerEntry
|
|
{
|
|
public:
|
|
PerformancerEntry(int index);
|
|
~PerformancerEntry();
|
|
|
|
private:
|
|
std::chrono::time_point<HighResClock> start;
|
|
int index;
|
|
};
|
|
|
|
#define PERFORMANCER \
|
|
static int __performancerIndex = Performancer::Instance.RegisterMethod( __FUNCTION__, __FUNCSIG__); \
|
|
PerformancerEntry __performancerEntry(__performancerIndex);
|
|
|
|
#define PERFORMANCER_DUMP Performancer::Instance.Dump();
|
|
|
|
#else
|
|
|
|
#define PERFORMANCER
|
|
#define PERFORMANCER_DUMP
|
|
|
|
#endif |