Skip to content

Commit 92c1eb0

Browse files
author
Lei Jin
committed
macros for perf_context
Summary: This will allow us to disable them completely for iOS or for better performance Test Plan: will run make all check Reviewers: igor, haobo, dhruba Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D17511
1 parent 5abae2c commit 92c1eb0

11 files changed

+133
-99
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ ldb: tools/ldb.o $(LIBOBJECTS)
418418
# ---------------------------------------------------------------------------
419419
JNI_NATIVE_SOURCES = ./java/rocksjni/rocksjni.cc ./java/rocksjni/options.cc ./java/rocksjni/write_batch.cc
420420

421-
JAVA_INCLUDE = -I/usr/lib/jvm/java-openjdk/include/ -I/usr/lib/jvm/java-openjdk/include/linux
421+
JAVA_INCLUDE = -I/usr/lib/jvm/java-openjdk/include/ -I/usr/lib/jvm/java-openjdk/include/linux
422422
ROCKSDBJNILIB = ./java/librocksdbjni.so
423423

424424
ifeq ($(PLATFORM), OS_MACOSX)

db/db_impl.cc

+18-29
Original file line numberDiff line numberDiff line change
@@ -3331,8 +3331,7 @@ Status DBImpl::GetImpl(const ReadOptions& options,
33313331
ColumnFamilyHandle* column_family, const Slice& key,
33323332
std::string* value, bool* value_found) {
33333333
StopWatch sw(env_, options_.statistics.get(), DB_GET, false);
3334-
StopWatchNano snapshot_timer(env_, false);
3335-
StartPerfTimer(&snapshot_timer);
3334+
PERF_TIMER_AUTO(get_snapshot_time);
33363335

33373336
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(column_family);
33383337
auto cfd = cfh->cfd();
@@ -3404,26 +3403,24 @@ Status DBImpl::GetImpl(const ReadOptions& options,
34043403
// s is both in/out. When in, s could either be OK or MergeInProgress.
34053404
// merge_operands will contain the sequence of merges in the latter case.
34063405
LookupKey lkey(key, snapshot);
3407-
BumpPerfTime(&perf_context.get_snapshot_time, &snapshot_timer);
3406+
PERF_TIMER_STOP(get_snapshot_time);
34083407
if (sv->mem->Get(lkey, value, &s, merge_context, *cfd->options())) {
34093408
// Done
34103409
RecordTick(options_.statistics.get(), MEMTABLE_HIT);
34113410
} else if (sv->imm->Get(lkey, value, &s, merge_context, *cfd->options())) {
34123411
// Done
34133412
RecordTick(options_.statistics.get(), MEMTABLE_HIT);
34143413
} else {
3415-
StopWatchNano from_files_timer(env_, false);
3416-
StartPerfTimer(&from_files_timer);
3414+
PERF_TIMER_START(get_from_output_files_time);
34173415

34183416
sv->current->Get(options, lkey, value, &s, &merge_context, &stats,
34193417
*cfd->options(), value_found);
34203418
have_stat_update = true;
3421-
BumpPerfTime(&perf_context.get_from_output_files_time, &from_files_timer);
3419+
PERF_TIMER_STOP(get_from_output_files_time);
34223420
RecordTick(options_.statistics.get(), MEMTABLE_MISS);
34233421
}
34243422

3425-
StopWatchNano post_process_timer(env_, false);
3426-
StartPerfTimer(&post_process_timer);
3423+
PERF_TIMER_START(get_post_process_time);
34273424

34283425
if (!cfd->options()->disable_seek_compaction && have_stat_update) {
34293426
mutex_.Lock();
@@ -3464,7 +3461,7 @@ Status DBImpl::GetImpl(const ReadOptions& options,
34643461

34653462
RecordTick(options_.statistics.get(), NUMBER_KEYS_READ);
34663463
RecordTick(options_.statistics.get(), BYTES_READ, value->size());
3467-
BumpPerfTime(&perf_context.get_post_process_time, &post_process_timer);
3464+
PERF_TIMER_STOP(get_post_process_time);
34683465
return s;
34693466
}
34703467

@@ -3474,8 +3471,7 @@ std::vector<Status> DBImpl::MultiGet(
34743471
const std::vector<Slice>& keys, std::vector<std::string>* values) {
34753472

34763473
StopWatch sw(env_, options_.statistics.get(), DB_MULTIGET, false);
3477-
StopWatchNano snapshot_timer(env_, false);
3478-
StartPerfTimer(&snapshot_timer);
3474+
PERF_TIMER_AUTO(get_snapshot_time);
34793475

34803476
SequenceNumber snapshot;
34813477

@@ -3519,7 +3515,7 @@ std::vector<Status> DBImpl::MultiGet(
35193515

35203516
// Keep track of bytes that we read for statistics-recording later
35213517
uint64_t bytes_read = 0;
3522-
BumpPerfTime(&perf_context.get_snapshot_time, &snapshot_timer);
3518+
PERF_TIMER_STOP(get_snapshot_time);
35233519

35243520
// For each of the given keys, apply the entire "get" process as follows:
35253521
// First look in the memtable, then in the immutable memtable (if any).
@@ -3555,8 +3551,7 @@ std::vector<Status> DBImpl::MultiGet(
35553551
}
35563552

35573553
// Post processing (decrement reference counts and record statistics)
3558-
StopWatchNano post_process_timer(env_, false);
3559-
StartPerfTimer(&post_process_timer);
3554+
PERF_TIMER_START(get_post_process_time);
35603555
autovector<SuperVersion*> superversions_to_delete;
35613556

35623557
bool schedule_flush_or_compaction = false;
@@ -3589,7 +3584,7 @@ std::vector<Status> DBImpl::MultiGet(
35893584
RecordTick(options_.statistics.get(), NUMBER_MULTIGET_CALLS);
35903585
RecordTick(options_.statistics.get(), NUMBER_MULTIGET_KEYS_READ, num_keys);
35913586
RecordTick(options_.statistics.get(), NUMBER_MULTIGET_BYTES_READ, bytes_read);
3592-
BumpPerfTime(&perf_context.get_post_process_time, &post_process_timer);
3587+
PERF_TIMER_STOP(get_post_process_time);
35933588

35943589
return stat_list;
35953590
}
@@ -3803,8 +3798,7 @@ Status DBImpl::Delete(const WriteOptions& options,
38033798
}
38043799

38053800
Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
3806-
StopWatchNano pre_post_process_timer(env_, false);
3807-
StartPerfTimer(&pre_post_process_timer);
3801+
PERF_TIMER_AUTO(write_pre_and_post_process_time);
38083802
Writer w(&mutex_);
38093803
w.batch = my_batch;
38103804
w.sync = options.sync;
@@ -3883,12 +3877,10 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
38833877
if (options.disableWAL) {
38843878
flush_on_destroy_ = true;
38853879
}
3886-
BumpPerfTime(&perf_context.write_pre_and_post_process_time,
3887-
&pre_post_process_timer);
3880+
PERF_TIMER_STOP(write_pre_and_post_process_time);
38883881

38893882
if (!options.disableWAL) {
3890-
StopWatchNano timer(env_);
3891-
StartPerfTimer(&timer);
3883+
PERF_TIMER_START(write_wal_time);
38923884
Slice log_entry = WriteBatchInternal::Contents(updates);
38933885
status = log_->AddRecord(log_entry);
38943886
RecordTick(options_.statistics.get(), WAL_FILE_SYNCED, 1);
@@ -3902,15 +3894,13 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
39023894
status = log_->file()->Sync();
39033895
}
39043896
}
3905-
BumpPerfTime(&perf_context.write_wal_time, &timer);
3897+
PERF_TIMER_STOP(write_wal_time);
39063898
}
39073899
if (status.ok()) {
3908-
StopWatchNano write_memtable_timer(env_, false);
3909-
3910-
StartPerfTimer(&write_memtable_timer);
3900+
PERF_TIMER_START(write_memtable_time);
39113901
status = WriteBatchInternal::InsertInto(
39123902
updates, column_family_memtables_.get(), false, 0, this, false);
3913-
BumpPerfTime(&perf_context.write_memtable_time, &write_memtable_timer);
3903+
PERF_TIMER_STOP(write_memtable_time);
39143904

39153905
if (!status.ok()) {
39163906
// Iteration failed (either in-memory writebatch corruption (very
@@ -3924,7 +3914,7 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
39243914
SetTickerCount(options_.statistics.get(), SEQUENCE_NUMBER,
39253915
last_sequence);
39263916
}
3927-
StartPerfTimer(&pre_post_process_timer);
3917+
PERF_TIMER_START(write_pre_and_post_process_time);
39283918
if (updates == &tmp_batch_) tmp_batch_.Clear();
39293919
mutex_.Lock();
39303920
if (status.ok()) {
@@ -3952,8 +3942,7 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
39523942
writers_.front()->cv.Signal();
39533943
}
39543944
mutex_.Unlock();
3955-
BumpPerfTime(&perf_context.write_pre_and_post_process_time,
3956-
&pre_post_process_timer);
3945+
PERF_TIMER_STOP(write_pre_and_post_process_time);
39573946
return status;
39583947
}
39593948

db/db_iter.cc

+10-14
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,9 @@ void DBIter::Next() {
189189
// NOTE: In between, saved_key_ can point to a user key that has
190190
// a delete marker
191191
inline void DBIter::FindNextUserEntry(bool skipping) {
192-
StopWatchNano timer(env_, false);
193-
StartPerfTimer(&timer);
192+
PERF_TIMER_AUTO(find_next_user_entry_time);
194193
FindNextUserEntryInternal(skipping);
195-
BumpPerfTime(&perf_context.find_next_user_entry_time, &timer);
194+
PERF_TIMER_STOP(find_next_user_entry_time);
196195
}
197196

198197
// Actual implementation of DBIter::FindNextUserEntry()
@@ -208,7 +207,7 @@ void DBIter::FindNextUserEntryInternal(bool skipping) {
208207
if (skipping &&
209208
user_comparator_->Compare(ikey.user_key, saved_key_.GetKey()) <= 0) {
210209
num_skipped++; // skip this entry
211-
BumpPerfCount(&perf_context.internal_key_skipped_count);
210+
PERF_COUNTER_ADD(internal_key_skipped_count, 1);
212211
} else {
213212
skipping = false;
214213
switch (ikey.type) {
@@ -218,7 +217,7 @@ void DBIter::FindNextUserEntryInternal(bool skipping) {
218217
saved_key_.SetUserKey(ikey.user_key);
219218
skipping = true;
220219
num_skipped = 0;
221-
BumpPerfCount(&perf_context.internal_delete_skipped_count);
220+
PERF_COUNTER_ADD(internal_delete_skipped_count, 1);
222221
break;
223222
case kTypeValue:
224223
valid_ = true;
@@ -423,10 +422,9 @@ void DBIter::Seek(const Slice& target) {
423422
saved_key_.Clear();
424423
// now savved_key is used to store internal key.
425424
saved_key_.SetInternalKey(target, sequence_);
426-
StopWatchNano internal_seek_timer(env_, false);
427-
StartPerfTimer(&internal_seek_timer);
425+
PERF_TIMER_AUTO(seek_internal_seek_time);
428426
iter_->Seek(saved_key_.GetKey());
429-
BumpPerfTime(&perf_context.seek_internal_seek_time, &internal_seek_timer);
427+
PERF_TIMER_STOP(seek_internal_seek_time);
430428
if (iter_->Valid()) {
431429
direction_ = kForward;
432430
ClearSavedValue();
@@ -439,10 +437,9 @@ void DBIter::Seek(const Slice& target) {
439437
void DBIter::SeekToFirst() {
440438
direction_ = kForward;
441439
ClearSavedValue();
442-
StopWatchNano internal_seek_timer(env_, false);
443-
StartPerfTimer(&internal_seek_timer);
440+
PERF_TIMER_AUTO(seek_internal_seek_time);
444441
iter_->SeekToFirst();
445-
BumpPerfTime(&perf_context.seek_internal_seek_time, &internal_seek_timer);
442+
PERF_TIMER_STOP(seek_internal_seek_time);
446443
if (iter_->Valid()) {
447444
FindNextUserEntry(false /* not skipping */);
448445
} else {
@@ -461,10 +458,9 @@ void DBIter::SeekToLast() {
461458

462459
direction_ = kReverse;
463460
ClearSavedValue();
464-
StopWatchNano internal_seek_timer(env_, false);
465-
StartPerfTimer(&internal_seek_timer);
461+
PERF_TIMER_AUTO(seek_internal_seek_time);
466462
iter_->SeekToLast();
467-
BumpPerfTime(&perf_context.seek_internal_seek_time, &internal_seek_timer);
463+
PERF_TIMER_STOP(seek_internal_seek_time);
468464
FindPrevUserEntry();
469465
}
470466

db/dbformat.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int InternalKeyComparator::Compare(const Slice& akey, const Slice& bkey) const {
5959
// decreasing sequence number
6060
// decreasing type (though sequence# should be enough to disambiguate)
6161
int r = user_comparator_->Compare(ExtractUserKey(akey), ExtractUserKey(bkey));
62-
BumpPerfCount(&perf_context.user_key_comparison_count);
62+
PERF_COUNTER_ADD(user_key_comparison_count, 1);
6363
if (r == 0) {
6464
const uint64_t anum = DecodeFixed64(akey.data() + akey.size() - 8);
6565
const uint64_t bnum = DecodeFixed64(bkey.data() + bkey.size() - 8);
@@ -79,7 +79,7 @@ int InternalKeyComparator::Compare(const ParsedInternalKey& a,
7979
// decreasing sequence number
8080
// decreasing type (though sequence# should be enough to disambiguate)
8181
int r = user_comparator_->Compare(a.user_key, b.user_key);
82-
BumpPerfCount(&perf_context.user_key_comparison_count);
82+
PERF_COUNTER_ADD(user_key_comparison_count, 1);
8383
if (r == 0) {
8484
if (a.sequence > b.sequence) {
8585
r = -1;

db/memtable.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ static bool SaveValue(void* arg, const char* entry) {
377377

378378
bool MemTable::Get(const LookupKey& key, std::string* value, Status* s,
379379
MergeContext& merge_context, const Options& options) {
380-
StopWatchNano memtable_get_timer(options.env, false);
381-
StartPerfTimer(&memtable_get_timer);
380+
PERF_TIMER_AUTO(get_from_memtable_time);
382381

383382
Slice user_key = key.user_key();
384383
bool found_final_value = false;
@@ -408,8 +407,8 @@ bool MemTable::Get(const LookupKey& key, std::string* value, Status* s,
408407
if (!found_final_value && merge_in_progress) {
409408
*s = Status::MergeInProgress("");
410409
}
411-
BumpPerfTime(&perf_context.get_from_memtable_time, &memtable_get_timer);
412-
BumpPerfCount(&perf_context.get_from_memtable_count);
410+
PERF_TIMER_STOP(get_from_memtable_time);
411+
PERF_COUNTER_ADD(get_from_memtable_count, 1);
413412
return found_final_value;
414413
}
415414

include/rocksdb/perf_context.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct PerfContext {
6464
uint64_t write_memtable_time;
6565
};
6666

67-
#if defined(IOS_CROSS_COMPILE)
67+
#if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE)
6868
extern PerfContext perf_context;
6969
#else
7070
extern __thread PerfContext perf_context;

table/block_based_table_reader.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Cache::Handle* GetEntryFromCache(Cache* block_cache, const Slice& key,
107107
Statistics* statistics) {
108108
auto cache_handle = block_cache->Lookup(key);
109109
if (cache_handle != nullptr) {
110-
BumpPerfCount(&perf_context.block_cache_hit_count);
110+
PERF_COUNTER_ADD(block_cache_hit_count, 1);
111111
// overall cache hit
112112
RecordTick(statistics, BLOCK_CACHE_HIT);
113113
// block-type specific cache hit

table/format.cc

+6-7
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,11 @@ Status ReadBlockContents(RandomAccessFile* file,
125125
char* buf = new char[n + kBlockTrailerSize];
126126
Slice contents;
127127

128-
StopWatchNano timer(env);
129-
StartPerfTimer(&timer);
128+
PERF_TIMER_AUTO(block_read_time);
130129
Status s = file->Read(handle.offset(), n + kBlockTrailerSize, &contents, buf);
131-
BumpPerfCount(&perf_context.block_read_count);
132-
BumpPerfCount(&perf_context.block_read_byte, n + kBlockTrailerSize);
133-
BumpPerfTime(&perf_context.block_read_time, &timer);
130+
PERF_TIMER_MEASURE(block_read_time);
131+
PERF_COUNTER_ADD(block_read_count, 1);
132+
PERF_COUNTER_ADD(block_read_byte, n + kBlockTrailerSize);
134133

135134
if (!s.ok()) {
136135
delete[] buf;
@@ -151,7 +150,7 @@ Status ReadBlockContents(RandomAccessFile* file,
151150
s = Status::Corruption("block checksum mismatch");
152151
return s;
153152
}
154-
BumpPerfTime(&perf_context.block_checksum_time, &timer);
153+
PERF_TIMER_MEASURE(block_checksum_time);
155154
}
156155

157156
// If the caller has requested that the block not be uncompressed
@@ -175,7 +174,7 @@ Status ReadBlockContents(RandomAccessFile* file,
175174
s = UncompressBlockContents(data, n, result);
176175
delete[] buf;
177176
}
178-
BumpPerfTime(&perf_context.block_decompress_time, &timer);
177+
PERF_TIMER_STOP(block_decompress_time);
179178
return s;
180179
}
181180

table/merger.cc

+11-13
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ class MergingIterator : public Iterator {
7979
// Invalidate the heap.
8080
use_heap_ = false;
8181
IteratorWrapper* first_child = nullptr;
82-
StopWatchNano child_seek_timer(env_, false);
83-
StopWatchNano min_heap_timer(env_, false);
82+
PERF_TIMER_DECLARE();
83+
8484
for (auto& child : children_) {
85-
StartPerfTimer(&child_seek_timer);
85+
PERF_TIMER_START(seek_child_seek_time);
8686
child.Seek(target);
87-
BumpPerfTime(&perf_context.seek_child_seek_time, &child_seek_timer);
88-
BumpPerfCount(&perf_context.seek_child_seek_count);
87+
PERF_TIMER_STOP(seek_child_seek_time);
88+
PERF_COUNTER_ADD(seek_child_seek_count, 1);
8989

9090
if (child.Valid()) {
9191
// This child has valid key
@@ -97,26 +97,24 @@ class MergingIterator : public Iterator {
9797
} else {
9898
// We have more than one children with valid keys. Initialize
9999
// the heap and put the first child into the heap.
100-
StartPerfTimer(&min_heap_timer);
100+
PERF_TIMER_START(seek_min_heap_time);
101101
ClearHeaps();
102-
BumpPerfTime(&perf_context.seek_min_heap_time, &child_seek_timer);
103-
StartPerfTimer(&min_heap_timer);
104102
minHeap_.push(first_child);
105-
BumpPerfTime(&perf_context.seek_min_heap_time, &child_seek_timer);
103+
PERF_TIMER_STOP(seek_min_heap_time);
106104
}
107105
}
108106
if (use_heap_) {
109-
StartPerfTimer(&min_heap_timer);
107+
PERF_TIMER_START(seek_min_heap_time);
110108
minHeap_.push(&child);
111-
BumpPerfTime(&perf_context.seek_min_heap_time, &child_seek_timer);
109+
PERF_TIMER_STOP(seek_min_heap_time);
112110
}
113111
}
114112
}
115113
if (use_heap_) {
116114
// If heap is valid, need to put the smallest key to curent_.
117-
StartPerfTimer(&min_heap_timer);
115+
PERF_TIMER_START(seek_min_heap_time);
118116
FindSmallest();
119-
BumpPerfTime(&perf_context.seek_min_heap_time, &child_seek_timer);
117+
PERF_TIMER_STOP(seek_min_heap_time);
120118
} else {
121119
// The heap is not valid, then the current_ iterator is the first
122120
// one, or null if there is no first child.

0 commit comments

Comments
 (0)