1#ifndef PROFILE_TIMER_HPP
2#define PROFILE_TIMER_HPP
6#define C_PROFILER_PUSH(name) \
7 push_prof_timer((name))
9#define C_PROFILER_POP \
21#define THREAD_EVENT_BUF_SIZE 256
24 Profile_timer PROFILER_PROFILE_TIMER_FUNC(Profiler_thread_inst::get_instance(), __PRETTY_FUNCTION__); \
25 Profile_timer PROFILER_PROFILE_TIMER_DETAIL(Profiler_thread_inst::get_instance(), "");
27#define PROFILE_DETAIL(name) \
28 PROFILER_PROFILE_TIMER_DETAIL = Profile_timer(Profiler_thread_inst::get_instance(), (name));
32 Profile_event(std::string
name,
33 std::thread::id thread_id) :
37 thread_id(thread_id) { }
39 Profile_event() =
default;
42 std::chrono::steady_clock::time_point::rep
start;
43 std::chrono::steady_clock::time_point::rep end;
45 std::thread::id thread_id;
48class Profiler_thread_inst;
51 friend Profiler_thread_inst;
53 static Profiler& get_instance();
55 Profiler(
const Profiler&) =
delete;
56 Profiler(Profiler&&) =
delete;
57 Profiler& operator=(Profiler&&) =
delete;
58 Profiler& operator=(
const Profiler&) =
delete;
60 void write_events(
const std::vector<Profile_event>& events);
62 static std::chrono::steady_clock::time_point get_start_point(){
70 std::ofstream out_file;
75 static std::chrono::steady_clock::time_point start_point;
80class Profiler_thread_inst {
84 Profiler_thread_inst(Profiler& profiler);
85 ~Profiler_thread_inst();
87 Profiler_thread_inst(
const Profiler_thread_inst&) =
delete;
88 Profiler_thread_inst(Profiler_thread_inst&&) =
delete;
89 Profiler_thread_inst& operator=(Profiler_thread_inst&&) =
delete;
90 Profiler_thread_inst& operator=(
const Profiler_thread_inst&) =
delete;
92 static Profiler_thread_inst& get_instance();
94 void add_event(Profile_event&& event);
96 void push_timer(
const char *
name);
101 std::vector<Profile_event> thread_events;
102 std::chrono::steady_clock::time_point::rep last_ts;
103 std::vector<Profile_timer> c_timers;
109 Profile_timer(Profiler_thread_inst& profiler, std::string
name);
110 Profile_timer(Profile_timer&&);
111 Profile_timer(
const Profile_timer&) =
delete;
114 Profile_timer& operator=(Profile_timer&& rhs);
115 Profile_timer& operator=(
const Profile_timer&) =
delete;
120 std::reference_wrapper<Profiler_thread_inst> profiler;
130 void push_prof_timer(
const char *
name);
131 void pop_prof_timer();
140#define PROFILE_DETAIL(name)
141#define C_PROFILER_PUSH(name)
142#define C_PROFILER_POP