]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/DaemonState: move PerfCounters classes to separate sources
authorMax Kellermann <max.kellermann@ionos.com>
Thu, 14 Aug 2025 16:41:01 +0000 (18:41 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Wed, 8 Apr 2026 11:26:58 +0000 (13:26 +0200)
To reduce header dependencies.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/mgr/ActivePyModules.cc
src/mgr/CMakeLists.txt
src/mgr/DaemonPerfCounters.cc [new file with mode: 0644]
src/mgr/DaemonPerfCounters.h [new file with mode: 0644]
src/mgr/DaemonState.cc
src/mgr/DaemonState.h
src/mgr/PerfCounterInstance.cc [new file with mode: 0644]
src/mgr/PerfCounterInstance.h [new file with mode: 0644]

index ab5e40898a7c244c9c2bb390447330ba7c0522f9..fcef67daa377c34e42d3963cfcaa4438470facff 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "DaemonKey.h"
 #include "DaemonServer.h"
+#include "PerfCounterInstance.h"
 #include "mgr/MgrContext.h"
 #include "PyFormatter.h"
 // For ::mgr_store_prefix
index ab1722494f7f786134ba7db324164f4a66f8bfb0..abf42bd4efd365172d0aedf469d49b2e9deeb469 100644 (file)
@@ -14,6 +14,7 @@ if(WITH_MGR)
     ClusterState.cc
     DaemonHealthMetricCollector.cc
     DaemonKey.cc
+    DaemonPerfCounters.cc
     DaemonServer.cc
     DaemonState.cc
     Gil.cc
@@ -25,6 +26,7 @@ if(WITH_MGR)
     OSDPerfMetricCollector.cc
     MDSPerfMetricTypes.cc
     MDSPerfMetricCollector.cc
+    PerfCounterInstance.cc
     PyFormatter.cc
     PyUtil.cc
     PyModule.cc
diff --git a/src/mgr/DaemonPerfCounters.cc b/src/mgr/DaemonPerfCounters.cc
new file mode 100644 (file)
index 0000000..6be9614
--- /dev/null
@@ -0,0 +1,86 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2016 John Spray <john.spray@redhat.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ */
+
+#include "DaemonPerfCounters.h"
+#include "PerfCounterInstance.h"
+#include "MgrSession.h"
+#include "common/Clock.h" // for ceph_clock_now()
+#include "common/debug.h"
+#include "messages/MMgrReport.h"
+
+#define dout_context g_ceph_context
+#define dout_subsys ceph_subsys_mgr
+#undef dout_prefix
+#define dout_prefix *_dout << "mgr " << __func__ << " "
+
+DaemonPerfCounters::DaemonPerfCounters(PerfCounterTypes &types_)
+  : types(types_)
+{}
+
+DaemonPerfCounters::~DaemonPerfCounters() noexcept = default;
+
+void DaemonPerfCounters::update(const MMgrReport& report)
+{
+  dout(20) << "loading " << report.declare_types.size() << " new types, "
+          << report.undeclare_types.size() << " old types, had "
+          << types.size() << " types, got "
+           << report.packed.length() << " bytes of data" << dendl;
+
+  // Retrieve session state
+  auto priv = report.get_connection()->get_priv();
+  auto session = static_cast<MgrSession*>(priv.get());
+
+  // Load any newly declared types
+  for (const auto &t : report.declare_types) {
+    types.insert(std::make_pair(t.path, t));
+    session->declared_types.insert(t.path);
+  }
+  // Remove any old types
+  for (const auto &t : report.undeclare_types) {
+    session->declared_types.erase(t);
+  }
+
+  const auto now = ceph_clock_now();
+
+  // Parse packed data according to declared set of types
+  auto p = report.packed.cbegin();
+  DECODE_START(1, p);
+  for (const auto &t_path : session->declared_types) {
+    const auto &t = types.at(t_path);
+    auto instances_it = instances.find(t_path);
+    // Always check the instance exists, as we don't prevent yet
+    // multiple sessions from daemons with the same name, and one
+    // session clearing stats created by another on open.
+    if (instances_it == instances.end()) {
+      instances_it = instances.insert({t_path, t.type}).first;
+    }
+    uint64_t val = 0;
+    uint64_t avgcount = 0;
+    uint64_t avgcount2 = 0;
+
+    decode(val, p);
+    if (t.type & PERFCOUNTER_LONGRUNAVG) {
+      decode(avgcount, p);
+      decode(avgcount2, p);
+      instances_it->second.push_avg(now, val, avgcount);
+    } else {
+      instances_it->second.push(now, val);
+    }
+  }
+  DECODE_FINISH(p);
+}
+
+void DaemonPerfCounters::clear()
+{
+  instances.clear();
+}
diff --git a/src/mgr/DaemonPerfCounters.h b/src/mgr/DaemonPerfCounters.h
new file mode 100644 (file)
index 0000000..d3d19f6
--- /dev/null
@@ -0,0 +1,47 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2016 John Spray <john.spray@redhat.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ */
+
+#ifndef DAEMON_PERF_COUNTERS_H_
+#define DAEMON_PERF_COUNTERS_H_
+
+#include <map>
+#include <string>
+
+namespace ceph {
+  class Formatter;
+}
+
+class MMgrReport;
+class PerfCounterType;
+class PerfCounterInstance;
+
+typedef std::map<std::string, PerfCounterType> PerfCounterTypes;
+
+// Performance counters for one daemon
+class DaemonPerfCounters
+{
+  public:
+  // The record of perf stat types, shared between daemons
+  PerfCounterTypes &types;
+
+  explicit DaemonPerfCounters(PerfCounterTypes &types_);
+  ~DaemonPerfCounters() noexcept;
+
+  std::map<std::string, PerfCounterInstance> instances;
+
+  void update(const MMgrReport& report);
+
+  void clear();
+};
+
+#endif
index 37231285f678eee4780d065050791dc404dede86..965bba4ad424d4f50de5214a5263ac6a03a62e9c 100644 (file)
@@ -378,65 +378,3 @@ void DaemonStateIndex::cull_services(const std::set<std::string>& types_exist)
     _erase(i);
   }
 }
