2 * Copyright (c) 1997-2001 Silicon Graphics, Inc. All Rights Reserved.
5 #define SOURCE handle == 0 ? "host" : ( type == PM_CONTEXT_ARCHIVE ? "archive" : "host" )
6 #define HOST handle == 0 ? "localhost" : host
9 * context and profile exerciser
12 #include <pcp/pmapi.h>
15 static int inst_bin
[] = { 100, 200, 300, 400, 500, 600, 700, 800, 900 };
17 static int xpect_bin
[] = { 1 };
18 static int xpect_colour
[] = { 0 };
20 static char *namelist
[] = {
26 * handle profile values expected
27 * 0 bin=500, no colour 1 bin 0 colour
31 main(int argc
, char **argv
)
37 char *host
= "localhost";
38 char *namespace = PM_NS_DEFAULT
;
39 pmInDom indom_bin
, indom_colour
;
45 static char *debug
= "[-D N] ";
47 static char *debug
= "";
49 static char *usage
= "[-a archive] [-h hostname] [-L] [-n namespace]";
51 __pmSetProgname(argv
[0]);
53 while ((c
= getopt(argc
, argv
, "a:D:h:Ln:")) != EOF
) {
56 case 'a': /* archive name */
58 fprintf(stderr
, "%s: at most one of -a, -h and -L allowed\n", pmProgname
);
61 type
= PM_CONTEXT_ARCHIVE
;
66 case 'D': /* debug flag */
67 sts
= __pmParseDebug(optarg
);
69 fprintf(stderr
, "%s: unrecognized debug flag specification (%s)\n",
78 case 'h': /* hostname for PMCD to contact */
80 fprintf(stderr
, "%s: at most one of -a, -h and -L allowed\n", pmProgname
);
84 type
= PM_CONTEXT_HOST
;
87 case 'L': /* local mode, no PMCD */
89 fprintf(stderr
, "%s: at most one of -a, -h and -L allowed\n", pmProgname
);
93 type
= PM_CONTEXT_LOCAL
;
96 case 'n': /* alternative name space file */
108 fprintf(stderr
, "Usage: %s %s%s\n", pmProgname
, debug
, usage
);
112 if ((sts
= pmLoadASCIINameSpace(namespace, 1)) < 0) {
113 printf("%s: Cannot load namespace from \"%s\": %s\n", pmProgname
, namespace, pmErrStr(sts
));
116 if ((sts
= pmLookupName(2, namelist
, metrics
)) < 0) {
117 fprintf(stderr
, "pmLookupName: %s\n", pmErrStr(sts
));
118 fprintf(stderr
, "pmids: 0x%x 0x%x\n", metrics
[0], metrics
[1]);
122 /* make context 0 the default localhost one */
123 if ((sts
= pmNewContext(PM_CONTEXT_HOST
, "localhost")) < 0) {
124 fprintf(stderr
, "pmNewContext(..., \"localhost\"): %s\n",
130 type
= PM_CONTEXT_HOST
; /* default */
132 if (type
== PM_CONTEXT_HOST
) {
133 if ((sts
= pmNewContext(PM_CONTEXT_HOST
, host
)) < 0) {
134 fprintf(stderr
, "handle: pmNewContext(host=%s): %s\n", host
, pmErrStr(sts
));
138 else if (type
== PM_CONTEXT_LOCAL
) {
139 if ((sts
= pmNewContext(PM_CONTEXT_LOCAL
, host
)) < 0) {
140 fprintf(stderr
, "handle: pmNewContext(local): %s\n", pmErrStr(sts
));
145 if ((sts
= pmNewContext(PM_CONTEXT_ARCHIVE
, host
)) < 0) {
146 fprintf(stderr
, "handle: pmNewContext(archive=%s): %s\n", host
, pmErrStr(sts
));
152 while (handle
>= 0) {
153 pmUseContext(handle
);
155 if ((sts
= pmLookupDesc(metrics
[0], &desc
)) < 0) {
156 fprintf(stderr
, "pmLookupDesc: context=%d %s=%s %s: %s\n",
157 handle
, SOURCE
, HOST
, namelist
[0], pmErrStr(sts
));
160 indom_bin
= desc
.indom
;
161 if ((sts
= pmLookupDesc(metrics
[1], &desc
)) < 0) {
162 fprintf(stderr
, "pmLookupDesc: context=%d %s=%s %s: %s\n",
163 handle
, SOURCE
, HOST
, namelist
[1], pmErrStr(sts
));
166 indom_colour
= desc
.indom
;
168 pmDelProfile(indom_bin
, 0, (int *)0);
169 pmAddProfile(indom_bin
, 1, &inst_bin
[4]);
170 pmDelProfile(indom_colour
, 0, (int *)0);
172 sts
= pmFetch(2, metrics
, &resp
);
174 fprintf(stderr
, "botch @ context=%d %s=%s: pmFetch: %s\n",
175 handle
, SOURCE
, HOST
, pmErrStr(sts
));
178 if (resp
->numpmid
!= 2) {
179 fprintf(stderr
, "botch @ context=%d %s=%s: numpmid %d != 2\n",
180 handle
, SOURCE
, HOST
, resp
->numpmid
);
183 if (resp
->vset
[0]->numval
!= xpect_bin
[0]) {
184 fprintf(stderr
, "botch @ context=%d %s=%s: [indom %s] numval got: %d expect: %d\n",
185 handle
, SOURCE
, HOST
, pmInDomStr(indom_bin
),
186 resp
->vset
[0]->numval
, xpect_bin
[0]);
188 if (resp
->vset
[1]->numval
!= xpect_colour
[0]) {
189 fprintf(stderr
, "botch @ context=%d %s=%s: [indom %s] numval got: %d expect: %d\n",
190 handle
, SOURCE
, HOST
, pmInDomStr(indom_colour
),
191 resp
->vset
[1]->numval
, xpect_colour
[0]);
197 if ((sts
= pmDestroyContext(handle
)) < 0)
198 fprintf(stderr
, "pmDestroyContext %d %s=%s: %s\n",
199 handle
, SOURCE
, HOST
, pmErrStr(sts
));