39 if (gettimeofday(&tv, NULL) < 0)
40 Fatal(
"gettimeofday: %s", strerror(errno));
41 return (
int64_t)tv.tv_sec * 1000*1000 + tv.tv_usec;
50 int64_t LargeIntegerToInt64(
const LARGE_INTEGER& i) {
51 return ((
int64_t)i.HighPart) << 32 | i.LowPart;
55 LARGE_INTEGER counter;
56 if (!QueryPerformanceCounter(&counter))
57 Fatal(
"QueryPerformanceCounter: %s", GetLastErrorString().c_str());
58 return LargeIntegerToInt64(counter);
62 static int64_t ticks_per_sec = 0;
65 if (!QueryPerformanceFrequency(&freq))
66 Fatal(
"QueryPerformanceFrequency: %s", GetLastErrorString().c_str());
67 ticks_per_sec = LargeIntegerToInt64(freq);
71 return (dt * 1000000) / ticks_per_sec;
97 metrics_.push_back(metric);
103 for (vector<Metric*>::iterator i = metrics_.begin();
104 i != metrics_.end(); ++i) {
105 width = max((
int)(*i)->name.size(), width);
108 printf(
"%-*s\t%-6s\t%-9s\t%s\n", width,
109 "metric",
"count",
"avg (us)",
"total (ms)");
110 for (vector<Metric*>::iterator i = metrics_.begin();
111 i != metrics_.end(); ++i) {
113 double total = metric->
sum / (double)1000;
114 double avg = metric->
sum / (double)metric->
count;
115 printf(
"%-*s\t%-6d\t%-8.1f\t%.1f\n", width, metric->
name.c_str(),
116 metric->
count, avg, total);
121 return TimerToMicros(HighResTimer());
125 return TimerToMicros(HighResTimer()) / 1000;
ScopedMetric(Metric *metric)
void Report()
Print a summary report to stdout.
int64_t start_
Timestamp when the measurement started.
int64_t sum
Total time (in micros) we've spent on the code path.
int count
Number of times we've hit the code path.
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.
signed long long int64_t
A 64-bit integer type.
Metric * NewMetric(const string &name)
void Fatal(const char *msg,...)
Log a fatal message and exit.
The singleton that stores metrics and prints the report.
unsigned long long uint64_t