Line data Source code
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 8 : metrics_type_to_str(const metrics_type_t type) 21 : { 22 8 : switch (type) { 23 : case METRICS_TYPE_COUNTER: 24 : return "counter"; 25 1 : case METRICS_TYPE_GAUGE: 26 1 : return "gauge"; 27 0 : default: 28 0 : 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 326 : metrics_format_label(const char *key, const char *value) 38 : { 39 326 : static char buf[128]; 40 326 : tor_snprintf(buf, sizeof(buf), "%s=\"%s\"", key, value); 41 326 : return buf; 42 : }