summaryrefslogtreecommitdiffstats
path: root/src/common/perf_counters_collection.h
blob: 53a8f34120e3d5006a37e955c2267a238361eb1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#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>;