2 * Copyright (c) 1995-2001 Silicon Graphics, Inc. All Rights Reserved.
3 * Copyright (c) 2009 Aconex. All Rights Reserved.
7 #include <pcp/mmv_stats.h>
9 static mmv_instances_t test_instances
[] = {
14 static mmv_instances_t nest_instances
[] = {
20 static mmv_indom_t indoms
[] = {
23 .instances
= test_instances
,
24 .shorttext
= "We can be heroes",
25 .helptext
= "We can be heroes, just for one day",
29 .instances
= nest_instances
,
30 /* exercise no-help-text case */
34 static mmv_metric_t metrics
[] = {
38 .semantics
= MMV_SEM_COUNTER
,
39 .dimension
= MMV_UNITS(0,0,1,0,0,PM_COUNT_ONE
),
40 .shorttext
= "test counter metric",
41 .helptext
= "Yes, this is a test counter metric",
46 .semantics
= MMV_SEM_DISCRETE
,
47 .dimension
= MMV_UNITS(0,0,0,0,0,0),
48 .shorttext
= "test discrete metric",
49 .helptext
= "Yes, this is a test discrete metric",
54 .semantics
= MMV_SEM_INSTANT
,
55 .dimension
= MMV_UNITS(0,0,1,0,0,PM_COUNT_ONE
),
57 /* exercise no-help-text, no indom case */
61 .type
= MMV_TYPE_ELAPSED
,
62 .semantics
= MMV_SEM_COUNTER
,
63 .dimension
= MMV_UNITS(0,1,0,0,PM_TIME_USEC
,0),
65 /* exercise no-help-text case */
69 .type
= MMV_TYPE_STRING
,
70 .dimension
= MMV_UNITS(0,0,0,0,0,0),
71 .semantics
= MMV_SEM_INSTANT
,
72 /* exercise no-help-text, string value case */
76 .type
= MMV_TYPE_STRING
,
77 .semantics
= MMV_SEM_INSTANT
,
78 .dimension
= MMV_UNITS(0,0,0,0,0,0),
80 .shorttext
= "test string metrics",
81 .helptext
= "Yes, this is a test string metric with instances",
85 static inline int indom_count() { return sizeof(indoms
)/sizeof(indoms
[0]); }
86 static inline int metric_count() { return sizeof(metrics
)/sizeof(metrics
[0]); }
89 main(int ac
, char * av
[])
92 char * file
= (ac
> 1) ? av
[1] : "test";
93 int sleeper
= (ac
> 2) ? atoi(av
[2]) : 0;
94 void * addr
= mmv_stats_init(file
, 0, 0,
95 metrics
, metric_count(), indoms
, indom_count());
98 fprintf(stderr
, "mmv_stats_init failed : %s\n", strerror(errno
));
102 /* start an interval */
103 atom
= mmv_stats_interval_start(addr
, NULL
, "interval", "eggs");
106 mmv_stats_add(addr
, "counter", "", 40);
108 mmv_stats_inc(addr
, "counter", "");
110 /* set string values */
111 mmv_stats_set_string(addr
, "string", "", "g'day world");
112 mmv_stats_set_strlen(addr
, "strings", "zero", "00oo00oo00", 10);
113 mmv_stats_set_strlen(addr
, "strings", "zero", "00oo00oo00", 6);
114 mmv_stats_set_strlen(addr
, "strings", "hero", "ZERO", 4);
115 mmv_stats_set_strlen(addr
, "strings", "hero", "", 0);
117 /* set discrete value ... */
118 mmv_stats_set(addr
, "discrete", "", 41);
119 mmv_stats_inc(addr
, "discrete", "");
121 /* add to instance or another if first doesn't exist */
122 mmv_stats_add_fallback(addr
, "indom", "foobar", "unknown", 42);
123 mmv_stats_add_fallback(addr
, "indom", "zero", "unknown", 43);
127 /* end an interval */
128 mmv_stats_interval_end(addr
, atom
);