summaryrefslogtreecommitdiff
path: root/src/lib/metrics/metrics_common.h
diff options
context:
space:
mode:
authorGabriela Moldovan <gabi@torproject.org>2023-03-08 17:51:58 +0000
committerDavid Goulet <dgoulet@torproject.org>2023-03-13 11:18:40 -0400
commitd1264d11c3320b8a28c3715acca8a8ace1d70569 (patch)
tree60f7969f01e8ec541ae2308cb709f088acf4ccf5 /src/lib/metrics/metrics_common.h
parent3fa08dc9a7041b82fd100d2fc30331c534723e17 (diff)
downloadtor-d1264d11c3320b8a28c3715acca8a8ace1d70569.tar.gz
tor-d1264d11c3320b8a28c3715acca8a8ace1d70569.zip
metrics: Add support for histograms.
This will enable us to add e.g. circuit build metrics (#40717). Signed-off-by: Gabriela Moldovan <gabi@torproject.org>
Diffstat (limited to 'src/lib/metrics/metrics_common.h')
-rw-r--r--src/lib/metrics/metrics_common.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/metrics/metrics_common.h b/src/lib/metrics/metrics_common.h
index 3644ad3d50..6c8e8bdbdc 100644
--- a/src/lib/metrics/metrics_common.h
+++ b/src/lib/metrics/metrics_common.h
@@ -10,6 +10,7 @@
#define TOR_LIB_METRICS_METRICS_COMMON_H
#include "lib/cc/torint.h"
+#include "lib/container/smartlist.h"
/** Helper macro that must be used to construct the right namespaced metrics
* name. A name is a string so stringify the result. */
@@ -28,8 +29,18 @@ typedef enum {
METRICS_TYPE_COUNTER,
/* Can go up or down. */
METRICS_TYPE_GAUGE,
+ /* Cumulative counters for multiple observation buckets. */
+ METRICS_TYPE_HISTOGRAM,
} metrics_type_t;
+typedef struct metrics_histogram_bucket_t {
+ /* The value of the counter of this bucket. */
+ uint64_t value;
+ /* Technically, this should be a floating point value, but in practice, we
+ * can make do with integer buckets. */
+ int64_t bucket;
+} metrics_histogram_bucket_t;
+
/** Metric counter object (METRICS_TYPE_COUNTER). */
typedef struct metrics_counter_t {
uint64_t value;
@@ -40,6 +51,18 @@ typedef struct metrics_gauge_t {
int64_t value;
} metrics_gauge_t;
+/** Metric histogram object (METRICS_TYPE_HISTOGRAM). */
+typedef struct metrics_histogram_t {
+ /* The observation buckets. */
+ metrics_histogram_bucket_t *buckets;
+ /* The number of observation buckets. */
+ size_t bucket_count;
+ /* The sum of all observations */
+ int64_t sum;
+ /* The total number of observations */
+ uint64_t count;
+} metrics_histogram_t;
+
const char *metrics_type_to_str(const metrics_type_t type);
/* Helpers. */