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
The following commit(s) were added to refs/heads/NewAPIMetricsPOC by this push:
new f872b88d77 fix cmake and const pass
f872b88d77 is described below
commit f872b88d77373c21b297e7952c5785a640a95422
Author: Chris McFarlen <[email protected]>
AuthorDate: Fri Jul 7 09:59:51 2023 -0500
fix cmake and const pass
---
include/api/Metrics.h | 16 ++++++++--------
src/api/CMakeLists.txt | 2 +-
src/api/Metrics.cc | 4 ++--
src/api/test_Metrics.cc | 2 +-
4 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/include/api/Metrics.h b/include/api/Metrics.h
index 35f573bc8b..e85f30033e 100644
--- a/include/api/Metrics.h
+++ b/include/api/Metrics.h
@@ -45,8 +45,8 @@ private:
public:
static constexpr uint16_t METRICS_MAX_BLOBS = 8192;
- static constexpr uint16_t METRICS_MAX_SIZE = 2048; // For a total of
16M metrics
- static constexpr IdType NOT_FOUND = INT32_MIN; // <16-bit,16-bit>
= <blob-index,offset>
+ static constexpr uint16_t METRICS_MAX_SIZE = 2048;
// For a total of 16M metrics
+ static constexpr IdType NOT_FOUND =
std::numeric_limits<IdType>::min(); // <16-bit,16-bit> = <blob-index,offset>
private:
using NameAndId = std::tuple<std::string, IdType>;
@@ -79,7 +79,7 @@ public:
// ID in the containers is very small and sufficient to work with. But
agreed, it's not
// very C++-like (but compatible with old librecords ATS code!).
IdType newMetric(const std::string_view name);
- IdType lookup(const std::string_view name);
+ IdType lookup(const std::string_view name) const;
AtomicType *lookup(IdType id) const;
AtomicType &
@@ -89,7 +89,7 @@ public:
}
IdType
- operator[](const std::string_view name)
+ operator[](const std::string_view name) const
{
return lookup(name);
}
@@ -132,12 +132,12 @@ public:
bool
valid(IdType id) const
{
- std::tuple<uint16_t, uint16_t> idx = _splitID(id);
+ auto [blob, entry] = _splitID(id);
- return (id >= 0 && std::get<0>(idx) <= _cur_blob && std::get<1>(idx) <
METRICS_MAX_SIZE);
+ return (id >= 0 && blob <= _cur_blob && entry < METRICS_MAX_SIZE);
}
- void recordsDump(RecDumpEntryCb callback, void *edata);
+ void recordsDump(RecDumpEntryCb callback, void *edata) const;
private:
static constexpr std::tuple<uint16_t, uint16_t>
@@ -148,7 +148,7 @@ private:
void _addBlob();
- std::mutex _mutex;
+ mutable std::mutex _mutex;
LookupTable _lookups;
MetricBlobs _blobs;
uint16_t _cur_blob = 0;
diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt
index 718d9eda5c..b0f0bbc5d2 100644
--- a/src/api/CMakeLists.txt
+++ b/src/api/CMakeLists.txt
@@ -15,7 +15,7 @@
#
#######################
-add_library(tsapi STATIC Metrics.cc)
+add_library(tsapi SHARED Metrics.cc)
add_executable(test_Metrics
test_Metrics.cc
diff --git a/src/api/Metrics.cc b/src/api/Metrics.cc
index 7135ba94f8..44bbb94657 100644
--- a/src/api/Metrics.cc
+++ b/src/api/Metrics.cc
@@ -75,7 +75,7 @@ Metrics::newMetric(std::string_view name)
}
Metrics::IdType
-Metrics::lookup(const std::string_view name)
+Metrics::lookup(const std::string_view name) const
{
std::lock_guard<std::mutex> lock(_mutex);
auto it = _lookups.find(name);
@@ -106,7 +106,7 @@ Metrics::lookup(IdType id) const
// way exposing iterators over the Metrics. That avoids this ugly dependency
// between librecords and this code.
void
-Metrics::recordsDump(RecDumpEntryCb callback, void *edata)
+Metrics::recordsDump(RecDumpEntryCb callback, void *edata) const
{
int16_t off_max = METRICS_MAX_SIZE;
diff --git a/src/api/test_Metrics.cc b/src/api/test_Metrics.cc
index 83f7d4df80..0c28f91fb3 100644
--- a/src/api/test_Metrics.cc
+++ b/src/api/test_Metrics.cc
@@ -32,7 +32,7 @@ TEST_CASE("Metrics", "[libtsapi][Metrics]")
auto fooid = m.newMetric("foo");
- REQUIRE(fooid == 0);
+ REQUIRE(fooid == 1);
m.increment(fooid);