Re: [hackers] [slstatus][PATCH] cpu_perc: Check for division by zero

From: Michael Buch <michaelbuch12_AT_gmail.com>
Date: Thu, 14 Feb 2019 00:31:46 +0000

Perhaps it might be cleaner to save the sum away in separate variables
instead of accessing the states several times. Or better extract into
a separate function/macro. Also mind doing it for FreeBSD and Linux?
Since they use the same logic

Regards,
Michael

Am Mi., 13. Feb. 2019 um 23:20 Uhr schrieb Ingo Feinerer <feinerer_AT_logic.at>:
>
> ---
> components/cpu.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/components/cpu.c b/components/cpu.c
> index d9bd018..47a10c5 100644
> --- a/components/cpu.c
> +++ b/components/cpu.c
> _AT_@ -92,6 +92,11 @@
> return NULL;
> }
>
> + if (a[CP_USER] + a[CP_NICE] + a[CP_SYS] + a[CP_INTR] + a[CP_IDLE] ==
> + b[CP_USER] + b[CP_NICE] + b[CP_SYS] + b[CP_INTR] + b[CP_IDLE]) {
> + return NULL;
> + }
> +
> return bprintf("%d", 100 *
> ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
> a[CP_INTR]) -
> --
> 2.20.1
>
>
Received on Thu Feb 14 2019 - 01:31:46 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 14 2019 - 01:36:22 CET