This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch NewAPIMetricsPOC in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 2017e8d984a46dd302237754b6a8a91f9e2362cb Author: Leif Hedstrom <zw...@apache.org> AuthorDate: Thu Jul 6 15:05:09 2023 -0600 Move the dumper, fix valid() --- include/api/Metrics.h | 34 ++-------------------------------- src/api/Metrics.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/include/api/Metrics.h b/include/api/Metrics.h index f343c0d786..0ab82324b8 100644 --- a/include/api/Metrics.h +++ b/include/api/Metrics.h @@ -113,40 +113,10 @@ public: { std::tuple<uint16_t, uint16_t> idx = _splitID(id); - return (id >= 0 && std::get<0>(idx) < _cur_blob && std::get<1>(idx) < METRICS_MAX_SIZE); + return (id >= 0 && std::get<0>(idx) <= _cur_blob && std::get<1>(idx) < METRICS_MAX_SIZE); } - void - recordsDump(RecDumpEntryCb callback, void *edata) - { - return; - int16_t blob_ix, off_ix; - int16_t off_max = METRICS_MAX_SIZE; - - { - std::lock_guard<std::mutex> lock(_mutex); - - // Capture these while protected, in case the blobs change - blob_ix = _cur_blob; - off_ix = _cur_off; - } - - for (int i = 0; i <= blob_ix; ++i) { - auto blob = _blobs[i]; - auto &names = std::get<0>(*blob); - auto &metrics = std::get<1>(*blob); - RecData datum; - - if (i == blob_ix) { - off_max = off_ix; - } - for (int j = 0; j < off_max; ++j) { - datum.rec_int = metrics[j].load(); - // ToDo: The recordtype here is fine for now, but we should probably make this generic - callback(RECT_PLUGIN, edata, 1, std::get<0>(names[i]).c_str(), TS_RECORDDATATYPE_INT, &datum); - } - } - } + void recordsDump(RecDumpEntryCb callback, void *edata); private: static constexpr std::tuple<uint16_t, uint16_t> diff --git a/src/api/Metrics.cc b/src/api/Metrics.cc index b2d04d31df..c87239b61a 100644 --- a/src/api/Metrics.cc +++ b/src/api/Metrics.cc @@ -97,4 +97,35 @@ Metrics::lookup(IdType id) const return &(atomics[std::get<1>(idx)]); } +void +Metrics::recordsDump(RecDumpEntryCb callback, void *edata) +{ + int16_t blob_ix, off_ix; + int16_t off_max = METRICS_MAX_SIZE; + + { + std::lock_guard<std::mutex> lock(_mutex); + + // Capture these while protected, in case the blobs change + blob_ix = _cur_blob; + off_ix = _cur_off; + } + + for (int i = 0; i <= blob_ix; ++i) { + auto blob = _blobs[i]; + auto &names = std::get<0>(*blob); + auto &metrics = std::get<1>(*blob); + RecData datum; + + if (i == blob_ix) { + off_max = off_ix; + } + for (int j = 0; j < off_max; ++j) { + datum.rec_int = metrics[j].load(); + // ToDo: The recordtype here is fine for now, but we should probably make this generic + callback(RECT_PLUGIN, edata, 1, std::get<0>(names[i]).c_str(), TS_RECORDDATATYPE_INT, &datum); + } + } +} + } // namespace ts