/*
* cache_query: cache_access and cache_hit
*/
- auto register_cache_access =
- [this, &labels_by_src, &labels_by_ext]
- (src_t src, const sm::label_instance& src_label,
- extent_types_t ext, const sm::label_instance& ext_label) {
- auto m_key = std::make_pair(src, ext);
- stats.cache_query[m_key] = {0, 0};
- {
- metrics.add_group(
- "cache",
- {
- sm::make_counter(
- "cache_access",
- stats.cache_query.find(m_key)->second.access,
- sm::description("total number of cache accesses labeled by "
- "transaction source and extent type"),
- {src_label, ext_label}
- ),
- sm::make_counter(
- "cache_hit",
- stats.cache_query.find(m_key)->second.hit,
- sm::description("total number of cache hits labeled by "
- "transaction source and extent type"),
- {src_label, ext_label}
- ),
- }
- );
- }
- };
-
+ stats.cache_query_by_src.fill({});
for (auto& [src, src_label] : labels_by_src) {
- for (auto& [ext, ext_label] : labels_by_ext) {
- if (ext != extent_types_t::RETIRED_PLACEHOLDER) {
- register_cache_access(src, src_label, ext, ext_label);
+ metrics.add_group(
+ "cache",
+ {
+ sm::make_counter(
+ "cache_access",
+ get_counter(stats.cache_query_by_src, src).access,
+ sm::description("total number of cache accesses"),
+ {src_label}
+ ),
+ sm::make_counter(
+ "cache_hit",
+ get_counter(stats.cache_query_by_src, src).hit,
+ sm::description("total number of cache hits"),
+ {src_label}
+ ),
}
- }
+ );
}
- metrics.add_group(
- "cache",
- {
- sm::make_counter(
- "cache_access",
- [this] {
- uint64_t total = 0;
- for (auto& [k, v] : stats.cache_query) {
- total += v.access;
- }
- return total;
- },
- sm::description("total number of cache accesses"),
- {src_label("ALL")}
- ),
- sm::make_counter(
- "cache_hit",
- [this] {
- uint64_t total = 0;
- for (auto& [k, v] : stats.cache_query) {
- total += v.hit;
- }
- return total;
- },
- sm::description("total number of cache hits"),
- {src_label("ALL")}
- ),
- }
- );
-
{
/*
* efforts discarded/committed
CachedExtent::list dirty;
struct query_counters_t {
- uint64_t access;
- uint64_t hit;
+ uint64_t access = 0;
+ uint64_t hit = 0;
};
/**
std::unordered_map<src_ext_t, uint64_t,
boost::hash<src_ext_t>> trans_invalidated;
std::array<trans_efforts_t, Transaction::SRC_MAX> invalidated_efforts_by_src;
- std::unordered_map<src_ext_t, query_counters_t,
- boost::hash<src_ext_t>> cache_query;
+ std::array<query_counters_t, Transaction::SRC_MAX> cache_query_by_src;
uint64_t read_transactions_successful;
effort_t read_effort_successful;
uint64_t dirty_bytes;
const src_ext_t* p_metric_key) {
query_counters_t* p_counters = nullptr;
if (p_metric_key) {
- assert(stats.cache_query.count(*p_metric_key));
- p_counters = &stats.cache_query[*p_metric_key];
+ p_counters = &get_counter(stats.cache_query_by_src, p_metric_key->first);
++p_counters->access;
}
if (auto iter = extents.find_offset(offset);