1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <list>
#include <mutex>
#include <string>
#include "CommonTypes.h"
namespace Common
{
class Profiler
{
public:
Profiler(const std::string& name);
~Profiler();
static std::string ToString();
void Start();
void Stop();
std::string Read();
bool operator<(const Profiler& b) const;
private:
static std::list<Profiler*> s_all_profilers;
static std::mutex s_mutex;
static u32 s_max_length;
static u64 s_frame_time;
static u64 s_usecs_frame;
static std::string s_lazy_result;
static int s_lazy_delay;
std::string m_name;
u64 m_usecs;
u64 m_usecs_min;
u64 m_usecs_max;
u64 m_usecs_quad;
u64 m_calls;
u64 m_time;
int m_depth;
};
class ProfilerExecuter
{
public:
ProfilerExecuter(Profiler* _p) : m_p(_p)
{
m_p->Start();
}
~ProfilerExecuter()
{
m_p->Stop();
}
private:
Profiler* m_p;
};
};
// Warning: This profiler isn't thread safe. Only profile functions which doesn't run simultaneously
#define PROFILE(name) static Common::Profiler prof_gen(name); Common::ProfilerExecuter prof_e(&prof_gen);
|