-
-void DaemonPerfCounters::update(const MMgrReport& report)
-{
-  dout(20) << "loading " << report.declare_types.size() << " new types, "
-          << report.undeclare_types.size() << " old types, had "
-          << types.size() << " types, got "
-           << report.packed.length() << " bytes of data" << dendl;
-
-  // Retrieve session state
-  auto priv = report.get_connection()->get_priv();
-  auto session = static_cast<MgrSession*>(priv.get());
-
-  // Load any newly declared types
-  for (const auto &t : report.declare_types) {
-    types.insert(std::make_pair(t.path, t));
-    session->declared_types.insert(t.path);
-  }
-  // Remove any old types
-  for (const auto &t : report.undeclare_types) {
-    session->declared_types.erase(t);
-  }
-
-  const auto now = ceph_clock_now();
-
-  // Parse packed data according to declared set of types
-  auto p = report.packed.cbegin();
-  DECODE_START(1, p);
-  for (const auto &t_path : session->declared_types) {
-    const auto &t = types.at(t_path);
-    auto instances_it = instances.find(t_path);
-    // Always check the instance exists, as we don't prevent yet
-    // multiple sessions from daemons with the same name, and one
-    // session clearing stats created by another on open.
-    if (instances_it == instances.end()) {
-      instances_it = instances.insert({t_path, t.type}).first;
-    }
-    uint64_t val = 0;
-    uint64_t avgcount = 0;
-    uint64_t avgcount2 = 0;
-
-    decode(val, p);
-    if (t.type & PERFCOUNTER_LONGRUNAVG) {
-      decode(avgcount, p);
-      decode(avgcount2, p);
-      instances_it->second.push_avg(now, val, avgcount);
-    } else {
-      instances_it->second.push(now, val);
-    }
-  }
-  DECODE_FINISH(p);
-}
-
-void PerfCounterInstance::push(utime_t t, uint64_t const &v)
-{
-  buffer.push_back({t, v});
-}
-
-void PerfCounterInstance::push_avg(utime_t t, uint64_t const &s,
-                                   uint64_t const &c)
-{
-  avg_buffer.push_back({t, s, c});
-}
index 5f59152522275508e95a1e7c7295840942e2e09f..fca31ac9e6528bd8c09093c8592b174ae6c289ca 100644 (file)
 #include <memory>
 #include <shared_mutex> // for std::shared_lock
 #include <set>
-#include <boost/circular_buffer.hpp>
 
 #include "common/ceph_mutex.h"
-#include "common/perf_counters.h" // for enum perfcounter_type_d
 #include "common/RefCountedObj.h"
 #include "include/utime.h"
 
 
 #include "DaemonHealthMetric.h"
 #include "DaemonKey.h"
+#include "DaemonPerfCounters.h"
 
 namespace ceph {
   class Formatter;
 }
 
-class PerfCounterType;
-class MMgrReport;
-
-// An instance of a performance counter type, within
-// a particular daemon.
-class PerfCounterInstance
-{
-  class DataPoint
-  {
-    public:
-    utime_t t;
-    uint64_t v;
-    DataPoint(utime_t t_, uint64_t v_)
-      : t(t_), v(v_)
-    {}
-  };
-
-  class AvgDataPoint
-  {
-    public:
-    utime_t t;
-    uint64_t s;
-    uint64_t c;
-    AvgDataPoint(utime_t t_, uint64_t s_, uint64_t c_)
-      : t(t_), s(s_), c(c_)
-    {}
-  };
-
-  boost::circular_buffer<DataPoint> buffer;
-  boost::circular_buffer<AvgDataPoint> avg_buffer;
-
-  uint64_t get_current() const;
-
-  public:
-  const boost::circular_buffer<DataPoint> & get_data() const
-  {
-    return buffer;
-  }
-  const DataPoint& get_latest_data() const
-  {
-    return buffer.back();
-  }
-  const boost::circular_buffer<AvgDataPoint> & get_data_avg() const
-  {
-    return avg_buffer;
-  }
-  const AvgDataPoint& get_latest_data_avg() const
-  {
-    return avg_buffer.back();
-  }
-  void push(utime_t t, uint64_t const &v);
-  void push_avg(utime_t t, uint64_t const &s, uint64_t const &c);
-
-  PerfCounterInstance(enum perfcounter_type_d type)
-  {
-    if (type & PERFCOUNTER_LONGRUNAVG)
-      avg_buffer = boost::circular_buffer<AvgDataPoint>(20);
-    else
-      buffer = boost::circular_buffer<DataPoint>(20);
-  };
-};
-
-
-typedef std::map<std::string, PerfCounterType> PerfCounterTypes;
-
-// Performance counters for one daemon
-class DaemonPerfCounters
-{
-  public:
-  // The record of perf stat types, shared between daemons
-  PerfCounterTypes &types;
-
-  explicit DaemonPerfCounters(PerfCounterTypes &types_)
-    : types(types_)
-  {}
-
-  std::map<std::string, PerfCounterInstance> instances;
-
-  void update(const MMgrReport& report);
-
-  void clear()
-  {
-    instances.clear();
-  }
-};
-
 // The state that we store about one daemon
 class DaemonState
 {
diff --git a/src/mgr/PerfCounterInstance.cc b/src/mgr/PerfCounterInstance.cc
new file mode 100644 (file)
index 0000000..97c8933
--- /dev/null
@@ -0,0 +1,25 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2016 John Spray <john.spray@redhat.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ */
+
+#include "PerfCounterInstance.h"
+
+void PerfCounterInstance::push(utime_t t, uint64_t const &v)
+{
+  buffer.push_back({t, v});
+}
+
+void PerfCounterInstance::push_avg(utime_t t, uint64_t const &s,
+                                   uint64_t const &c)
+{
+  avg_buffer.push_back({t, s, c});
+}
diff --git a/src/mgr/PerfCounterInstance.h b/src/mgr/PerfCounterInstance.h
new file mode 100644 (file)
index 0000000..ac225a6
--- /dev/null
@@ -0,0 +1,83 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2016 John Spray <john.spray@redhat.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ */
+
+#ifndef PERF_COUNTER_INSTANCE_H_
+#define PERF_COUNTER_INSTANCE_H_
+
+#include <cstdint>
+
+#include <boost/circular_buffer.hpp>
+
+#include "common/perf_counters.h" // for enum perfcounter_type_d
+#include "include/utime.h"
+
+// An instance of a performance counter type, within
+// a particular daemon.
+class PerfCounterInstance
+{
+  class DataPoint
+  {
+    public:
+    utime_t t;
+    uint64_t v;
+    DataPoint(utime_t t_, uint64_t v_)
+      : t(t_), v(v_)
+    {}
+  };
+
+  class AvgDataPoint
+  {
+    public:
+    utime_t t;
+    uint64_t s;
+    uint64_t c;
+    AvgDataPoint(utime_t t_, uint64_t s_, uint64_t c_)
+      : t(t_), s(s_), c(c_)
+    {}
+  };
+
+  boost::circular_buffer<DataPoint> buffer;
+  boost::circular_buffer<AvgDataPoint> avg_buffer;
+
+  uint64_t get_current() const;
+
+  public:
+  const boost::circular_buffer<DataPoint> & get_data() const
+  {
+    return buffer;
+  }
+  const DataPoint& get_latest_data() const
+  {
+    return buffer.back();
+  }
+  const boost::circular_buffer<AvgDataPoint> & get_data_avg() const
+  {
+    return avg_buffer;
+  }
+  const AvgDataPoint& get_latest_data_avg() const
+  {
+    return avg_buffer.back();
+  }
+  void push(utime_t t, uint64_t const &v);
+  void push_avg(utime_t t, uint64_t const &s, uint64_t const &c);
+
+  PerfCounterInstance(enum perfcounter_type_d type)
+  {
+    if (type & PERFCOUNTER_LONGRUNAVG)
+      avg_buffer = boost::circular_buffer<AvgDataPoint>(20);
+    else
+      buffer = boost::circular_buffer<DataPoint>(20);
+  };
+};
+
+#endif