If you really need it to add up to 100, then it's simple ...

    if (Kernel + User > 100) {
        User = 100 - Kernel;
    }
    Idle = 100 - Kernel - User;

If you want to be smart, you might want to round small numbers up, and 
large numbers down (e.g. perhaps any non-zero amount should always show 
as at least 1%?)

As to why they don't already add up,  I had a quick look at the kstat 
code, but didn't find the specifics. However, it should be noted that 
one has to choose to update kstats atomically, and if one does not, it's 
possible to sample more than one set of values with one read. It's a 
trade off between performance and accuracy. But, as I said, I don't 
actually know what we do in this case.

Phil


Stefan Parvu wrote:
>> Just grab the nsec values. As I recall, the others are just
>> lower precision
>> numbers derived from them.
>>     
>
> using cpu::sys:cpu_nsec_user,kernel,idle
> does not fix the problem. I think this is more
> an issue about printing the output in Perl using
> print or printf and rounding the values. 
>
> Example using: loadstat.pl:
> Idle   Kernel User
> 93      4       1
> 98      0       1
> 98      0       1
> 96      1       2
> 89      7       2
> 93      5       1
> 98      0       1
> 98      0       1
> 97      0       1
> 98      0       1
> 92      5       2
> 97      0       1
> 96      1       2
> 91      4       4
> 90      6       3
> 92      5       2
> 34      1       64
> 0       0       99
> 0       0       99
> 86      1       12
>
>
> If you change the output from print to printf and have a format 
> output we get closer but not enough :) There are sometimes
> samples which dont match User+Sys+Idle=100. But more accurate.
>
> Stefan
>
>
> [1] - 
> http://opensolaris.org/os/project/onnv/onnv_build/faster_builds/tools/scripts/loadstat.pl
>
>
> _______________________________________________
> perf-discuss mailing list
> perf-discuss@opensolaris.org
>   

_______________________________________________
perf-discuss mailing list
perf-discuss@opensolaris.org

Reply via email to