To reduce header dependencies.
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
#include "DaemonKey.h"
#include "DaemonServer.h"
+#include "PerfCounterInstance.h"
#include "mgr/MgrContext.h"
#include "PyFormatter.h"
// For ::mgr_store_prefix
ClusterState.cc
DaemonHealthMetricCollector.cc
DaemonKey.cc
+ DaemonPerfCounters.cc
DaemonServer.cc
DaemonState.cc
Gil.cc
OSDPerfMetricCollector.cc
MDSPerfMetricTypes.cc
MDSPerfMetricCollector.cc
+ PerfCounterInstance.cc
PyFormatter.cc
PyUtil.cc
PyModule.cc
--- /dev/null
+// -*- 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();
+}
--- /dev/null
+// -*- 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
_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});
-}
#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
{
--- /dev/null
+// -*- 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});
+}
--- /dev/null
+// -*- 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