Skip to content

Commit 04298f8

Browse files
author
Lei Jin
committed
output perf_context in db_bench readrandom
Summary: Add helper function to print perf context data in db_bench if enabled. I didn't find any code that actually exports perf context data. Not sure if I missed anything Test Plan: ran db_bench Reviewers: haobo, sdong, igor Reviewed By: igor CC: leveldb Differential Revision: https://reviews.facebook.net/D16575
1 parent 64138b5 commit 04298f8

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

db/db_bench.cc

+5
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,12 @@ class Benchmark {
19941994
char msg[100];
19951995
snprintf(msg, sizeof(msg), "(%" PRIu64 " of %" PRIu64 " found)",
19961996
found, reads_);
1997+
19971998
thread->stats.AddMessage(msg);
1999+
2000+
if (FLAGS_perf_level > 0) {
2001+
thread->stats.AddMessage(perf_context.ToString());
2002+
}
19982003
}
19992004

20002005
void PrefixScanRandom(ThreadState* thread) {

include/rocksdb/perf_context.h

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define STORAGE_ROCKSDB_INCLUDE_PERF_CONTEXT_H
88

99
#include <stdint.h>
10+
#include <string>
1011

1112
namespace rocksdb {
1213

@@ -26,6 +27,8 @@ struct PerfContext {
2627

2728
void Reset(); // reset all performance counters to zero
2829

30+
std::string ToString() const;
31+
2932
uint64_t user_key_comparison_count; // total number of user key comparisons
3033
uint64_t block_cache_hit_count; // total number of block cache hits
3134
uint64_t block_read_count; // total number of block reads (with IO)

util/perf_context.cc

+31
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// LICENSE file in the root directory of this source tree. An additional grant
44
// of patent rights can be found in the PATENTS file in the same directory.
55
//
6+
7+
#include <sstream>
68
#include "util/perf_context_imp.h"
79

810
namespace rocksdb {
@@ -38,6 +40,35 @@ void PerfContext::Reset() {
3840
write_memtable_time = 0;
3941
}
4042

43+
#define OUTPUT(counter) #counter << " = " << counter << ", "
44+
45+
std::string PerfContext::ToString() const {
46+
std::ostringstream ss;
47+
ss << OUTPUT(user_key_comparison_count)
48+
<< OUTPUT(block_cache_hit_count)
49+
<< OUTPUT(block_read_count)
50+
<< OUTPUT(block_read_byte)
51+
<< OUTPUT(block_read_time)
52+
<< OUTPUT(block_checksum_time)
53+
<< OUTPUT(block_decompress_time)
54+
<< OUTPUT(internal_key_skipped_count)
55+
<< OUTPUT(internal_delete_skipped_count)
56+
<< OUTPUT(write_wal_time)
57+
<< OUTPUT(get_snapshot_time)
58+
<< OUTPUT(get_from_memtable_time)
59+
<< OUTPUT(get_from_memtable_count)
60+
<< OUTPUT(get_post_process_time)
61+
<< OUTPUT(get_from_output_files_time)
62+
<< OUTPUT(seek_child_seek_time)
63+
<< OUTPUT(seek_child_seek_count)
64+
<< OUTPUT(seek_min_heap_time)
65+
<< OUTPUT(seek_internal_seek_time)
66+
<< OUTPUT(find_next_user_entry_time)
67+
<< OUTPUT(write_pre_and_post_process_time)
68+
<< OUTPUT(write_memtable_time);
69+
return ss.str();
70+
}
71+
4172
__thread PerfContext perf_context;
4273

4374
}

0 commit comments

Comments
 (0)