/var/lib/pcp/testsuite/src/exercise.c is in pcp-testsuite 3.8.12ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | /*
* Copyright (c) 1995-2002 Silicon Graphics, Inc. All Rights Reserved.
*/
/*
* General exerciser, checks (for licensed/unlicensed PMCDs)
* - PMCD availability
* - pmDesc availability
* - indom availiability
* - metric value availability
* - memory leaks (when -i used to make iterations > 1)
*/
#include <ctype.h>
#include <string.h>
#include <pcp/pmapi.h>
#include <pcp/impl.h>
extern int errno;
static int _metrics;
static int _indom;
static int _insitu;
static int _ptr;
static void
dometric(const char *name)
{
int n;
pmID pmidlist[] = { PM_ID_NULL };
pmDesc desc;
int *instlist = NULL;
char **instname = NULL;
pmResult *result;
extern int pmDebug;
_metrics++;
/* cast const away as pmLookupName will not modify this string */
if ((n = pmLookupName(1, (char **)&name, pmidlist)) < 0) {
printf("%s: pmLookupName: %s\n", name, pmErrStr(n));
return;
}
if ((n = pmLookupDesc(pmidlist[0], &desc)) < 0) {
printf("%s: pmLookupDesc: %s\n", name, pmErrStr(n));
return;
}
if (desc.indom != PM_INDOM_NULL) {
_indom++;
if ((n = pmGetInDom(desc.indom, &instlist, &instname)) < 0) {
printf("%s: pmGetInDom: %s\n", name, pmErrStr(n));
return;
}
if (instlist)
free(instlist);
if (instname)
free(instname);
}
if ((n = pmFetch(1, pmidlist, &result)) < 0) {
printf("%s: pmFetch: %s\n", name, pmErrStr(n));
return;
}
if (result->numpmid != 1) {
printf("%s: pmFetch: numpmid=%d, not 1\n", name, result->numpmid);
}
else {
if (result->vset[0]->numval == 0)
printf("%s: pmFetch: no value available\n", name);
else if (result->vset[0]->numval < 0)
printf("%s: pmFetch: %s\n", name, pmErrStr(result->vset[0]->numval));
else {
if (result->vset[0]->valfmt == PM_VAL_INSITU) {
_insitu++;
if (pmDebug && DBG_TRACE_APPL0)
printf("%s: insitu type=%s\n", name, pmTypeStr(desc.type));
}
else {
_ptr++;
if (pmDebug && DBG_TRACE_APPL0)
printf("%s: ptr size=%d valtype=%d descrtype=%s\n",
name,
result->vset[0]->vlist[0].value.pval->vlen,
result->vset[0]->vlist[0].value.pval->vtype,
pmTypeStr(desc.type));
}
}
}
pmFreeResult(result);
}
int
main(argc, argv)
int argc;
char *argv[];
{
int c;
int sts;
int i;
int errflag = 0;
char *host = "localhost";
char *namespace = NULL;
char *endnum;
int iter = 1;
unsigned long datasize;
#ifdef PCP_DEBUG
static char *debug = "[-D N]";
#else
static char *debug = "";
#endif
static char *usage = "[-h hostname] [-i iterations] [-n namespace] [-l licenseflag ] [name ...]";
__pmProcessDataSize(NULL);
__pmSetProgname(pmProgname);
while ((c = getopt(argc, argv, "D:h:i:l: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 'h': /* hostname for PMCD to contact */
host = optarg;
break;
case 'i': /* iteration count */
iter = (int)strtol(optarg, &endnum, 10);
if (*endnum != '\0') {
fprintf(stderr, "%s: -i requires numeric argument\n", pmProgname);
errflag++;
}
break;
case 'n': /* alternative name space file */
namespace = optarg;
break;
case '?':
default:
errflag++;
break;
}
}
if (errflag) {
fprintf(stderr, "Usage: %s %s%s\n", pmProgname, debug, usage);
exit(1);
}
sts = pmNewContext(PM_CONTEXT_HOST, host);
if (sts < 0) {
printf("%s: Cannot connect to PMCD on host \"%s\": %s\n", pmProgname, host, pmErrStr(sts));
exit(1);
}
if (namespace != NULL) {
/*
* only explicitly load namespace if -n specified
*/
if ((sts = pmLoadNameSpace(namespace)) < 0) {
printf("%s: Cannot load namespace from \"%s\": %s\n", pmProgname, namespace, pmErrStr(sts));
exit(1);
}
}
/* non-flag args are argv[optind] ... argv[argc-1] */
for (i = 0; i < iter; i++) {
if (optind >= argc)
pmTraversePMNS("", dometric);
else {
int a;
for (a = optind; a < argc; a++) {
pmTraversePMNS(argv[a], dometric);
}
}
__pmProcessDataSize(&datasize);
printf("[%d] %d metrics, %d getindom, %d insitu, %d ptr",
i, _metrics, _indom, _insitu, _ptr);
if (datasize)
printf(", mem leak: %ld Kbytes", datasize);
putchar('\n');
_metrics = _indom = _insitu = _ptr = 0;
}
exit(0);
}
|