#!/usr/bin/perl -w # # Quick 'n' dirty plotting of the free.csv report. use strict; use English; BEGIN { # Argument processing. if (@ARGV == 2 and $ARGV[1] =~ /\D/) { # free_plot.pl 123 file.csv # Yuck, because the 'missing' value could be either top limit. die "Arguments '@ARGV' too hard to interpret: use 'NNN NNN file.c +sv'\n" } elsif (@ARGV == 1 and $ARGV[0] =~ /\D/) { # free_plot.pl file.csv # Stick in a couple of empty strings to get the TOP_* constants to + work. unshift @ARGV, '',''; } } my $screen; # screen control panel use constant TERM_SIZE => 75; # how big is the screen? use constant TIME_FLD => 6; # how wide is the time display? use constant TOP_LOAD => shift || 20; # scale factor for load a +verage use constant TOP_BUFF => shift || 20000; # scale factor for buffer +size INIT { { no warnings; require Term::Screen; } # Set up the screen. $screen = Term::Screen->new() or die "Something's wrong with Term::S +creen"; $screen->clrscr(); $screen->at(0,TIME_FLD)->puts(join('', '|----' x (TERM_SIZE/5), '*/L' . TOP_LOAD, ' o/F+/B' . TOP_BUFF, ) ); } END { # Cleanup. $screen->at($screen->{ROWS}-1, 0); } $|++; # no buffered output # Ctrl-C handler. $SIG{INT} = sub { exit }; # Do we have a filename to read? if (my $file = shift) { open(INPUT, $file) or die $!; } else { open(INPUT, "<&STDIN") or die $!; } while (<INPUT>) { # process all the input # CSV file has 'time,loadavg,junk,buff,...' my($time,$load,$buff,$free) = (split /,/)[0,1,3,10]; next if ($load . $buff . $free) =~ /[^\d\.]/; $screen->at(1,0)->il; # new line after the axis $time =~ s/\D//g; # reduce time to HHMMSS $time =~ s/.*(\d{6})$/$1/; $screen->at(1,0)->puts($time); $_ ||= 0E0 # for old format CSV with missing fields foreach ($load,$buff,$free); # create scaling my $load_sp = min(TERM_SIZE, TERM_SIZE * ($load/TOP_LOAD)); my $buff_sp = min(TERM_SIZE, TERM_SIZE * ($buff/TOP_BUFF)); my $free_sp = min(TERM_SIZE, TERM_SIZE * ($free/TOP_BUFF)); if ($load_sp == $buff_sp) { # The overlap case. $screen->at(1,TIME_FLD+$load_sp)->puts('X'); } else { # The normal case. $screen->at(1,TIME_FLD+$load_sp)->puts('*'); if ($buff_sp == $free_sp) { $screen->at(1,TIME_FLD+$buff_sp)->puts('x'); } else { $screen->at(1,TIME_FLD+$buff_sp)->puts('+'); $screen->at(1,TIME_FLD+$free_sp)->puts('o'); } } } sub min { my @list = grep(defined,@_); return $list[0] unless @list > 1; return (sort {$a <=> $b} @list)[0]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Quick 'n' dirty plotting
by zentara (Cardinal) on Nov 13, 2002 at 14:52 UTC | |
by Mur (Pilgrim) on Nov 15, 2002 at 21:20 UTC | |
|
Re: Quick 'n' dirty plotting
by petral (Curate) on Nov 13, 2002 at 17:27 UTC |