qa: update 660 to generate index.html, fixing pcp-testsuite runs
[pcp.git] / qa / src / mmv_genstats.c
blobe10e19fb9e81b038332308a182767dc9f05f64fe
1 /*
2 * Copyright (c) 1995-2001 Silicon Graphics, Inc. All Rights Reserved.
3 * Copyright (c) 2009 Aconex. All Rights Reserved.
4 */
6 #include <pcp/pmapi.h>
7 #include <pcp/mmv_stats.h>
9 static mmv_instances_t test_instances [] = {
10 { 0, "zero" },
11 { 1, "hero" },
14 static mmv_instances_t nest_instances [] = {
15 { 0, "bird" },
16 { 1, "tree" },
17 { 2, "eggs" },
20 static mmv_indom_t indoms[] = {
21 { .serial = 1,
22 .count = 2,
23 .instances = test_instances,
24 .shorttext = "We can be heroes",
25 .helptext = "We can be heroes, just for one day",
27 { .serial = 2,
28 .count = 3,
29 .instances = nest_instances,
30 /* exercise no-help-text case */
34 static mmv_metric_t metrics[] = {
35 { .name = "counter",
36 .item = 1,
37 .type = MMV_TYPE_U32,
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",
43 { .name = "discrete",
44 .item = 2,
45 .type = MMV_TYPE_I32,
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",
51 { .name = "indom",
52 .item = 3,
53 .type = MMV_TYPE_U32,
54 .semantics = MMV_SEM_INSTANT,
55 .dimension = MMV_UNITS(0,0,1,0,0,PM_COUNT_ONE),
56 .indom = 1,
57 /* exercise no-help-text, no indom case */
59 { .name = "interval",
60 .item = 4,
61 .type = MMV_TYPE_ELAPSED,
62 .semantics = MMV_SEM_COUNTER,
63 .dimension = MMV_UNITS(0,1,0,0,PM_TIME_USEC,0),
64 .indom = 2,
65 /* exercise no-help-text case */
67 { .name = "string",
68 .item = 5,
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 */
74 { .name = "strings",
75 .item = 6,
76 .type = MMV_TYPE_STRING,
77 .semantics = MMV_SEM_INSTANT,
78 .dimension = MMV_UNITS(0,0,0,0,0,0),
79 .indom = 1,
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]); }
88 int
89 main(int ac, char * av[])
91 pmAtomValue * atom;
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());
97 if (!addr) {
98 fprintf(stderr, "mmv_stats_init failed : %s\n", strerror(errno));
99 return 1;
102 /* start an interval */
103 atom = mmv_stats_interval_start(addr, NULL, "interval", "eggs");
105 /* add ... */
106 mmv_stats_add(addr, "counter", "", 40);
107 /* add 1 ... */
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);
125 sleep(sleeper);
127 /* end an interval */
128 mmv_stats_interval_end(addr, atom);
130 return 0;