options.cc
page.cc
perf_counters.cc
+ perf_counters_collection.cc
perf_histogram.cc
pick_address.cc
reverse.c
*/
#include "common/Mutex.h"
-#include "common/perf_counters.h"
#include "common/config.h"
#include "common/Clock.h"
#include "common/valgrind.h"
#include "common/ThrottleInterface.h"
#include "common/Timer.h"
#include "common/convenience.h"
-#include "common/perf_counters.h"
+#include "common/perf_counters_collection.h"
/**
* @class Throttle
*
*/
+#include "common/ceph_context.h"
+
#include <mutex>
#include <iostream>
#include "include/mempool.h"
#include "common/admin_socket.h"
-#include "common/perf_counters.h"
#include "common/code_environment.h"
#include "common/Cond.h"
#include "common/config.h"
#include "common/config_proxy.h"
#include "include/spinlock.h"
#endif
+#include "common/perf_counters_collection.h"
#include "crush/CrushLocation.h"
class AdminSocket;
class CephContextServiceThread;
-class PerfCountersCollection;
-class PerfCounters;
class CephContextHook;
class CephContextObs;
class CryptoHandler;
CryptoRandom* random() const;
PerfCountersCollection* get_perfcounters_collection();
ceph::common::ConfigProxy& _conf;
-
CephContext* get();
void put();
private:
using std::ostringstream;
-PerfCountersCollection::PerfCountersCollection(CephContext *cct)
- : m_cct(cct),
- m_lock("PerfCountersCollection")
+PerfCountersCollectionImpl::PerfCountersCollectionImpl()
{
}
-PerfCountersCollection::~PerfCountersCollection()
+PerfCountersCollectionImpl::~PerfCountersCollectionImpl()
{
clear();
}
-void PerfCountersCollection::add(class PerfCounters *l)
+void PerfCountersCollectionImpl::add(PerfCounters *l)
{
- std::lock_guard<Mutex> lck(m_lock);
-
// make sure the name is unique
perf_counters_set_t::iterator i;
i = m_loggers.find(l);
}
}
-void PerfCountersCollection::remove(class PerfCounters *l)
+void PerfCountersCollectionImpl::remove(PerfCounters *l)
{
- std::lock_guard<Mutex> lck(m_lock);
-
for (unsigned int i = 0; i < l->m_data.size(); ++i) {
PerfCounters::perf_counter_data_any_d &data = l->m_data[i];
m_loggers.erase(i);
}
-void PerfCountersCollection::clear()
+void PerfCountersCollectionImpl::clear()
{
- std::lock_guard<Mutex> lck(m_lock);
perf_counters_set_t::iterator i = m_loggers.begin();
perf_counters_set_t::iterator i_end = m_loggers.end();
for (; i != i_end; ) {
+ delete *i;
m_loggers.erase(i++);
}
by_path.clear();
}
-bool PerfCountersCollection::reset(const std::string &name)
+bool PerfCountersCollectionImpl::reset(const std::string &name)
{
bool result = false;
- std::lock_guard<Mutex> lck(m_lock);
perf_counters_set_t::iterator i = m_loggers.begin();
perf_counters_set_t::iterator i_end = m_loggers.end();
* @param histograms if true, dump histogram values,
* if false dump all non-histogram counters
*/
-void PerfCountersCollection::dump_formatted_generic(
+void PerfCountersCollectionImpl::dump_formatted_generic(
Formatter *f,
bool schema,
bool histograms,
const std::string &logger,
const std::string &counter)
{
- std::lock_guard<Mutex> lck(m_lock);
f->open_object_section("perfcounter_collection");
for (perf_counters_set_t::iterator l = m_loggers.begin();
f->close_section();
}
-void PerfCountersCollection::with_counters(std::function<void(
- const PerfCountersCollection::CounterMap &)> fn) const
+void PerfCountersCollectionImpl::with_counters(std::function<void(
+ const PerfCountersCollectionImpl::CounterMap &)> fn) const
{
- std::lock_guard<Mutex> lck(m_lock);
-
fn(by_path);
}
void PerfCounters::inc(int idx, uint64_t amt)
{
+#ifndef WITH_SEASTAR
if (!m_cct->_conf->perf)
return;
+#endif
ceph_assert(idx > m_lower_bound);
ceph_assert(idx < m_upper_bound);
void PerfCounters::dec(int idx, uint64_t amt)
{
+#ifndef WITH_SEASTAR
if (!m_cct->_conf->perf)
return;
+#endif
ceph_assert(idx > m_lower_bound);
ceph_assert(idx < m_upper_bound);
void PerfCounters::set(int idx, uint64_t amt)
{
+#ifndef WITH_SEASTAR
if (!m_cct->_conf->perf)
return;
+#endif
ceph_assert(idx > m_lower_bound);
ceph_assert(idx < m_upper_bound);
uint64_t PerfCounters::get(int idx) const
{
+#ifndef WITH_SEASTAR
if (!m_cct->_conf->perf)
return 0;
+#endif
ceph_assert(idx > m_lower_bound);
ceph_assert(idx < m_upper_bound);
void PerfCounters::tinc(int idx, utime_t amt)
{
+#ifndef WITH_SEASTAR
if (!m_cct->_conf->perf)
return;
+#endif
ceph_assert(idx > m_lower_bound);
ceph_assert(idx < m_upper_bound);
void PerfCounters::tinc(int idx, ceph::timespan amt)
{
+#ifndef WITH_SEASTAR
if (!m_cct->_conf->perf)
return;
+#endif
ceph_assert(idx > m_lower_bound);
ceph_assert(idx < m_upper_bound);
void PerfCounters::tset(int idx, utime_t amt)
{
+#ifndef WITH_SEASTAR
if (!m_cct->_conf->perf)
return;
+#endif
ceph_assert(idx > m_lower_bound);
ceph_assert(idx < m_upper_bound);
utime_t PerfCounters::tget(int idx) const
{
+#ifndef WITH_SEASTAR
if (!m_cct->_conf->perf)
return utime_t();
+#endif
ceph_assert(idx > m_lower_bound);
ceph_assert(idx < m_upper_bound);
void PerfCounters::hinc(int idx, int64_t x, int64_t y)
{
+#ifndef WITH_SEASTAR
if (!m_cct->_conf->perf)
return;
+#endif
ceph_assert(idx > m_lower_bound);
ceph_assert(idx < m_upper_bound);
pair<uint64_t, uint64_t> PerfCounters::get_tavg_ns(int idx) const
{
+#ifndef WITH_SEASTAR
if (!m_cct->_conf->perf)
return make_pair(0, 0);
+#endif
ceph_assert(idx > m_lower_bound);
ceph_assert(idx < m_upper_bound);
: m_cct(cct),
m_lower_bound(lower_bound),
m_upper_bound(upper_bound),
+#ifndef WITH_SEASTAR
m_name(name.c_str()),
m_lock_name(std::string("PerfCounters::") + name.c_str()),
- m_lock(m_lock_name.c_str())
+ m_lock(ceph::make_mutex(m_lock_name))
+#else
+ m_name(name.c_str())
+#endif
{
m_data.resize(upper_bound - lower_bound - 1);
}
#include "common/perf_histogram.h"
#include "include/utime.h"
-#include "common/Mutex.h"
-#include "common/ceph_context.h"
+#include "common/ceph_mutex.h"
#include "common/ceph_time.h"
class CephContext;
class PerfCountersBuilder;
+class PerfCounters;
enum perfcounter_type_d : uint8_t
{
int m_lower_bound;
int m_upper_bound;
std::string m_name;
+#ifndef WITH_SEASTAR
const std::string m_lock_name;
+#endif
int prio_adjust = 0;
+#ifndef WITH_SEASTAR
/** Protects m_data */
- mutable Mutex m_lock;
+ ceph::mutex m_lock;
+#endif
perf_counter_data_vec_t m_data;
friend class PerfCountersBuilder;
- friend class PerfCountersCollection;
+ friend class PerfCountersCollectionImpl;
};
class SortPerfCountersByName {
typedef std::set <PerfCounters*, SortPerfCountersByName> perf_counters_set_t;
/*
- * PerfCountersCollection manages PerfCounters objects for a Ceph process.
+ * PerfCountersCollectionImp manages PerfCounters objects for a Ceph process.
*/
-class PerfCountersCollection
+class PerfCountersCollectionImpl
{
public:
- PerfCountersCollection(CephContext *cct);
- ~PerfCountersCollection();
- void add(class PerfCounters *l);
- void remove(class PerfCounters *l);
+ PerfCountersCollectionImpl();
+ ~PerfCountersCollectionImpl();
+ void add(PerfCounters *l);
+ void remove(PerfCounters *l);
void clear();
bool reset(const std::string &name);
const std::string &logger = "",
const std::string &counter = "");
- CephContext *m_cct;
-
- /** Protects m_loggers */
- mutable Mutex m_lock;
-
perf_counters_set_t m_loggers;
CounterMap by_path;
-
- friend class PerfCountersCollectionTest;
};
};
-class PerfCountersDeleter {
- CephContext* cct;
-
-public:
- PerfCountersDeleter() noexcept : cct(nullptr) {}
- PerfCountersDeleter(CephContext* cct) noexcept : cct(cct) {}
- void operator()(PerfCounters* p) noexcept {
- if (cct)
- cct->get_perfcounters_collection()->remove(p);
- delete p;
- }
-};
-
-using PerfCountersRef = std::unique_ptr<PerfCounters, PerfCountersDeleter>;
-
#endif
--- /dev/null
+#include "common/perf_counters_collection.h"
+#include "common/ceph_mutex.h"
+#include "common/ceph_context.h"
+
+/* PerfcounterCollection hold the lock for PerfCounterCollectionImp */
+PerfCountersCollection::PerfCountersCollection(CephContext *cct)
+ : m_cct(cct),
+ m_lock(ceph::make_mutex("PerfCountersCollection"))
+{
+}
+PerfCountersCollection::~PerfCountersCollection()
+{
+ clear();
+}
+void PerfCountersCollection::add(PerfCounters *l)
+{
+ std::lock_guard lck(m_lock);
+ perf_impl.add(l);
+}
+void PerfCountersCollection::remove(PerfCounters *l)
+{
+ std::lock_guard lck(m_lock);
+ perf_impl.remove(l);
+}
+void PerfCountersCollection::clear()
+{
+ std::lock_guard lck(m_lock);
+ perf_impl.clear();
+}
+bool PerfCountersCollection::reset(const std::string &name)
+{
+ std::lock_guard lck(m_lock);
+ return perf_impl.reset(name);
+}
+void PerfCountersCollection::dump_formatted(ceph::Formatter *f, bool schema,
+ const std::string &logger,
+ const std::string &counter)
+{
+ std::lock_guard lck(m_lock);
+ perf_impl.dump_formatted(f,schema,logger,counter);
+}
+void PerfCountersCollection::dump_formatted_histograms(ceph::Formatter *f, bool schema,
+ const std::string &logger,
+ const std::string &counter)
+{
+ std::lock_guard lck(m_lock);
+ perf_impl.dump_formatted_histograms(f,schema,logger,counter);
+}
+void PerfCountersCollection::with_counters(std::function<void(const PerfCountersCollectionImpl::CounterMap &)> fn) const
+{
+ std::lock_guard lck(m_lock);
+ perf_impl.with_counters(fn);
+}
+void PerfCountersDeleter::operator()(PerfCounters* p) noexcept
+{
+ if (cct)
+ cct->get_perfcounters_collection()->remove(p);
+ delete p;
+}
+
--- /dev/null
+#pragma once
+
+#include "common/perf_counters.h"
+#include "common/ceph_mutex.h"
+
+class CephContext;
+
+class PerfCountersCollection
+{
+ CephContext *m_cct;
+
+ /** Protects perf_impl->m_loggers */
+ mutable ceph::mutex m_lock;
+ PerfCountersCollectionImpl perf_impl;
+public:
+ PerfCountersCollection(CephContext *cct);
+ ~PerfCountersCollection();
+ void add(PerfCounters *l);
+ void remove(PerfCounters *l);
+ void clear();
+ bool reset(const std::string &name);
+
+ void dump_formatted(ceph::Formatter *f, bool schema,
+ const std::string &logger = "",
+ const std::string &counter = "");
+ void dump_formatted_histograms(ceph::Formatter *f, bool schema,
+ const std::string &logger = "",
+ const std::string &counter = "");
+
+ void with_counters(std::function<void(const PerfCountersCollectionImpl::CounterMap &)>) const;
+
+ friend class PerfCountersCollectionTest;
+};
+
+class PerfCountersDeleter {
+ CephContext* cct;
+
+public:
+ PerfCountersDeleter() noexcept : cct(nullptr) {}
+ PerfCountersDeleter(CephContext* cct) noexcept : cct(cct) {}
+ void operator()(PerfCounters* p) noexcept;
+};
+
+using PerfCountersRef = std::unique_ptr<PerfCounters, PerfCountersDeleter>;
+
+
auto pcc = cct->get_perfcounters_collection();
pcc->with_counters([this, report](
- const PerfCountersCollection::CounterMap &by_path)
+ const PerfCountersCollectionImpl::CounterMap &by_path)
{
// Helper for checking whether a counter should be included
auto include_counter = [this](
// now, this include has to come before the others.
-#include "common/perf_counters.h"
+#include "common/perf_counters_collection.h"
#include "common/admin_socket_client.h"
#include "common/ceph_context.h"
#include "common/config.h"