[hackers] [slstatus] corrected calculation for swap on openbsd || Tobias Tschinkowitz

From: <git_AT_suckless.org>
Date: Wed, 16 May 2018 19:18:33 +0200 (CEST)

commit c1f79d741a160ea17a110ca09b3deb705636ec4a
Author: Tobias Tschinkowitz <he4d_AT_posteo.de>
AuthorDate: Wed May 16 13:26:34 2018 +0200
Commit: Aaron Marcher <me_AT_drkhsh.at>
CommitDate: Wed May 16 19:17:49 2018 +0200

    corrected calculation for swap on openbsd
    
    The swapctl(2) function fills the swapent struct with 512KB blocks.
    As we want to display in GB, i just modified the calculation for this to
    get the expected output.

diff --git a/components/swap.c b/components/swap.c
index 031b713..caa4788 100644
--- a/components/swap.c
+++ b/components/swap.c
_AT_@ -131,8 +131,6 @@
         #include <sys/types.h>
         #include <unistd.h>
 
- #define dbtoqb(b) dbtob((int64_t)(b))
-
         static void
         getstats(int *total, int *used)
         {
_AT_@ -162,8 +160,8 @@
                 *used = 0;
 
                 for (i = 0; i < rnswap; i++) {
- *total += dbtoqb(sep->se_nblks);
- *used += dbtoqb(sep->se_inuse);
+ *total += sep->se_nblks >> 1;
+ *used += sep->se_inuse >> 1;
                 }
 
                 free(fsep);
_AT_@ -176,7 +174,7 @@
 
                 getstats(&total, &used);
 
- return bprintf("%f", (float)(total - used) / 1024 / 1024 / 1024);
+ return bprintf("%f", (float)(total - used) / 1024 / 1024);
         }
 
         const char *
_AT_@ -196,7 +194,7 @@
 
                 getstats(&total, &used);
 
- return bprintf("%f", (float)total / 1024 / 1024 / 1024);
+ return bprintf("%f", (float)total / 1024 / 1024);
         }
 
         const char *
_AT_@ -206,6 +204,6 @@
 
                 getstats(&total, &used);
 
- return bprintf("%f", (float)used / 1024 / 1024 / 1024);
+ return bprintf("%f", (float)used / 1024 / 1024);
         }
 #endif
Received on Wed May 16 2018 - 19:18:33 CEST

This archive was generated by hypermail 2.3.0 : Wed May 16 2018 - 19:24:25 CEST