On 15/04/15 10:09, Frank Ch. Eigler wrote:
Ken McDonell <kenj@xxxxxxxxxxxxxxxx> writes:
[...]
1. if numpmid == 1, then return 1 for success else an error code (<0)
... this special case is really required to allow a caller to discover
_why_ a lookup failed for a particular metric
2. if numpmid > 1, then 3 cases apply
[...]
- otherwise, return n (0 <= n < numpmid) as the count for those
that are OK
I don't quite understand why 1 and >1 cases are different. What
reason could the caller discover in the first case, that she wouldn't
also want to know about the others?
Fair question, Frank.
Given there are numpmid lookups to be done, when numpmid > 1, there are
> 1 possible "error" conditions that we have to map to a single integer
return value ... we flag the individual PMIDs as PM_ID_NULL if the
corresponding lookup fails, but we really need a short-hand way to know
if all is well or not (to avoid scanning the array of PMIDs).
So the common code template would be something like ...
if ((sts = pmLookupName(numpmid, namelist, pmidlist)) != numpmid) {
/* error case */
}
But now, the problem is in the error case, what to do? We can skip the
PM_ID_NULL ones in the code that follows and/or report something more
useful to the punter.
With the API as proposed (and indeed as implemented today), the error
code might look like:
int i;
for (i = 0; i < numpmid; i++) {
if (pmidlist[i] == PM_ID_NULL) {
sts = pmLookupName(1, &namelist[i], &pmidlist[i]);
printf("failed lookup for %s: %s\n",
namelist[i], pmErrStr(sts));
}
}
|