diff --git a/db/db_statistics_test.cc b/db/db_statistics_test.cc index c99af22d6f..d4e4c628b1 100644 --- a/db/db_statistics_test.cc +++ b/db/db_statistics_test.cc @@ -142,6 +142,19 @@ TEST_F(DBStatisticsTest, ResetStats) { } } +TEST_F(DBStatisticsTest, ExcludeTickers) { + Options options = CurrentOptions(); + options.statistics = ROCKSDB_NAMESPACE::CreateDBStatistics(); + DestroyAndReopen(options); + options.statistics->set_stats_level(StatsLevel::kExceptTickers); + ASSERT_OK(Put("foo", "value")); + ASSERT_EQ(0, options.statistics->getTickerCount(BYTES_WRITTEN)); + options.statistics->set_stats_level(StatsLevel::kExceptHistogramOrTimers); + Reopen(options); + ASSERT_EQ("value", Get("foo")); + ASSERT_GT(options.statistics->getTickerCount(BYTES_READ), 0); +} + } // namespace ROCKSDB_NAMESPACE int main(int argc, char** argv) { diff --git a/include/rocksdb/statistics.h b/include/rocksdb/statistics.h index cc99f67638..74ee6bd29b 100644 --- a/include/rocksdb/statistics.h +++ b/include/rocksdb/statistics.h @@ -488,6 +488,10 @@ struct HistogramData { // Usage: // options.statistics->set_stats_level(StatsLevel::kExceptTimeForMutex); enum StatsLevel : uint8_t { + // Disable all metrics + kDisableAll, + // Disable tickers + kExceptTickers = kDisableAll, // Disable timer stats, and skip histogram stats kExceptHistogramOrTimers, // Skip timer stats diff --git a/monitoring/statistics.cc b/monitoring/statistics.cc index 181065c439..b0f8bb30ef 100644 --- a/monitoring/statistics.cc +++ b/monitoring/statistics.cc @@ -329,11 +329,17 @@ uint64_t StatisticsImpl::getAndResetTickerCount(uint32_t tickerType) { } void StatisticsImpl::recordTick(uint32_t tickerType, uint64_t count) { - assert(tickerType < TICKER_ENUM_MAX); - per_core_stats_.Access()->tickers_[tickerType].fetch_add( - count, std::memory_order_relaxed); - if (stats_ && tickerType < TICKER_ENUM_MAX) { - stats_->recordTick(tickerType, count); + if (get_stats_level() <= StatsLevel::kExceptTickers) { + return; + } + if (tickerType < TICKER_ENUM_MAX) { + per_core_stats_.Access()->tickers_[tickerType].fetch_add( + count, std::memory_order_relaxed); + if (stats_) { + stats_->recordTick(tickerType, count); + } + } else { + assert(false); } }