Skip to content

Commit 237a3da

Browse files
committed
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
1 parent 424a524 commit 237a3da

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

db/db_impl.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -2080,11 +2080,11 @@ Status DBImpl::FinishCompactionOutputFile(CompactionState* compact,
20802080
if (s.ok() && !options_.disableDataSync) {
20812081
if (options_.use_fsync) {
20822082
StopWatch sw(env_, options_.statistics.get(),
2083-
COMPACTION_OUTFILE_SYNC_MICROS);
2083+
COMPACTION_OUTFILE_SYNC_MICROS, false);
20842084
s = compact->outfile->Fsync();
20852085
} else {
20862086
StopWatch sw(env_, options_.statistics.get(),
2087-
COMPACTION_OUTFILE_SYNC_MICROS);
2087+
COMPACTION_OUTFILE_SYNC_MICROS, false);
20882088
s = compact->outfile->Sync();
20892089
}
20902090
}
@@ -2717,7 +2717,7 @@ Status DBImpl::GetImpl(const ReadOptions& options,
27172717
bool* value_found) {
27182718
Status s;
27192719

2720-
StopWatch sw(env_, options_.statistics.get(), DB_GET);
2720+
StopWatch sw(env_, options_.statistics.get(), DB_GET, false);
27212721
StopWatchNano snapshot_timer(env_, false);
27222722
StartPerfTimer(&snapshot_timer);
27232723
SequenceNumber snapshot;
@@ -2798,7 +2798,7 @@ Status DBImpl::GetImpl(const ReadOptions& options,
27982798
std::vector<Status> DBImpl::MultiGet(const ReadOptions& options,
27992799
const std::vector<Slice>& keys,
28002800
std::vector<std::string>* values) {
2801-
StopWatch sw(env_, options_.statistics.get(), DB_MULTIGET);
2801+
StopWatch sw(env_, options_.statistics.get(), DB_MULTIGET, false);
28022802
StopWatchNano snapshot_timer(env_, false);
28032803
StartPerfTimer(&snapshot_timer);
28042804

@@ -2958,7 +2958,7 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
29582958
w.disableWAL = options.disableWAL;
29592959
w.done = false;
29602960

2961-
StopWatch sw(env_, options_.statistics.get(), DB_WRITE);
2961+
StopWatch sw(env_, options_.statistics.get(), DB_WRITE, false);
29622962
mutex_.Lock();
29632963
writers_.push_back(&w);
29642964
while (!w.done && &w != writers_.front()) {

util/stop_watch.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ class StopWatch {
1515
explicit StopWatch(
1616
Env * const env,
1717
Statistics* statistics = nullptr,
18-
const Histograms histogram_name = DB_GET) :
18+
const Histograms histogram_name = DB_GET,
19+
bool auto_start = true) :
1920
env_(env),
20-
start_time_(env->NowMicros()),
21+
start_time_((!auto_start && !statistics) ? 0 : env->NowMicros()),
2122
statistics_(statistics),
2223
histogram_name_(histogram_name) {}
2324

0 commit comments

Comments
 (0)