15 #if defined(DIY_PROFILE)
18 using Clock = std::chrono::high_resolution_clock;
19 using Time = Clock::time_point;
23 Event(
const std::string& name_,
bool begin_):
34 using EventsVector = std::vector<Event>;
38 Scoped(Profiler& prof_, std::string name_):
39 prof(prof_), name(name_), active(true) { prof << name; }
40 ~Scoped() {
if (active) prof >> name; }
42 Scoped(Scoped&& other):
45 active(other.active) { other.active =
false; }
48 operator=(Scoped&& other) =
delete;
49 Scoped(
const Scoped&) =
delete;
51 operator=(
const Scoped&) =
delete;
58 Profiler() { reset_time(); }
60 void reset_time() { start = Clock::now(); }
62 void operator<<(std::string name) { enter(name); }
63 void operator>>(std::string name) { exit(name); }
65 void enter(std::string name) { events.push_back(Event(name,
true)); }
66 void exit(std::string name) { events.push_back(Event(name,
false)); }
68 void output(std::ostream& out)
70 for (
size_t i = 0; i < events.size(); ++i)
72 const Event& e = events[i];
73 auto time = std::chrono::duration_cast<std::chrono::microseconds>(e.stamp - start).count();
75 fmt::print(out,
"{:02d}:{:02d}:{:02d}.{:06d} {}{}\n",
80 (e.begin ?
'<' :
'>'),
85 Scoped scoped(std::string name) {
return Scoped(*
this, name); }
87 void clear() { events.clear(); }
100 void operator<<(std::string) {}
101 void operator>>(std::string) {}
103 void enter(
const std::string&) {}
104 void exit(
const std::string&) {}
106 void output(std::ostream&) {}
109 Scoped scoped(std::string) {
return Scoped(); }