On Tue, May 23, 2017 at 11:33:00PM +0200, Jan Vlach wrote:
> Hello bugs team,
>
> I've been playing with system accounting a bit and noticed, that sa -c does
> not show percentages correctly. The multiply by 100 is missing in the
> calculation in various places.
>
> FreeBSD fixed this in 2007
> https://svnweb.freebsd.org/base/head/usr.sbin/sa/pdb.c?r1=168455&r2=168456&
>
> Patch attached. (cvs diff pdb.c)
>
> Tried the fix on 6.1 stable on amd64, applies cleanly on -current on i386
> (dmesg below)
>
> Could you please check this?
>
> Thank you,
> Jan
>
>
> ### EXAMPLE OUTPUT (sa -c | head -7):
> 2031267 2957434.95re 15203.74cp 42avio
> 0k
> 658 0.00% 3731.97re 0.00% 1621.36cp 0.11% 3271avio
> 0k ffmpeg
> 856 0.00% 31754.99re 0.01% 1610.75cp 0.11% 1168avio
> 0k surf
> 10424 0.01% 1534.91re 0.00% 1530.84cp 0.10% 14avio
> 0k cc1plus
> 19393 0.01% 3675.59re 0.00% 1004.55cp 0.07% 733avio
> 0k perl
> 155 0.00% 14729.46re 0.00% 983.00cp 0.06% 2153avio
> 0k firefox-es
> 66261 0.03% 1001.52re 0.00% 678.09cp 0.04% 3avio
> 0k cc1
>
> ### EXAMPLE OUTPUT PATCHED (sa -c | head -7):
> 2031261 2957434.95re 15203.74cp 42avio
> 0k
> 658 0.0% 3731.97re 0.1% 1621.36cp 10.7% 3271avio
> 0k ffmpeg
> 856 0.0% 31754.99re 1.1% 1610.75cp 10.6% 1168avio
> 0k surf
> 10424 0.5% 1534.91re 0.1% 1530.84cp 10.1% 14avio
> 0k cc1plus
> 19393 1.0% 3675.59re 0.1% 1004.55cp 6.6% 733avio
> 0k perl
> 155 0.0% 14729.46re 0.5% 983.00cp 6.5% 2153avio
> 0k firefox-es
> 66261 3.3% 1001.52re 0.0% 678.09cp 4.5% 3avio
> 0k cc1
>
The patch below looks correct to me. The current output makes no sense.
I'm not sure if there might be a concern for scripts depending on this.
If that's not the case, ok tb@
> Index: pdb.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/sa/pdb.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 pdb.c
> --- pdb.c 14 Aug 2016 22:29:01 -0000 1.9
> +++ pdb.c 23 May 2017 20:36:47 -0000
> @@ -335,8 +335,8 @@ print_ci(const struct cmdinfo *cip, cons
> printf("%8llu ", cip->ci_calls);
> if (cflag) {
> if (cip != totalcip)
> - printf(" %4.2f%% ",
> - cip->ci_calls / (double) totalcip->ci_calls);
> + printf(" %4.1f%% ",
> + cip->ci_calls / (double) totalcip->ci_calls * 100);
> else
> printf(" %4s ", "");
> }
> @@ -347,8 +347,8 @@ print_ci(const struct cmdinfo *cip, cons
> printf("%11.2fre ", cip->ci_etime / (60.0 * AHZ));
> if (cflag) {
> if (cip != totalcip)
> - printf(" %4.2f%% ",
> - cip->ci_etime / (double) totalcip->ci_etime);
> + printf(" %4.1f%% ",
> + cip->ci_etime / (double) totalcip->ci_etime * 100);
> else
> printf(" %4s ", "");
> }
> @@ -360,9 +360,9 @@ print_ci(const struct cmdinfo *cip, cons
> printf("%11.2fcp ", t / 60.0);
> if (cflag) {
> if (cip != totalcip)
> - printf(" %4.2f%% ",
> + printf(" %4.1f%% ",
> (cip->ci_utime + cip->ci_stime) / (double)
> - (totalcip->ci_utime + totalcip->ci_stime));
> + (totalcip->ci_utime + totalcip->ci_stime) *
> 100);
> else
> printf(" %4s ", "");
> }
> @@ -373,7 +373,7 @@ print_ci(const struct cmdinfo *cip, cons
> printf("%11.2fu ", cip->ci_utime / (60.0 * AHZ));
> if (cflag) {
> if (cip != totalcip)
> - printf(" %4.2f%% ", cip->ci_utime / (double)
> totalcip->ci_utime);
> + printf(" %4.1f%% ", cip->ci_utime / (double)
> totalcip->ci_utime * 100);
> else
> printf(" %4s ", "");
> }
> @@ -383,7 +383,7 @@ print_ci(const struct cmdinfo *cip, cons
> printf("%11.2fs ", cip->ci_stime / (60.0 * AHZ));
> if (cflag) {
> if (cip != totalcip)
> - printf(" %4.2f%% ", cip->ci_stime / (double)
> totalcip->ci_stime);
> + printf(" %4.1f%% ", cip->ci_stime / (double)
> totalcip->ci_stime * 100);
> else
> printf(" %4s ", "");
> }