Browse Source

Add auto-detection of platform integer size in prometheus

Joseph Henry 5 months ago
parent
commit
6b113c8270

+ 12 - 1
ext/prometheus-cpp-lite-1.0/core/include/prometheus/counter.h

@@ -25,7 +25,18 @@ namespace prometheus {
   ///
   ///
   /// The class is thread-safe. No concurrent call to any API of this type causes
   /// The class is thread-safe. No concurrent call to any API of this type causes
   /// a data race.
   /// a data race.
-  template <typename Value_ = uint64_t>
+
+#include <stdint.h>
+
+#if UINTPTR_MAX == 0xffFFffFF
+// 32-bit platform
+template <typename Value_ = uint32_t>
+#elif UINTPTR_MAX == 0xffFFffFFffFFffFF
+// 64-bit platform
+template <typename Value_ = uint64_t>
+#else
+#error Unknown platform - does not look either like 32-bit or 64-bit
+#endif
   class Counter : public Metric {
   class Counter : public Metric {
 
 
     std::atomic<Value_> value{ 0 };
     std::atomic<Value_> value{ 0 };

+ 10 - 0
ext/prometheus-cpp-lite-1.0/core/include/prometheus/gauge.h

@@ -23,7 +23,17 @@ namespace prometheus {
   ///
   ///
   /// The class is thread-safe. No concurrent call to any API of this type causes
   /// The class is thread-safe. No concurrent call to any API of this type causes
   /// a data race.
   /// a data race.
+  #include <stdint.h>
+
+  #if UINTPTR_MAX == 0xffFFffFF
+  // 32-bit
+  template <typename Value_ = uint32_t>
+  #elif UINTPTR_MAX == 0xffFFffFFffFFffFF
+  // 64-bit
   template <typename Value_ = uint64_t>
   template <typename Value_ = uint64_t>
+  #else
+  #error Unknown platform - does not look either like 32-bit or 64-bit
+  #endif
   class Gauge : public Metric {
   class Gauge : public Metric {
 
 
     std::atomic<Value_> value { 0 };
     std::atomic<Value_> value { 0 };

+ 13 - 2
ext/prometheus-cpp-lite-1.0/simpleapi/include/prometheus/simpleapi.h

@@ -15,6 +15,17 @@
 #include <memory>
 #include <memory>
 #include <functional>
 #include <functional>
 #include <stdexcept>
 #include <stdexcept>
+#include <stdint.h>
+
+#if UINTPTR_MAX == 0xffFFffFF
+// 32-bit
+typedef uint32_tmetric_size;
+#elif UINTPTR_MAX == 0xffFFffFFffFFffFF
+// 64-bit
+typedef uint64_t metric_size;
+#else
+#error Unknown platform - does not look either like 32-bit or 64-bit
+#endif
 
 
 namespace prometheus {
 namespace prometheus {
   namespace simpleapi {
   namespace simpleapi {
@@ -46,7 +57,7 @@ namespace prometheus {
 
 
     public:
     public:
 
 
-      using Metric = Counter<uint64_t>;
+      using Metric = Counter<metric_size>;
       using Family = Metric::Family;
       using Family = Metric::Family;
 
 
     private:
     private:
@@ -82,7 +93,7 @@ namespace prometheus {
 
 
     public:
     public:
 
 
-      using Metric = Gauge<int64_t>;
+      using Metric = Gauge<metric_size>;
       using Family = Metric::Family;
       using Family = Metric::Family;
 
 
     private:
     private: