From: Max Kellermann Date: Thu, 14 Aug 2025 16:41:01 +0000 (+0200) Subject: mgr/DaemonState: move PerfCounters classes to separate sources X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=35f6dd06dd0b3c78235e21ac309e4226aa733af1;p=ceph.git mgr/DaemonState: move PerfCounters classes to separate sources To reduce header dependencies. Signed-off-by: Max Kellermann --- diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index ab5e40898a7c..fcef67daa377 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -35,6 +35,7 @@ #include "DaemonKey.h" #include "DaemonServer.h" +#include "PerfCounterInstance.h" #include "mgr/MgrContext.h" #include "PyFormatter.h" // For ::mgr_store_prefix diff --git a/src/mgr/CMakeLists.txt b/src/mgr/CMakeLists.txt index ab1722494f7f..abf42bd4efd3 100644 --- a/src/mgr/CMakeLists.txt +++ b/src/mgr/CMakeLists.txt @@ -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 index 000000000000..6be96141e33c --- /dev/null +++ b/src/mgr/DaemonPerfCounters.cc @@ -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 + * + * 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(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 index 000000000000..d3d19f602781 --- /dev/null +++ b/src/mgr/DaemonPerfCounters.h @@ -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 + * + * 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 +#include + +namespace ceph { + class Formatter; +} + +class MMgrReport; +class PerfCounterType; +class PerfCounterInstance; + +typedef std::map 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 instances; + + void update(const MMgrReport& report); + + void clear(); +}; + +#endif diff --git a/src/mgr/DaemonState.cc b/src/mgr/DaemonState.cc index 37231285f678..965bba4ad424 100644 --- a/src/mgr/DaemonState.cc +++ b/src/mgr/DaemonState.cc @@ -378,65 +378,3 @@ void DaemonStateIndex::cull_services(const std::set& 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(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}); -} diff --git a/src/mgr/DaemonState.h b/src/mgr/DaemonState.h index 5f5915252227..fca31ac9e652 100644 --- a/src/mgr/DaemonState.h +++ b/src/mgr/DaemonState.h @@ -21,10 +21,8 @@ #include #include // for std::shared_lock #include -#include #include "common/ceph_mutex.h" -#include "common/perf_counters.h" // for enum perfcounter_type_d #include "common/RefCountedObj.h" #include "include/utime.h" @@ -32,97 +30,12 @@ #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 buffer; - boost::circular_buffer avg_buffer; - - uint64_t get_current() const; - - public: - const boost::circular_buffer & get_data() const - { - return buffer; - } - const DataPoint& get_latest_data() const - { - return buffer.back(); - } - const boost::circular_buffer & 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(20); - else - buffer = boost::circular_buffer(20); - }; -}; - - -typedef std::map 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 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 index 000000000000..97c89330f2f4 --- /dev/null +++ b/src/mgr/PerfCounterInstance.cc @@ -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 + * + * 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 index 000000000000..ac225a627889 --- /dev/null +++ b/src/mgr/PerfCounterInstance.h @@ -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 + * + * 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 + +#include + +#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 buffer; + boost::circular_buffer avg_buffer; + + uint64_t get_current() const; + + public: + const boost::circular_buffer & get_data() const + { + return buffer; + } + const DataPoint& get_latest_data() const + { + return buffer.back(); + } + const boost::circular_buffer & 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(20); + else + buffer = boost::circular_buffer(20); + }; +}; + +#endif