summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorYi Wu <yiwu@fb.com>2016-02-23 10:26:24 -0800
committerYi Wu <yiwu@fb.com>2016-02-23 10:26:24 -0800
commit2568985ab3dfece60bcd8fb61c0bf7b7c7dd0db6 (patch)
treeac54633183ce707481e7f696d2dc4ba75131b1b3 /util
parentb0469166564cb4a686ef33f8209513fdd8606be8 (diff)
IOStatsContext::ToString() add option to exclude zero counters
Summary: similar to D52809 add option to exclude zero counters. Test Plan: [yiwu@dev4504.prn1 ~/rocksdb] ./iostats_context_test [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from IOStatsContextTest [ RUN ] IOStatsContextTest.ToString [ OK ] IOStatsContextTest.ToString (0 ms) [----------] 1 test from IOStatsContextTest (0 ms total) [----------] Global test environment tear-down [==========] 1 test from 1 test case ran. (0 ms total) [ PASSED ] 1 test. Reviewers: anthony, yhchiang, andrewkr, IslamAbdelRahman, kradhakrishnan, sdong Reviewed By: sdong Subscribers: leveldb, dhruba Differential Revision: https://reviews.facebook.net/D54591
Diffstat (limited to 'util')
-rw-r--r--util/iostats_context.cc29
-rw-r--r--util/iostats_context_test.cc29
2 files changed, 45 insertions, 13 deletions
diff --git a/util/iostats_context.cc b/util/iostats_context.cc
index 666fddcd1..a3c72db96 100644
--- a/util/iostats_context.cc
+++ b/util/iostats_context.cc
@@ -31,21 +31,24 @@ void IOStatsContext::Reset() {
logger_nanos = 0;
}
-#define IOSTATS_CONTEXT_OUTPUT(counter) #counter << " = " << counter << ", "
+#define IOSTATS_CONTEXT_OUTPUT(counter) \
+ if (!exclude_zero_counters || counter > 0) { \
+ ss << #counter << " = " << counter << ", "; \
+ }
-std::string IOStatsContext::ToString() const {
+std::string IOStatsContext::ToString(bool exclude_zero_counters) const {
std::ostringstream ss;
- ss << IOSTATS_CONTEXT_OUTPUT(thread_pool_id)
- << IOSTATS_CONTEXT_OUTPUT(bytes_read)
- << IOSTATS_CONTEXT_OUTPUT(bytes_written)
- << IOSTATS_CONTEXT_OUTPUT(open_nanos)
- << IOSTATS_CONTEXT_OUTPUT(allocate_nanos)
- << IOSTATS_CONTEXT_OUTPUT(write_nanos)
- << IOSTATS_CONTEXT_OUTPUT(read_nanos)
- << IOSTATS_CONTEXT_OUTPUT(range_sync_nanos)
- << IOSTATS_CONTEXT_OUTPUT(fsync_nanos)
- << IOSTATS_CONTEXT_OUTPUT(prepare_write_nanos)
- << IOSTATS_CONTEXT_OUTPUT(logger_nanos);
+ IOSTATS_CONTEXT_OUTPUT(thread_pool_id);
+ IOSTATS_CONTEXT_OUTPUT(bytes_read);
+ IOSTATS_CONTEXT_OUTPUT(bytes_written);
+ IOSTATS_CONTEXT_OUTPUT(open_nanos);
+ IOSTATS_CONTEXT_OUTPUT(allocate_nanos);
+ IOSTATS_CONTEXT_OUTPUT(write_nanos);
+ IOSTATS_CONTEXT_OUTPUT(read_nanos);
+ IOSTATS_CONTEXT_OUTPUT(range_sync_nanos);
+ IOSTATS_CONTEXT_OUTPUT(fsync_nanos);
+ IOSTATS_CONTEXT_OUTPUT(prepare_write_nanos);
+ IOSTATS_CONTEXT_OUTPUT(logger_nanos);
return ss.str();
}
diff --git a/util/iostats_context_test.cc b/util/iostats_context_test.cc
new file mode 100644
index 000000000..a2884f8a6
--- /dev/null
+++ b/util/iostats_context_test.cc
@@ -0,0 +1,29 @@
+// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+
+#include "rocksdb/iostats_context.h"
+#include "util/testharness.h"
+
+namespace rocksdb {
+
+TEST(IOStatsContextTest, ToString) {
+ iostats_context.Reset();
+ iostats_context.bytes_read = 12345;
+
+ std::string zero_included = iostats_context.ToString();
+ ASSERT_NE(std::string::npos, zero_included.find("= 0"));
+ ASSERT_NE(std::string::npos, zero_included.find("= 12345"));
+
+ std::string zero_excluded = iostats_context.ToString(true);
+ ASSERT_EQ(std::string::npos, zero_excluded.find("= 0"));
+ ASSERT_NE(std::string::npos, zero_excluded.find("= 12345"));
+}
+
+} // namespace rocksdb
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}