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
This commit is contained in:
Yi Wu 2016-02-23 10:26:24 -08:00
parent b046916656
commit 2568985ab3
6 changed files with 53 additions and 15 deletions

View File

@ -391,6 +391,7 @@ set(TESTS
util/file_reader_writer_test.cc util/file_reader_writer_test.cc
util/heap_test.cc util/heap_test.cc
util/histogram_test.cc util/histogram_test.cc
util/iostats_context_test.cc
util/memenv_test.cc util/memenv_test.cc
util/mock_env_test.cc util/mock_env_test.cc
util/options_test.cc util/options_test.cc

View File

@ -340,7 +340,8 @@ TESTS = \
compact_on_deletion_collector_test \ compact_on_deletion_collector_test \
compaction_job_stats_test \ compaction_job_stats_test \
transaction_test \ transaction_test \
ldb_cmd_test ldb_cmd_test \
iostats_context_test
SUBSET := $(shell echo $(TESTS) |sed s/^.*$(ROCKSDBTESTS_START)/$(ROCKSDBTESTS_START)/) SUBSET := $(shell echo $(TESTS) |sed s/^.*$(ROCKSDBTESTS_START)/$(ROCKSDBTESTS_START)/)
@ -1045,6 +1046,9 @@ ldb_cmd_test: tools/ldb_cmd_test.o $(LIBOBJECTS) $(TESTHARNESS)
ldb: tools/ldb.o $(LIBOBJECTS) ldb: tools/ldb.o $(LIBOBJECTS)
$(AM_LINK) $(AM_LINK)
iostats_context_test: util/iostats_context_test.o $(LIBOBJECTS) $(TESTHARNESS)
$(AM_V_CCLD)$(CXX) $^ $(EXEC_LDFLAGS) -o $@ $(LDFLAGS)
#------------------------------------------------- #-------------------------------------------------
# make install related stuff # make install related stuff
INSTALL_PATH ?= /usr/local INSTALL_PATH ?= /usr/local

View File

@ -18,7 +18,7 @@ struct IOStatsContext {
// reset all io-stats counter to zero // reset all io-stats counter to zero
void Reset(); void Reset();
std::string ToString() const; std::string ToString(bool exclude_zero_counters = false) const;
// the thread pool id // the thread pool id
uint64_t thread_pool_id; uint64_t thread_pool_id;

1
src.mk
View File

@ -269,6 +269,7 @@ TEST_BENCH_SOURCES = \
utilities/transactions/transaction_test.cc \ utilities/transactions/transaction_test.cc \
utilities/ttl/ttl_test.cc \ utilities/ttl/ttl_test.cc \
utilities/write_batch_with_index/write_batch_with_index_test.cc \ utilities/write_batch_with_index/write_batch_with_index_test.cc \
util/iostats_context_test.cc \
util/log_write_bench.cc \ util/log_write_bench.cc \
util/memenv_test.cc \ util/memenv_test.cc \
util/mock_env_test.cc \ util/mock_env_test.cc \

View File

@ -31,21 +31,24 @@ void IOStatsContext::Reset() {
logger_nanos = 0; 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; std::ostringstream ss;
ss << IOSTATS_CONTEXT_OUTPUT(thread_pool_id) IOSTATS_CONTEXT_OUTPUT(thread_pool_id);
<< IOSTATS_CONTEXT_OUTPUT(bytes_read) IOSTATS_CONTEXT_OUTPUT(bytes_read);
<< IOSTATS_CONTEXT_OUTPUT(bytes_written) IOSTATS_CONTEXT_OUTPUT(bytes_written);
<< IOSTATS_CONTEXT_OUTPUT(open_nanos) IOSTATS_CONTEXT_OUTPUT(open_nanos);
<< IOSTATS_CONTEXT_OUTPUT(allocate_nanos) IOSTATS_CONTEXT_OUTPUT(allocate_nanos);
<< IOSTATS_CONTEXT_OUTPUT(write_nanos) IOSTATS_CONTEXT_OUTPUT(write_nanos);
<< IOSTATS_CONTEXT_OUTPUT(read_nanos) IOSTATS_CONTEXT_OUTPUT(read_nanos);
<< IOSTATS_CONTEXT_OUTPUT(range_sync_nanos) IOSTATS_CONTEXT_OUTPUT(range_sync_nanos);
<< IOSTATS_CONTEXT_OUTPUT(fsync_nanos) IOSTATS_CONTEXT_OUTPUT(fsync_nanos);
<< IOSTATS_CONTEXT_OUTPUT(prepare_write_nanos) IOSTATS_CONTEXT_OUTPUT(prepare_write_nanos);
<< IOSTATS_CONTEXT_OUTPUT(logger_nanos); IOSTATS_CONTEXT_OUTPUT(logger_nanos);
return ss.str(); return ss.str();
} }

View File

@ -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();
}