]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore: measure cache hit ratio by src
authorYingxin Cheng <yingxin.cheng@intel.com>
Tue, 27 Jul 2021 08:04:28 +0000 (16:04 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Thu, 29 Jul 2021 06:58:18 +0000 (14:58 +0800)
Remove excessive amount of cache hit/access metrics by extent type.

Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/os/seastore/cache.cc
src/crimson/os/seastore/cache.h

index 8966dc5a9e3e944ddffc44922720fdd707c42005..9e6b26e1cfd306ede2741e4055250d7c2e804f14 100644 (file)
@@ -275,73 +275,27 @@ void Cache::register_metrics()
   /*
    * 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
index 35d175360b2f1e54c24ca977dc24adc201b163d8..e4da2bd34b71a76dd016a9c16690cf776594902d 100644 (file)
@@ -592,8 +592,8 @@ private:
   CachedExtent::list dirty;
 
   struct query_counters_t {
-    uint64_t access;
-    uint64_t hit;
+    uint64_t access = 0;
+    uint64_t hit = 0;
   };
 
   /**
@@ -662,8 +662,7 @@ private:
     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;
@@ -758,8 +757,7 @@ private:
       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);