Skip to content

Commit ebe9bb4

Browse files
TehPeGaSuSflashcode
authored andcommitted
sysinfo.pl 1.2.3: fix memory used/free swapped in display and percent
memoryusage() computed $vard as actual used memory (Total - Free - Buffers - Cached), but the final return statement treated it as if it were free memory: it displayed human_size($vara-$vard) as "used" and computed the percentage as 100-($vard/($vara-$vard)*100). This mislabeled free memory as used in the output, and produced a negative percentage whenever used memory exceeded free memory (e.g. '2.83GB/7.57GB (-67.52%)' on a host where 4.74GB was actually in use). Fix by using $vard directly as used memory in both the display and the percentage calculation.
1 parent 962b42b commit ebe9bb4

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎perl/sysinfo.pl‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
#
4040
# ported to WeeChat (http://www.weechat.org/) by Nils Görs.
4141
#
42+
# 2026-09-05: 1.2.3 TehPeGaSuS <pegasus@computer4u.com>
43+
# : fix: memoryusage() showed free memory mislabeled as used, and
44+
# the percentage could go negative, because the used/free values
45+
# were swapped in the final display/percent calculation
4246
# 2026-09-05: 1.2.2 TehPeGaSuS <pegasus@computer4u.com>
4347
# : fix: memory usage broken (uninitialized values / division by 0,
4448
# closes #581) on kernel >= 6.x due to kernel version regex only
@@ -83,7 +87,7 @@
8387
use strict;
8488

8589
my $SCRIPT_NAME = "sysinfo";
86-
my $SCRIPT_VERSION = "1.2.2";
90+
my $SCRIPT_VERSION = "1.2.3";
8791
my $SCRIPT_DESCR = "provides a system info command";
8892
my $SCRIPT_LICENSE = "BSD-2-Clause";
8993
my $SCRIPT_AUTHOR = "Nils Görs <weechatter\@arcor.de>";
@@ -884,8 +888,8 @@ sub memoryusage {
884888
$vard = `vmstat -s | grep 'pages active' | awk '{print \$1}'` * `vmstat -s | grep 'per page' | awk '{print \$1}'`;
885889
$vara = `$sysctl -n hw.physmem`;
886890
}
887-
$varp = sprintf("%.2f", 100-($vard / ($vara-$vard) * 100));
888-
return human_size($vara-$vard)."/".human_size($vara)." ($varp%)";
891+
$varp = sprintf("%.2f", ($vard / $vara) * 100);
892+
return human_size($vard)."/".human_size($vara)." ($varp%)";
889893
}
890894

891895
sub networkinfobsd {

0 commit comments

Comments
 (0)