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
|
#include "pmlogreduce.h"
void
doindom(pmResult *rp)
{
pmValueSet *vsp;
int i;
int j;
int needti = 0;
int need;
metric_t *mp = NULL;
int *instlist;
char **namelist;
int sts;
for (i = 0; i < rp->numpmid; i++) {
vsp = rp->vset[i];
if (vsp->numval <= 0)
continue;
/*
* pmidlist[] and rp->vset[]->pmid may not be in 1:1
* correspondence because we come here after rewrite() has
* been called ... search for matching pmid
*/
for (j = 0; j < numpmid; j++) {
if (pmidlist[j] == vsp->pmid) {
mp = &metriclist[j];
break;
}
}
if (mp == NULL) {
fprintf(stderr,
"%s: doindom: Arrgh, unexpected PMID %s @ vset[%d]\n",
pmProgname, pmIDStr(vsp->pmid), i);
__pmDumpResult(stderr, rp);
exit(1);
}
if (mp->idp == NULL)
continue;
if ((sts = pmGetInDom(mp->idp->indom, &instlist, &namelist)) < 0) {
fprintf(stderr,
"%s: doindom: pmGetInDom (%s) failed: %s\n",
pmProgname, pmInDomStr(mp->idp->indom), pmErrStr(sts));
exit(1);
}
need = 1;
/*
* Need to output the indom if the number of instances changes
* or the set of instance ids are not the same from the last
* time.
*/
if (sts == mp->idp->numinst) {
for (j = 0; j < mp->idp->numinst; j++) {
if (mp->idp->inst[j] != instlist[j])
break;
}
if (j == mp->idp->numinst) {
/*
* Do we need to check the namelist elts as well, e.g.
* using strcmp()?
* Not at this stage ... if the instance ids are all the
* same, then only a very odd (and non-compliant) PMDA
* would change the mapping from id to name on the fly
*/
need = 0;
}
}
if (need) {
#if PCP_DEBUG
if (pmDebug & DBG_TRACE_APPL0) {
fprintf(stderr, "Add metadata: indom %s for metric %s\n", pmInDomStr(mp->idp->indom), pmIDStr(vsp->pmid));
}
#endif
if (mp->idp->name != NULL) free(mp->idp->name);
if (mp->idp->inst != NULL) free(mp->idp->inst);
mp->idp->name = namelist;
mp->idp->inst = instlist;
mp->idp->numinst = sts;
if ((sts = __pmLogPutInDom(&logctl, mp->idp->indom, ¤t, mp->idp->numinst, mp->idp->inst, mp->idp->name)) < 0) {
fprintf(stderr,
"%s: Error: failed to add pmInDom: indom %s (for pmid %s): %s\n",
pmProgname, pmInDomStr(mp->idp->indom), pmIDStr(vsp->pmid), pmErrStr(sts));
exit(1);
}
needti = 1; /* requires a temporal index update */
}
else {
free(instlist);
free(namelist);
}
}
if (needti) {
fflush(logctl.l_mdfp);
__pmLogPutIndex(&logctl, ¤t);
}
}
|