]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: store osd perf counters received in osd reports
authorMykola Golub <mgolub@suse.com>
Mon, 12 Nov 2018 18:41:42 +0000 (20:41 +0200)
committerMykola Golub <mgolub@suse.com>
Tue, 20 Nov 2018 11:18:30 +0000 (13:18 +0200)
Make the counters accessible for the query owners.

Signed-off-by: Mykola Golub <mgolub@suse.com>
src/mgr/OSDPerfMetricCollector.cc
src/mgr/OSDPerfMetricCollector.h

index 1d922d16ed781c1f9abd1700ce01f78231077765..e8669bb163b0d1a5c6a0cd30d7f74a748fc7f290 100644 (file)
@@ -40,6 +40,7 @@ int OSDPerfMetricCollector::add_query(const OSDPerfMetricQuery& query) {
       notify = true;
     }
     it->second.insert(query_id);
+    counters[query_id];
   }
 
   dout(10) << query << " query_id=" << query_id << dendl;
@@ -70,6 +71,7 @@ int OSDPerfMetricCollector::remove_query(int query_id) {
         break;
       }
     }
+    counters.erase(query_id);
   }
 
   if (!found) {
@@ -103,6 +105,23 @@ void OSDPerfMetricCollector::remove_all_queries() {
   }
 }
 
+int OSDPerfMetricCollector::get_counters(
+    OSDPerfMetricQueryID query_id,
+    std::map<OSDPerfMetricKey, PerformanceCounters> *c) {
+  std::lock_guard locker(lock);
+
+  auto it = counters.find(query_id);
+  if (it == counters.end()) {
+    dout(10) << "counters for " << query_id << " not found" << dendl;
+    return -ENOENT;
+  }
+
+  *c = std::move(it->second);
+  it->second.clear();
+
+  return 0;
+}
+
 void OSDPerfMetricCollector::process_reports(
     const std::map<OSDPerfMetricQuery, OSDPerfMetricReport> &reports) {
 
@@ -113,17 +132,42 @@ void OSDPerfMetricCollector::process_reports(
   std::lock_guard locker(lock);
 
   for (auto &it : reports) {
+    auto &query = it.first;
     auto &report = it.second;
-    dout(10) << "report for " << it.first << " query: "
+    dout(10) << "report for " << query << " query: "
              << report.group_packed_performance_counters.size() << " records"
              << dendl;
+
     for (auto &it : report.group_packed_performance_counters) {
       auto &key = it.first;
       auto bl_it = it.second.cbegin();
-      for (auto &d : report.performance_counter_descriptors) {
+
+      for (auto query_id : queries[query]) {
+        auto &key_counters = counters[query_id][key];
+        if (key_counters.empty()) {
+          key_counters.resize(query.performance_counter_descriptors.size(),
+                              {0, 0});
+        }
+      }
+
+      auto desc_it = report.performance_counter_descriptors.begin();
+      for (size_t i = 0; i < query.performance_counter_descriptors.size(); i++) {
+        if (desc_it == report.performance_counter_descriptors.end()) {
+          break;
+        }
+        if (desc_it->type != query.performance_counter_descriptors[i].type) {
+          continue;
+        }
         PerformanceCounter c;
-        d.unpack_counter(bl_it, &c);
-        dout(20) << "counter " << key << " " << d << ": " << c << dendl;
+        desc_it->unpack_counter(bl_it, &c);
+        dout(20) << "counter " << key << " " << *desc_it << ": " << c << dendl;
+
+        for (auto query_id : queries[query]) {
+          auto &key_counters = counters[query_id][key];
+          key_counters[i].first += c.first;
+          key_counters[i].second += c.second;
+        }
+        desc_it++;
       }
     }
   }
index ca32df35ff29b64c5b7acaff059cc4344c4ab8bc..5b9b8dc10ba95504ee0ddacf14515b50785fd33e 100644 (file)
@@ -31,16 +31,22 @@ public:
   int remove_query(OSDPerfMetricQueryID query_id);
   void remove_all_queries();
 
+  int get_counters(OSDPerfMetricQueryID query_id,
+                   std::map<OSDPerfMetricKey, PerformanceCounters> *counters);
+
   void process_reports(
       const std::map<OSDPerfMetricQuery, OSDPerfMetricReport> &reports);
 
 private:
   typedef std::map<OSDPerfMetricQuery, std::set<OSDPerfMetricQueryID>> Queries;
+  typedef std::map<OSDPerfMetricQueryID,
+                   std::map<OSDPerfMetricKey, PerformanceCounters>> Counters;
 
   Listener &listener;
   mutable Mutex lock;
   OSDPerfMetricQueryID next_query_id = 0;
   Queries queries;
+  Counters counters;
 };
 
 #endif // OSD_PERF_METRIC_COLLECTOR_H_