| 30 | DaemonPerfCounters::~DaemonPerfCounters() noexcept = default; |
| 31 | |
| 32 | void DaemonPerfCounters::update(const MMgrReport& report) |
| 33 | { |
| 34 | dout(20) << "loading " << report.declare_types.size() << " new types, " |
| 35 | << report.undeclare_types.size() << " old types, had " |
| 36 | << types.size() << " types, got " |
| 37 | << report.packed.length() << " bytes of data" << dendl; |
| 38 | |
| 39 | // Retrieve session state |
| 40 | auto priv = report.get_connection()->get_priv(); |
| 41 | auto session = static_cast<MgrSession*>(priv.get()); |
| 42 | |
| 43 | // Load any newly declared types |
| 44 | for (const auto &t : report.declare_types) { |
| 45 | types.insert(std::make_pair(t.path, t)); |
| 46 | session->declared_types.insert(t.path); |
| 47 | } |
| 48 | // Remove any old types |
| 49 | for (const auto &t : report.undeclare_types) { |
| 50 | session->declared_types.erase(t); |
| 51 | } |
| 52 | |
| 53 | const auto now = ceph_clock_now(); |
| 54 | |
| 55 | // Parse packed data according to declared set of types |
| 56 | auto p = report.packed.cbegin(); |
| 57 | DECODE_START(1, p); |
| 58 | for (const auto &t_path : session->declared_types) { |
| 59 | const auto &t = types.at(t_path); |
| 60 | auto instances_it = instances.find(t_path); |
| 61 | // Always check the instance exists, as we don't prevent yet |
| 62 | // multiple sessions from daemons with the same name, and one |
| 63 | // session clearing stats created by another on open. |
| 64 | if (instances_it == instances.end()) { |
| 65 | instances_it = instances.insert({t_path, t.type}).first; |
| 66 | } |
| 67 | uint64_t val = 0; |
| 68 | uint64_t avgcount = 0; |
| 69 | uint64_t avgcount2 = 0; |
| 70 | |
| 71 | decode(val, p); |
| 72 | if (t.type & PERFCOUNTER_LONGRUNAVG) { |
| 73 | decode(avgcount, p); |
| 74 | decode(avgcount2, p); |
| 75 | instances_it->second.push_avg(now, val, avgcount); |
| 76 | } else { |
| 77 | instances_it->second.push(now, val); |
| 78 | } |
| 79 | } |
| 80 | DECODE_FINISH(p); |
| 81 | } |
| 82 | |
| 83 | void DaemonPerfCounters::clear() |
| 84 | { |