#!/usr/bin/env perl
open STDIN, "vmstat -z |" or die "Failed to run vmstat program";
open STDOUT, "| sort -n @ARGV -k 2" or die "Failed to pipe through sort";
$fmt="%-30s %8.3f %8.3f %8.3f %6.1f%%\n";
while (<STDIN>) {
    ($n, $s, undef, $u, $c) = split /[:,] */;
    next unless $s > 0;
    $n =~ s/ /_/g;
    $s /= 1024 * 1024;
    $u *= $s;
    $c *= $s;
    $t =  $u + $c;
    next unless $t > 0;
    printf $fmt, $n, $t, $u, $c, 100 * $c / $t;
    $cache += $c;
    $used  += $u;
    $total += $t;
}
printf $fmt, TOTAL, $total, $used, $cache, 100 * $cached / $total;
close STDOUT;
