12 #include <unordered_map> 17 using Clock = std::chrono::high_resolution_clock;
18 using Time = Clock::time_point;
19 using Duration = Clock::duration;
33 static void summary(std::ostream& out);
40 static std::shared_ptr<Manager>
singleton();
46 Manager() : _created(Clock::now()) {}
48 void register_(
Ledger* ledger);
49 void unregister(
Ledger* ledger);
50 Ledger* newLedger(
const std::string& name);
54 std::unordered_map<std::string, Ledger*> _all_ledgers;
55 std::list<Ledger> _our_ledgers;
66 _manager->register_(
this);
68 ~
Ledger() { _manager->unregister(
this); }
76 const std::string& name()
const {
return _name; }
78 void summary(std::ostream& out)
const;
91 assert(_time_started == Time());
92 _time_started = Clock::now();
104 assert(_time_started != Time());
105 _time_used += (Clock::now() - _time_started);
106 _time_started = Time();
112 _time_used += (Clock::now() - _time_started);
113 _time_started = Time();
120 Duration _time_used = Duration(0);
121 uint64_t _num_completed = 0;
126 std::shared_ptr<detail::Manager> _manager;
142 void finish() { _ledger->finish(); }
static void summary(std::ostream &out)
Definition: timing.cc:68
static std::shared_ptr< Manager > singleton()
Definition: timing.cc:41