blob: 1b429f32f5ce7ec92b141973d272dad5adfd8bf6 (
plain) (
blame)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* Profiler.h
* ----------
* Purpose: Performance measuring
* Notes : (currently none)
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/
#pragma once
#include "openmpt/all/BuildSettings.hpp"
#include "mpt/mutex/mutex.hpp"
#include <string>
#include <vector>
OPENMPT_NAMESPACE_BEGIN
#if defined(MODPLUG_TRACKER)
//#define USE_PROFILER
#endif
#ifdef USE_PROFILER
class Profiler
{
public:
enum Category
{
GUI,
Audio,
Notify,
CategoriesCount
};
static std::vector<std::string> GetCategoryNames()
{
std::vector<std::string> ret;
ret.push_back("GUI");
ret.push_back("Audio");
ret.push_back("Notify");
return ret;
}
public:
static void Update();
static std::string DumpProfiles();
static std::vector<double> DumpCategories();
};
class Profile
{
private:
mutable mpt::mutex datamutex;
public:
struct Data
{
uint64 Calls;
uint64 Sum;
int64 Overhead;
uint64 Start;
};
public:
Data data;
uint64 EnterTime;
Profiler::Category Category;
const char * const Name;
uint64 GetTime() const;
uint64 GetFrequency() const;
public:
Profile(Profiler::Category category, const char *name);
~Profile();
void Reset();
void Enter();
void Leave();
class Scope
{
private:
Profile &profile;
public:
Scope(Profile &p) : profile(p) { profile.Enter(); }
~Scope() { profile.Leave(); }
};
public:
Data GetAndResetData();
};
#define OPENMPT_PROFILE_SCOPE(cat, name) \
static Profile OPENMPT_PROFILE_VAR(cat, name);\
Profile::Scope OPENMPT_PROFILE_SCOPE_VAR(OPENMPT_PROFILE_VAR); \
/**/
#define OPENMPT_PROFILE_FUNCTION(cat) OPENMPT_PROFILE_SCOPE(cat, __func__)
#else // !USE_PROFILER
class Profiler
{
public:
enum Category
{
CategoriesCount
};
static std::vector<std::string> GetCategoryNames() { return std::vector<std::string>(); }
public:
static void Update() { }
static std::string DumpProfiles() { return std::string(); }
static std::vector<double> DumpCategories() { return std::vector<double>(); }
};
#define OPENMPT_PROFILE_SCOPE(cat, name) do { } while(0)
#define OPENMPT_PROFILE_FUNCTION(cat) do { } while(0)
#endif // USE_PROFILER
OPENMPT_NAMESPACE_END
|