metrics_common.c (983B)
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 16 #include "lib/metrics/metrics_common.h" 17 18 /** Return string representation of a metric type. */ 19 const char * 20 metrics_type_to_str(const metrics_type_t type) 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 }