pcp
[Top] [All Lists]

Re: [pcp] Confusion about metricConvert() value for kernel.all.cpu.user

To: pcp@xxxxxxxxxxx
Subject: Re: [pcp] Confusion about metricConvert() value for kernel.all.cpu.user
From: Rohan Arora <rarora2012@xxxxxxxxx>
Date: Thu, 6 Aug 2015 16:34:06 -0400
Delivered-to: pcp@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=TAApDiPSEU1brdPMmw9KJjml3FxjwBLBLtjtlfBZYAc=; b=n4MRxoM/8t8Jsm+uPNAovjscuuN2Utse6GTMT+TMF8qYrsFkJTHzC6hzCVEKEwlVTN 8fbLyI5E2rpH3iP2dLkgQBspQU5w2FJc5uYNy9nuadNK9cD13ZYMnKIKvXvuyCJ8W/x5 FE3fD4UNjTEDH3fUu/5aA9PFFwOSqZEPGS9RpdTsGMSmfmlWthp6awAAPxEqvgLrQ1KC IOaRZzFX4qYlWwgb6v9rqJoRbb/DLduubHyAEQmOYL47sbnOZmQXuFMwJybDZc+21pz1 Ec0+UGzMAidu1v6LP7Voez58fXl6ONsFJri2bGnnE9sE2mXZ51NlLyt8iVQAZcQ9fxJN MRnA==
In-reply-to: <87si7wxjpv.fsf@xxxxxxxxxx>
References: <CANbxzdVdC91nn8WG8MXNu=LjP32ehO4VAa7tKNVuUONOyJh8uA@xxxxxxxxxxxxxx> <87si7wxjpv.fsf@xxxxxxxxxx>
It depends what you want to do with the final value, but usually interpreting
such a value (note - "Semantics: counter") requires two samples at different
times (i.e. 2 pmFetch calls, with different result->timestamps). This is
then "rate converted" - i.e. we look at the change in value divided by the
change in time. Percentage utilisation can be then calculated by multiplying
by 100.
From the above portion of an e-mail, I was under the impression that the rate-converted value would come out as a decimal directly corresponding to the percentage from a reply from a former thread.Â

So would the correct way to go about calculating the percentage of user cpu usage be to get the values for ALL cpu metrics, and then do the following?
(metricConvert for user) / (sum of metricConvert for all cpu metrics) * 100

Thanks,
Rohan

On Thu, Aug 6, 2015 at 4:09 PM, Lukas Berk <lberk@xxxxxxxxxx> wrote:
Hi,

Rohan Arora <rarora2012@xxxxxxxxx> writes:
> I am using the Python API, and if I run a couple of mgFetch() calls
> using the MetricGroup class, and then use the metricConvert()
> function, I end up getting a value like 308.4132647893692. I had
> thought that to convert this rate converted value to a percentage, all
> I had to do was multiply by 100, but that would result in 30,800% of
> the CPU being used, and that is just by the user.

Assuming this is a continuation from your former thread, looking into
the metric description can help explain this;

% pminfo -dT kernel.all.cpu.user

kernel.all.cpu.user
  Data Type: 64-bit unsigned int InDom: PM_INDOM_NULL 0xffffffff
  Semantics: counter Units: millisec
Help:
total user CPU time from /proc/stat for all CPUs, including guest CPU
  time

Notice the semantics lists it as a 'counter' metric, not a percentage,
so we can't simply multiply by 100 and call it a day. (check Section
2.3.3.2 in the PCP Programmer's Guide[1] for more details on semantics).

Second, the metricConvert() function doesn't convert from a counter
value to a percentage. Instead, it calculates the delta between the
most current value you've fetched and the previously stored value.

Therefore, you'll have to fetch the other various cpu states (`pminfo
kernel.all.cpu` on the commandline for a full list of them) and
calculate the percentage as a total of all the cpu counters.

Hope that helps,

Lukas

[1] - http://www.pcp.io/doc/pcp-programmers-guide.pdf

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