2424#pragma once
2525
2626#include < array>
27- #include < optional>
2827#include < unordered_map>
2928#include < tuple>
3029#include < mutex>
@@ -50,8 +49,7 @@ class Metrics
5049 friend class Metrics ;
5150
5251 public:
53- AtomicType () = default ;
54- virtual ~AtomicType () = default ;
52+ AtomicType () = default ;
5553
5654 int64_t
5755 load () const
@@ -113,18 +111,8 @@ class Metrics
113111 // Yes, we don't return objects here, but rather ID's and atomic's directly. Treat
114112 // the std::atomic<int64_t> as the underlying class for a single metric, and be happy.
115113 IdType lookup (const std::string_view name) const ;
116- AtomicType *lookup (IdType id, std::string_view *name = nullptr ) const ;
117-
118- std::optional<AtomicType *>
119- lookupPtr (const std::string_view name) const
120- {
121- IdType id = lookup (name);
122- if (id != NOT_FOUND) {
123- return lookup (id);
124- }
125- return std::nullopt ;
126- }
127-
114+ AtomicType *lookup (const std::string_view name, IdType *out_id) const ;
115+ AtomicType *lookup (IdType id, std::string_view *out_name = nullptr ) const ;
128116 bool rename (IdType id, const std::string_view name);
129117
130118 AtomicType &
@@ -296,6 +284,30 @@ class Metrics
296284 {
297285 };
298286
287+ static IdType
288+ lookup (const std::string_view name)
289+ {
290+ auto &instance = Metrics::instance ();
291+
292+ return instance.lookup (name);
293+ }
294+
295+ static AtomicType *
296+ lookup (const IdType id, std::string_view *out_name = nullptr )
297+ {
298+ auto &instance = Metrics::instance ();
299+
300+ return reinterpret_cast <AtomicType *>(instance.lookup (id, out_name));
301+ }
302+
303+ static AtomicType *
304+ lookup (const std::string_view name, IdType *id)
305+ {
306+ auto &instance = Metrics::instance ();
307+
308+ return reinterpret_cast <AtomicType *>(instance.lookup (name, id));
309+ }
310+
299311 static Metrics::IdType
300312 create (const std::string_view name)
301313 {
@@ -335,7 +347,7 @@ class Metrics
335347 }
336348
337349 static int64_t
338- load (AtomicType *metric)
350+ load (const AtomicType *metric)
339351 {
340352 ink_assert (metric);
341353 return metric->_value .load ();
@@ -360,6 +372,30 @@ class Metrics
360372 {
361373 };
362374
375+ static IdType
376+ lookup (const std::string_view name)
377+ {
378+ auto &instance = Metrics::instance ();
379+
380+ return instance.lookup (name);
381+ }
382+
383+ static AtomicType *
384+ lookup (const IdType id, std::string_view *out_name = nullptr )
385+ {
386+ auto &instance = Metrics::instance ();
387+
388+ return reinterpret_cast <AtomicType *>(instance.lookup (id, out_name));
389+ }
390+
391+ static AtomicType *
392+ lookup (const std::string_view name, IdType *id)
393+ {
394+ auto &instance = Metrics::instance ();
395+
396+ return reinterpret_cast <AtomicType *>(instance.lookup (name, id));
397+ }
398+
363399 static Metrics::IdType
364400 create (const std::string_view name)
365401 {
@@ -392,7 +428,7 @@ class Metrics
392428 }
393429
394430 static int64_t
395- load (AtomicType *metric)
431+ load (const AtomicType *metric)
396432 {
397433 ink_assert (metric);
398434 return metric->_value .load ();
0 commit comments