34 auto now = chrono::steady_clock::now();
35 return chrono::duration_cast<chrono::steady_clock::duration>(
36 now.time_since_epoch())
42 return chrono::duration_cast<chrono::microseconds>(
43 std::chrono::steady_clock::duration{ dt })
47 int64_t TimerToMicros(
double dt) {
49 using DoubleSteadyClock =
50 std::chrono::duration<double, std::chrono::steady_clock::period>;
51 return chrono::duration_cast<chrono::microseconds>(DoubleSteadyClock{ dt })
61 start_ = HighResTimer();
69 int64_t dt = HighResTimer() - start_;
78 metrics_.push_back(metric);
84 for (vector<Metric*>::iterator i = metrics_.begin();
85 i != metrics_.end(); ++i) {
86 width = max((
int)(*i)->name.size(), width);
89 printf(
"%-*s\t%-6s\t%-9s\t%s\n", width,
90 "metric",
"count",
"avg (us)",
"total (ms)");
91 for (vector<Metric*>::iterator i = metrics_.begin();
92 i != metrics_.end(); ++i) {
95 double total = micros / (double)1000;
96 double avg = micros / (double)metric->
count;
97 printf(
"%-*s\t%-6d\t%-8.1f\t%.1f\n", width, metric->
name.c_str(),
98 metric->
count, avg, total);
104 return 1e-6 * TimerToMicros(
static_cast<double>(NowRaw() - started_));
108 return HighResTimer();
112 return TimerToMicros(HighResTimer()) / 1000;
int64_t GetTimeMillis()
Get the current time as relative to some epoch.
The Metrics module is used for the debug mode that dumps timing stats of various actions.
int count
Number of times we've hit the code path.
int64_t sum
Total time (in platform-dependent units) we've spent on the code path.
The singleton that stores metrics and prints the report.
void Report()
Print a summary report to stdout.
Metric * NewMetric(const std::string &name)
ScopedMetric(Metric *metric)
double Elapsed() const
Seconds since Restart() call.
unsigned long long uint64_t
signed long long int64_t
A 64-bit integer type.