CMS 3D CMS Logo

HistogrammingAllocMonitor.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PerfTools/AllocMonitor
4 // Class : HistogrammingAllocMonitor
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Christopher Jones
10 // Created: Mon, 21 Aug 2023 20:31:57 GMT
11 //
12 
13 // system include files
14 #include <atomic>
15 
16 // user include files
22 
23 namespace {
24  class MonitorAdaptor : public cms::perftools::AllocMonitorBase {
25  public:
26  void allocCalled(size_t iRequested, size_t iActual, void const*) final {
27  auto& a = allocRequested_[bin(iRequested)];
28  a.fetch_add(1, std::memory_order_acq_rel);
29 
30  auto& u = allocUsed_[bin(iActual)];
31  u.fetch_add(1, std::memory_order_acq_rel);
32  }
33  void deallocCalled(size_t iActual, void const*) final {
34  auto& u = deallocUsed_[bin(iActual)];
35  u.fetch_add(1, std::memory_order_acq_rel);
36  }
37 
38  void performanceReport() const {
39  auto log = edm::LogSystem("HistogrammingAllocMonitor");
40  log << "Memory Histogram"
41  << "\n size | allocated | deallocated"
42  << "\n | requested used | used";
43  size_t size = 0;
44  for (unsigned int i = 0; i < allocRequested_.size(); ++i) {
45  log << "\n"
46  << std::setw(12) << size << " " << std::setw(12) << allocRequested_[i] << " " << std::setw(12)
47  << allocUsed_[i] << " " << std::setw(12) << deallocUsed_[i];
48  if (size == 0) {
49  size = 1;
50  } else {
51  size *= 2;
52  }
53  }
54  }
55 
56  private:
57  static size_t bin(size_t iValue) {
58  size_t i = 0;
59 
60  while (iValue != 0) {
61  ++i;
62  iValue /= 2;
63  }
64  return i;
65  };
66 
67  std::array<std::atomic<size_t>, 40> allocRequested_;
68  std::array<std::atomic<size_t>, 40> allocUsed_;
69  std::array<std::atomic<size_t>, 40> deallocUsed_;
70  };
71 
72 } // namespace
73 
75 public:
77  : adaptor_(cms::perftools::AllocMonitorRegistry::instance().createAndRegisterMonitor<MonitorAdaptor>()) {}
78 
80  adaptor_->performanceReport();
82  }
83 
84  MonitorAdaptor* adaptor_;
85 };
86 
size
Write out results.
Log< level::System, false > LogSystem
#define DEFINE_FWK_SERVICE_MAKER(concrete, maker)
Definition: ServiceMaker.h:102
static PFTauRenderPlugin instance
virtual void allocCalled(size_t iRequestedSize, size_t iActualSize, void const *iAddress)=0
static AllocMonitorRegistry & instance()
Namespace of DDCMS conversion namespace.
virtual void deallocCalled(size_t iActualSize, void const *iAddress)=0
double a
Definition: hdecay.h:121