LCOV - code coverage report
Current view: top level - lib/metrics - metrics_common.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 8 10 80.0 %
Date: 2021-11-24 03:28:48 Functions: 2 2 100.0 %

          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             : }

Generated by: LCOV version 1.14