Commit e1051feb authored by Peter Pentchev's avatar Peter Pentchev

Break the output formatting out into format_line().

parent d68df680
......@@ -15,6 +15,7 @@ Change log for ethstats, the network traffic statistics utility
- use strict mode and the warnings pragma
- reflow to a tab indent
- remove the unused tquad() and toquad() functions
- break the output formatting out into format_line()
1.0 (unknown)
- released into the public domain by Drew Strieb
......
......@@ -65,6 +65,16 @@ sub acolor($)
return $COLOR? Term::ANSIColor::color($color): '';
}
sub format_line($ $ $ $ $)
{
my ($dev, $kbin, $kbout, $packin, $packout) = @_;
return ($dev eq 'total'? 'total: ': sprintf(' %6s: ', $dev)).
sprintf('%7.2f Mb/s In %7.2f Mb/s Out - '.
'%8.1f p/s In %8.1f p/s Out',
$kbin, $kbout, $packin, $packout);
}
$| = 1;
#Inter-| Receive | Transmit
......@@ -119,16 +129,13 @@ while(1) {
convert();
print time()." " if $addtime;
if ($numdevs > 1) {
print acolor 'yellow';
printf "total: %7.2f Mb/s In %7.2f Mb/s Out", $tkbin, $tkbout;
printf " - %8.1f p/s In %8.1f p/s Out", $tpackin, $tpackout;
print acolor 'reset';
print "\n";
say acolor('yellow').
format_line('total', $tkbin, $tkbout, $tpackin, $tpackout).
acolor('reset');
}
foreach my $dev(sort keys %kbin) {
printf " %4s: %7.2f Mb/s In %7.2f Mb/s Out", $dev, $kbin{$dev}, $kbout{$dev};
printf " - %8.1f p/s In %8.1f p/s Out", $packin{$dev}, $packout{$dev};
print "\n";
say format_line($dev, $kbin{$dev}, $kbout{$dev},
$packin{$dev}, $packout{$dev});
}
if (defined($count)) {
$count--;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment