1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
* Copyright (c) 1997-2001 Silicon Graphics, Inc. All Rights Reserved.
*/
/*
* Check new functionality of pmTrimNameSpace
*/
#include <ctype.h>
#include <string.h>
#include <pcp/pmapi.h>
#include <pcp/impl.h>
extern int errno;
static char tag;
static void
dometric(const char *name)
{
printf("%c %s\n", tag, name);
}
int
main(argc, argv)
int argc;
char *argv[];
{
int c;
int sts;
int errflag = 0;
char *namespace = PM_NS_DEFAULT;
int ctx; /* context for localhost */
int arch; /* context for archive */
#ifdef PCP_DEBUG
static char *debug = "[-D N]";
#else
static char *debug = "";
#endif
static char *usage = "[-n namespace] archive";
__pmSetProgname(argv[0]);
while ((c = getopt(argc, argv, "D:n:")) != EOF) {
switch (c) {
#ifdef PCP_DEBUG
case 'D': /* debug flag */
sts = __pmParseDebug(optarg);
if (sts < 0) {
fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n",
pmProgname, optarg);
errflag++;
}
else
pmDebug |= sts;
break;
#endif
case 'n': /* alternative name space file */
namespace = optarg;
break;
case '?':
default:
errflag++;
break;
}
}
if (errflag || optind != argc-1) {
fprintf(stderr, "Usage: %s %s%s\n", pmProgname, debug, usage);
exit(1);
}
if ((sts = pmLoadNameSpace(namespace)) < 0) {
printf("%s: Cannot load namespace from \"%s\": %s\n", pmProgname, namespace, pmErrStr(sts));
exit(1);
}
if ((ctx = pmNewContext(PM_CONTEXT_HOST, "localhost")) < 0) {
printf("%s: pmNewContext(localhost): %s\n", pmProgname, pmErrStr(ctx));
exit(1);
}
printf("0 NameSpace for host context ...\n");
tag = '0';
pmTraversePMNS("sample", dometric);
if ((arch = pmNewContext(PM_CONTEXT_ARCHIVE, argv[optind])) < 0) {
printf("%s: pmNewContext(%s): %s\n", pmProgname, argv[optind], pmErrStr(arch));
exit(1);
}
printf("1\n1 Trimmed NameSpace for archive context ...\n");
pmTrimNameSpace();
tag = '1';
pmTraversePMNS("", dometric);
printf("2\n2 Trimmed NameSpace for host context ...\n");
pmUseContext(ctx);
pmTrimNameSpace();
tag = '2';
pmTraversePMNS("sample", dometric);
exit(0);
}
|