41 if (gettimeofday(&tv, NULL) < 0)
42 Fatal(
"gettimeofday: %s", strerror(errno));
43 return (
int64_t)tv.tv_sec * 1000*1000 + tv.tv_usec;
52 int64_t LargeIntegerToInt64(
const LARGE_INTEGER& i) {
53 return ((
int64_t)i.HighPart) << 32 | i.LowPart;
57 LARGE_INTEGER counter;
58 if (!QueryPerformanceCounter(&counter))
59 Fatal(
"QueryPerformanceCounter: %s", GetLastErrorString().c_str());
60 return LargeIntegerToInt64(counter);
64 static int64_t ticks_per_sec = 0;
67 if (!QueryPerformanceFrequency(&freq))
68 Fatal(
"QueryPerformanceFrequency: %s", GetLastErrorString().c_str());
69 ticks_per_sec = LargeIntegerToInt64(freq);
73 return (dt * 1000000) / ticks_per_sec;
84 start_ = HighResTimer();
90 int64_t dt = TimerToMicros(HighResTimer() - start_);
99 metrics_.push_back(metric);
105 for (vector<Metric*>::iterator i = metrics_.begin();
106 i != metrics_.end(); ++i) {
107 width = max((
int)(*i)->name.size(), width);
110 printf(
"%-*s\t%-6s\t%-9s\t%s\n", width,
111 "metric",
"count",
"avg (us)",
"total (ms)");
112 for (vector<Metric*>::iterator i = metrics_.begin();
113 i != metrics_.end(); ++i) {
115 double total = metric->
sum / (double)1000;
116 double avg = metric->
sum / (double)metric->
count;
117 printf(
"%-*s\t%-6d\t%-8.1f\t%.1f\n", width, metric->
name.c_str(),
118 metric->
count, avg, total);
123 return TimerToMicros(HighResTimer());
127 return TimerToMicros(HighResTimer()) / 1000;
ScopedMetric(Metric *metric)
void Report()
Print a summary report to stdout.
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 std::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