Tor  0.4.8.0-alpha-dev
metrics_common.c
Go to the documentation of this file.
1 /* 2020, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
4 /**
5  * @file metrics_common.c
6  * @brief Common code for the metrics library
7  **/
8 
9 #include <stddef.h>
10 
11 #include "orconfig.h"
12 
13 #include "lib/log/util_bug.h"
14 #include "lib/string/printf.h"
15 
17 
18 /** Return string representation of a metric type. */
19 const char *
21 {
22  switch (type) {
23  case METRICS_TYPE_COUNTER:
24  return "counter";
25  case METRICS_TYPE_GAUGE:
26  return "gauge";
27  case METRICS_TYPE_HISTOGRAM:
28  return "histogram";
29  default:
30  tor_assert_unreached();
31  }
32 }
33 
34 /** Return a static buffer pointer that contains a formatted label on the form
35  * of key=value.
36  *
37  * Subsequent call to this function invalidates the previous buffer. */
38 const char *
39 metrics_format_label(const char *key, const char *value)
40 {
41  static char buf[128];
42  tor_snprintf(buf, sizeof(buf), "%s=\"%s\"", key, value);
43  return buf;
44 }
const char * metrics_format_label(const char *key, const char *value)
const char * metrics_type_to_str(const metrics_type_t type)
Header for lib/metrics/metrics_common.c.
metrics_type_t
int tor_snprintf(char *str, size_t size, const char *format,...)
Definition: printf.c:27
Header for printf.c.
Macros to manage assertions, fatal and non-fatal.