pcp
[Top] [All Lists]

Re: pmLookupName sts differences

To: "Frank Ch. Eigler" <fche@xxxxxxxxxx>
Subject: Re: pmLookupName sts differences
From: Ken McDonell <kenj@xxxxxxxxxxxxxxxx>
Date: Wed, 15 Apr 2015 12:03:57 +1000
Cc: Martins Innus <minnus@xxxxxxxxxxx>, pcp@xxxxxxxxxxx
Delivered-to: pcp@xxxxxxxxxxx
In-reply-to: <y0mmw2auu9h.fsf@xxxxxxxx>
References: <551D8119.5010404@xxxxxxxxxxx> <552CA769.1070607@xxxxxxxxxxxxxxxx> <552D1EE1.5000600@xxxxxxxxxxx> <552D7DE8.4030706@xxxxxxxxxxxxxxxx> <y0mmw2auu9h.fsf@xxxxxxxx>
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0
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));
        }
}

<Prev in Thread] Current Thread [Next in Thread>