From 1b01d23be2a50e4514c0eb2e530ce77841324dfc Mon Sep 17 00:00:00 2001 From: Anand Ananthabhotla Date: Fri, 7 Dec 2018 15:04:20 -0800 Subject: [PATCH] Add PerfContext counters for index/filter block cache stats (#4540) Summary: Add counters to track block cache index/filter hits and misses. We currently count aggregate hits and misses, which includes index/filter/data blocks. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4540 Differential Revision: D10459652 Pulled By: anand1976 fbshipit-source-id: 0c59eee7f12f5103dcb6686f0e7995babe63d425 --- include/rocksdb/perf_context.h | 4 ++++ monitoring/perf_context.cc | 8 ++++++++ table/block_based_table_reader.cc | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/include/rocksdb/perf_context.h b/include/rocksdb/perf_context.h index 1b11fa3cc..9fec56b8a 100644 --- a/include/rocksdb/perf_context.h +++ b/include/rocksdb/perf_context.h @@ -60,6 +60,10 @@ struct PerfContext { uint64_t block_read_count; // total number of block reads (with IO) uint64_t block_read_byte; // total number of bytes from block reads uint64_t block_read_time; // total nanos spent on block reads + uint64_t block_cache_index_hit_count; // total number of index block hits + uint64_t index_block_read_count; // total number of index block reads + uint64_t block_cache_filter_hit_count; // total number of filter block hits + uint64_t filter_block_read_count; // total number of filter block reads uint64_t block_checksum_time; // total nanos spent on block checksum uint64_t block_decompress_time; // total nanos spent on block decompression diff --git a/monitoring/perf_context.cc b/monitoring/perf_context.cc index 423443869..6c164cfe9 100644 --- a/monitoring/perf_context.cc +++ b/monitoring/perf_context.cc @@ -44,6 +44,10 @@ void PerfContext::Reset() { block_read_count = 0; block_read_byte = 0; block_read_time = 0; + block_cache_index_hit_count = 0; + index_block_read_count = 0; + block_cache_filter_hit_count = 0; + filter_block_read_count = 0; block_checksum_time = 0; block_decompress_time = 0; get_read_bytes = 0; @@ -152,6 +156,10 @@ std::string PerfContext::ToString(bool exclude_zero_counters) const { PERF_CONTEXT_OUTPUT(block_read_count); PERF_CONTEXT_OUTPUT(block_read_byte); PERF_CONTEXT_OUTPUT(block_read_time); + PERF_CONTEXT_OUTPUT(block_cache_index_hit_count); + PERF_CONTEXT_OUTPUT(index_block_read_count); + PERF_CONTEXT_OUTPUT(block_cache_filter_hit_count); + PERF_CONTEXT_OUTPUT(filter_block_read_count); PERF_CONTEXT_OUTPUT(block_checksum_time); PERF_CONTEXT_OUTPUT(block_decompress_time); PERF_CONTEXT_OUTPUT(get_read_bytes); diff --git a/table/block_based_table_reader.cc b/table/block_based_table_reader.cc index 3fba7b103..974ba4b24 100644 --- a/table/block_based_table_reader.cc +++ b/table/block_based_table_reader.cc @@ -1617,6 +1617,7 @@ BlockBasedTable::CachableEntry BlockBasedTable::GetFilter( FilterBlockReader* filter = nullptr; if (cache_handle != nullptr) { + PERF_COUNTER_ADD(block_cache_filter_hit_count, 1); filter = reinterpret_cast( block_cache->Value(cache_handle)); } else if (no_io) { @@ -1633,6 +1634,7 @@ BlockBasedTable::CachableEntry BlockBasedTable::GetFilter( ? Cache::Priority::HIGH : Cache::Priority::LOW); if (s.ok()) { + PERF_COUNTER_ADD(filter_block_read_count, 1); if (get_context != nullptr) { get_context->get_context_stats_.num_cache_add++; get_context->get_context_stats_.num_cache_bytes_write += usage; @@ -1708,6 +1710,7 @@ InternalIteratorBase* BlockBasedTable::NewIndexIterator( IndexReader* index_reader = nullptr; if (cache_handle != nullptr) { + PERF_COUNTER_ADD(block_cache_index_hit_count, 1); index_reader = reinterpret_cast(block_cache->Value(cache_handle)); } else { @@ -1737,6 +1740,7 @@ InternalIteratorBase* BlockBasedTable::NewIndexIterator( RecordTick(statistics, BLOCK_CACHE_ADD); RecordTick(statistics, BLOCK_CACHE_BYTES_WRITE, charge); } + PERF_COUNTER_ADD(index_block_read_count, 1); RecordTick(statistics, BLOCK_CACHE_INDEX_ADD); RecordTick(statistics, BLOCK_CACHE_INDEX_BYTES_INSERT, charge); } else {