Debian Codegraph @

Source/Core/Common/Profiler.h

raw symbols SCIP
1 // Copyright 2014 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <list>
7 #include <mutex>
8 #include <string>
9
10 #include "CommonTypes.h"
11
12 namespace Common
13 {
14 class Profiler
15 {
16 public:
17 Profiler(std::string name);
18 ~Profiler();
19
20 static std::string ToString();
21
22 void Start(u64* time, int* depth);
23 void Stop(u64* time, int* depth);
24 std::string Read();
25
26 bool operator<(const Profiler& b) const;
27
28 private:
29 static std::list<Profiler*> s_all_profilers;
30 static std::mutex s_mutex;
31 static u32 s_max_length;
32 static u64 s_frame_time;
33 static u64 s_usecs_frame;
34
35 static std::string s_lazy_result;
36 static int s_lazy_delay;
37
38 std::mutex m_mutex;
39 std::string m_name;
40 u64 m_usecs;
41 u64 m_usecs_min;
42 u64 m_usecs_max;
43 u64 m_usecs_quad;
44 u64 m_calls;
45 };
46
47 class ProfilerExecuter
48 {
49 public:
50 ProfilerExecuter(Profiler* profiler, u64* time, int* depth)
51 : m_profiler(profiler), m_time(time), m_depth(depth)
52 {
53 m_profiler->Start(m_time, m_depth);
54 }
55 ~ProfilerExecuter() { m_profiler->Stop(m_time, m_depth); }
56
57 private:
58 Profiler* m_profiler;
59 u64* m_time;
60 int* m_depth;
61 };
62 } // namespace Common
63
64 #define PROFILE(name) \
65 static Common::Profiler prof_gen(name); \
66 static thread_local u64 prof_time; \
67 static thread_local int prof_depth; \
68 Common::ProfilerExecuter prof_e(&prof_gen, &prof_time, &prof_depth);