diff options
author | David Goulet <dgoulet@torproject.org> | 2021-04-15 09:05:55 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2021-05-12 11:58:25 -0400 |
commit | 455471835da35d8ee64e6a2c0a70acb89a003bf4 (patch) | |
tree | ce582e1605b9e35e88f8fd33aad7790d53759dba /src/lib/metrics | |
parent | cc2947c0070faac0805478381f13956bb2775621 (diff) | |
download | tor-455471835da35d8ee64e6a2c0a70acb89a003bf4.tar.gz tor-455471835da35d8ee64e6a2c0a70acb89a003bf4.zip |
metrics: Move helper function to lib/metrics
It is a common function that a lot of subsystem can use which is to
format a label so move it out of the HS subsystem into the more generic
metrics library.
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/lib/metrics')
-rw-r--r-- | src/lib/metrics/metrics_common.c | 13 | ||||
-rw-r--r-- | src/lib/metrics/metrics_common.h | 3 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/lib/metrics/metrics_common.c b/src/lib/metrics/metrics_common.c index 5941a4d892..c0352b6646 100644 --- a/src/lib/metrics/metrics_common.c +++ b/src/lib/metrics/metrics_common.c @@ -11,6 +11,7 @@ #include "orconfig.h" #include "lib/log/util_bug.h" +#include "lib/string/printf.h" #include "lib/metrics/metrics_common.h" @@ -27,3 +28,15 @@ metrics_type_to_str(const metrics_type_t type) tor_assert_unreached(); } } + +/** Return a static buffer pointer that contains a formatted label on the form + * of key=value. + * + * Subsequent call to this function invalidates the previous buffer. */ +const char * +metrics_format_label(const char *key, const char *value) +{ + static char buf[128]; + tor_snprintf(buf, sizeof(buf), "%s=%s", key, value); + return buf; +} diff --git a/src/lib/metrics/metrics_common.h b/src/lib/metrics/metrics_common.h index 59aa9c0e90..3644ad3d50 100644 --- a/src/lib/metrics/metrics_common.h +++ b/src/lib/metrics/metrics_common.h @@ -42,4 +42,7 @@ typedef struct metrics_gauge_t { const char *metrics_type_to_str(const metrics_type_t type); +/* Helpers. */ +const char *metrics_format_label(const char *key, const char *value); + #endif /* !defined(TOR_LIB_METRICS_METRICS_COMMON_H) */ |