StopWatch not to get time if it is created for statistics and it is disabled

Summary: Currently, even if statistics is not enabled, StopWatch only for the stats still gets the time of the day, which is wasteful. This patch adds a new option to StopWatch to disable this get in this case.

Test Plan: make all check

Reviewers: dhruba, haobo, igor

CC: leveldb

Differential Revision: https://reviews.facebook.net/D14703

Conflicts:
	db/db_impl.cc
This commit is contained in:
Siying Dong 2014-01-07 14:33:15 -08:00
parent 424a524ac9
commit 237a3da677
2 changed files with 8 additions and 7 deletions

View File

@ -2080,11 +2080,11 @@ Status DBImpl::FinishCompactionOutputFile(CompactionState* compact,
if (s.ok() && !options_.disableDataSync) { if (s.ok() && !options_.disableDataSync) {
if (options_.use_fsync) { if (options_.use_fsync) {
StopWatch sw(env_, options_.statistics.get(), StopWatch sw(env_, options_.statistics.get(),
COMPACTION_OUTFILE_SYNC_MICROS); COMPACTION_OUTFILE_SYNC_MICROS, false);
s = compact->outfile->Fsync(); s = compact->outfile->Fsync();
} else { } else {
StopWatch sw(env_, options_.statistics.get(), StopWatch sw(env_, options_.statistics.get(),
COMPACTION_OUTFILE_SYNC_MICROS); COMPACTION_OUTFILE_SYNC_MICROS, false);
s = compact->outfile->Sync(); s = compact->outfile->Sync();
} }
} }
@ -2717,7 +2717,7 @@ Status DBImpl::GetImpl(const ReadOptions& options,
bool* value_found) { bool* value_found) {
Status s; Status s;
StopWatch sw(env_, options_.statistics.get(), DB_GET); StopWatch sw(env_, options_.statistics.get(), DB_GET, false);
StopWatchNano snapshot_timer(env_, false); StopWatchNano snapshot_timer(env_, false);
StartPerfTimer(&snapshot_timer); StartPerfTimer(&snapshot_timer);
SequenceNumber snapshot; SequenceNumber snapshot;
@ -2798,7 +2798,7 @@ Status DBImpl::GetImpl(const ReadOptions& options,
std::vector<Status> DBImpl::MultiGet(const ReadOptions& options, std::vector<Status> DBImpl::MultiGet(const ReadOptions& options,
const std::vector<Slice>& keys, const std::vector<Slice>& keys,
std::vector<std::string>* values) { std::vector<std::string>* values) {
StopWatch sw(env_, options_.statistics.get(), DB_MULTIGET); StopWatch sw(env_, options_.statistics.get(), DB_MULTIGET, false);
StopWatchNano snapshot_timer(env_, false); StopWatchNano snapshot_timer(env_, false);
StartPerfTimer(&snapshot_timer); StartPerfTimer(&snapshot_timer);
@ -2958,7 +2958,7 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
w.disableWAL = options.disableWAL; w.disableWAL = options.disableWAL;
w.done = false; w.done = false;
StopWatch sw(env_, options_.statistics.get(), DB_WRITE); StopWatch sw(env_, options_.statistics.get(), DB_WRITE, false);
mutex_.Lock(); mutex_.Lock();
writers_.push_back(&w); writers_.push_back(&w);
while (!w.done && &w != writers_.front()) { while (!w.done && &w != writers_.front()) {

View File

@ -15,9 +15,10 @@ class StopWatch {
explicit StopWatch( explicit StopWatch(
Env * const env, Env * const env,
Statistics* statistics = nullptr, Statistics* statistics = nullptr,
const Histograms histogram_name = DB_GET) : const Histograms histogram_name = DB_GET,
bool auto_start = true) :
env_(env), env_(env),
start_time_(env->NowMicros()), start_time_((!auto_start && !statistics) ? 0 : env->NowMicros()),
statistics_(statistics), statistics_(statistics),
histogram_name_(histogram_name) {} histogram_name_(histogram_name) {}