Skip to content

Commit

Permalink
update metric to include description and type information for printing
Browse files Browse the repository at this point in the history
  • Loading branch information
Yao Yue committed Feb 13, 2016
1 parent ee6abc7 commit 1139bb3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/modules/cc_metric.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Data Structure
struct metric {
char *name;
char *desc;
metric_type_e type;
union {
uint64_t counter;
Expand All @@ -60,7 +61,7 @@ Data Structure
};
};
``metric`` is the fundamental data structure, each metric has (for now) three types, a printable name, and value.
``metric`` is the fundamental data structure, each metric has (for now) three types, a printable name, a short description, and value.

If a metric is of type ``METRIC_COUNTER``, its value always increases monotonically. A metric of type ``METRIC_GAUGE`` has a signed integer value. Type ``METRIC_FPN`` means the value is a floating-point number.

Expand Down
5 changes: 4 additions & 1 deletion include/cc_metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extern "C" {
struct metric _name;

#define METRIC_INIT(_name, _type, _description) \
._name = {.name = #_name, .type = _type},
._name = {.name = #_name, .desc = _description, .type = _type},

#define METRIC_NAME(_name, _type, _description) \
#_name,
Expand All @@ -118,12 +118,15 @@ typedef enum metric_type {
METRIC_FPN /* supports UPDATE_VAL */
} metric_type_e;

extern char *metric_type_str[3];

/* Note: anonymous union does not work with older (<gcc4.7) compilers */
/* TODO(yao): determine if we should dynamically allocate the value field
* during init. The benefit is we don't have to allocate the same amount of
* memory for different types of values, potentially wasting space. */
struct metric {
char *name;
char *desc;
metric_type_e type;
union {
uint64_t counter;
Expand Down
2 changes: 2 additions & 0 deletions src/stats/cc_metric.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <stdbool.h>

char *metric_type_str[] = {"counter", "gauge", "floating point"};

void
metric_reset(struct metric sarr[], unsigned int n)
{
Expand Down

0 comments on commit 1139bb3

Please sign in to comment.