7 using namespace private_;
9 map<string, event_ctx *> &
10 event_ctx::event_counters()
12 static map<string, event_ctx *> s_counters;
17 event_ctx::event_counters_lock()
19 static spinlock s_lock;
24 event_ctx::stat(counter_data &d)
26 for (size_t i = 0; i < coreid::NMaxCores; i++)
27 d.count_ += counts_[i];
29 d.type_ = counter_data::TYPE_AGG;
31 for (size_t i = 0; i < coreid::NMaxCores; i++) {
32 m = max(m, static_cast<event_ctx_avg *>(this)->highs_[i]);
35 for (size_t i = 0; i < coreid::NMaxCores; i++)
36 s += static_cast<event_ctx_avg *>(this)->sums_[i];
42 map<string, counter_data>
43 event_counter::get_all_counters()
45 map<string, counter_data> ret;
46 const map<string, event_ctx *> &evts = event_ctx::event_counters();
47 spinlock &l = event_ctx::event_counters_lock();
48 lock_guard<spinlock> sl(l);
49 for (auto &p : evts) {
52 if (d.type_ == counter_data::TYPE_AGG)
53 ret[p.first].type_ = counter_data::TYPE_AGG;
60 event_counter::reset_all_counters()
62 const map<string, event_ctx *> &evts = event_ctx::event_counters();
63 spinlock &l = event_ctx::event_counters_lock();
64 lock_guard<spinlock> sl(l);
66 for (size_t i = 0; i < coreid::NMaxCores; i++) {
67 p.second->counts_[i] = 0;
68 if (p.second->avg_tag_) {
69 static_cast<event_ctx_avg *>(p.second)->sums_[i] = 0;
70 static_cast<event_ctx_avg *>(p.second)->highs_[i] = 0;
76 event_counter::stat(const string &name, counter_data &d)
78 const map<string, event_ctx *> &evts = event_ctx::event_counters();
79 spinlock &l = event_ctx::event_counters_lock();
80 event_ctx *ctx = nullptr;
82 lock_guard<spinlock> sl(l);
83 auto it = evts.find(name);
93 #ifdef ENABLE_EVENT_COUNTERS
94 event_counter::event_counter(const string &name)
97 spinlock &l = event_ctx::event_counters_lock();
98 map<string, event_ctx *> &evts = event_ctx::event_counters();
99 lock_guard<spinlock> sl(l);
100 evts[name] = ctx_.obj();
103 event_avg_counter::event_avg_counter(const string &name)
106 spinlock &l = event_ctx::event_counters_lock();
107 map<string, event_ctx *> &evts = event_ctx::event_counters();
108 lock_guard<spinlock> sl(l);
109 evts[name] = ctx_.obj();
112 event_counter::event_counter(const string &name)
116 event_avg_counter::event_avg_counter(const string &name)