e1174306c5
Summary: Make stop watch a simple implementation, instead of subclass of a virtual class Allocate stop watches off the stack instead of heap. Code is more terse now. Test Plan: make all check, db_bench with --statistics=1 Reviewers: haobo, dhruba Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D10809
42 lines
918 B
C++
42 lines
918 B
C++
#ifndef STORAGE_LEVELDB_UTIL_STOP_WATCH_H_
|
|
#define STORAGE_LEVELDB_UTIL_STOP_WATCH_H_
|
|
|
|
#include "leveldb/env.h"
|
|
#include "leveldb/statistics.h"
|
|
|
|
namespace leveldb {
|
|
// Auto-scoped.
|
|
// Records the statistic into the corresponding histogram.
|
|
class StopWatch {
|
|
public:
|
|
StopWatch(
|
|
Env * const env,
|
|
std::shared_ptr<Statistics> statistics,
|
|
const Histograms histogram_name) :
|
|
env_(env),
|
|
start_time_(env->NowMicros()),
|
|
statistics_(statistics),
|
|
histogram_name_(histogram_name) {}
|
|
|
|
|
|
|
|
uint64_t ElapsedMicros() {
|
|
return env_->NowMicros() - start_time_;
|
|
}
|
|
|
|
~StopWatch() {
|
|
if (statistics_) {
|
|
statistics_->measureTime(histogram_name_, ElapsedMicros());
|
|
}
|
|
}
|
|
|
|
private:
|
|
Env* const env_;
|
|
const uint64_t start_time_;
|
|
std::shared_ptr<Statistics> statistics_;
|
|
const Histograms histogram_name_;
|
|
|
|
};
|
|
} // namespace leveldb
|
|
#endif // STORAGE_LEVELDB_UTIL_STOP_WATCH_H_
|