Tor  0.4.7.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  default:
28  tor_assert_unreached();
29  }
30 }
31 
32 /** Return a static buffer pointer that contains a formatted label on the form
33  * of key=value.
34  *
35  * Subsequent call to this function invalidates the previous buffer. */
36 const char *
37 metrics_format_label(const char *key, const char *value)
38 {
39  static char buf[128];
40  tor_snprintf(buf, sizeof(buf), "%s=\"%s\"", key, value);
41  return buf;
42 }
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.