37 if (gettimeofday(&tv, NULL) < 0)
38 Fatal(
"gettimeofday: %s", strerror(errno));
39 return (
int64_t)tv.tv_sec * 1000*1000 + tv.tv_usec;
48 int64_t LargeIntegerToInt64(
const LARGE_INTEGER& i) {
49 return ((
int64_t)i.HighPart) << 32 | i.LowPart;
53 LARGE_INTEGER counter;
54 if (!QueryPerformanceCounter(&counter))
55 Fatal(
"QueryPerformanceCounter: %s", GetLastErrorString().c_str());
56 return LargeIntegerToInt64(counter);
60 static int64_t ticks_per_sec = 0;
63 if (!QueryPerformanceFrequency(&freq))
64 Fatal(
"QueryPerformanceFrequency: %s", GetLastErrorString().c_str());
65 ticks_per_sec = LargeIntegerToInt64(freq);
69 return (dt * 1000000) / ticks_per_sec;
101 for (vector<Metric*>::iterator i =
metrics_.begin();
103 width = max((
int)(*i)->name.size(), width);
106 printf(
"%-*s\t%-6s\t%-9s\t%s\n", width,
107 "metric",
"count",
"avg (us)",
"total (ms)");
108 for (vector<Metric*>::iterator i =
metrics_.begin();
111 double total = metric->
sum / (double)1000;
112 double avg = metric->
sum / (double)metric->
count;
113 printf(
"%-*s\t%-6d\t%-8.1f\t%.1f\n", width, metric->
name.c_str(),
114 metric->
count, avg, total);
119 return TimerToMicros(HighResTimer());
123 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.
vector< Metric * > metrics_
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