rehauled drivegnuplot, support all-at-once plotting as a cmdline option

Ignore-this: 77ef24b11e28017f77c9a2015701d73c

darcs-hash:20090209111726-0cb85-ac339192253c86d402a4486152ee3f9babcf5bcf.gz
This commit is contained in:
Dima Kogan 2009-02-09 03:17:26 -08:00
parent 855a0d5583
commit 44c2d22c59

View File

@ -1,10 +1,15 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
use strict; use strict;
use Getopt::Long; use Getopt::Long;
use Data::Dumper;
# stream in the data by default
# point plotting by default # point plotting by default
my %options = ( "lines" => 0); my %options = ( "stream" => 1,
"lines" => 0);
GetOptions(\%options, GetOptions(\%options,
"stream!",
"lines!"); "lines!");
# set up plotting style # set up plotting style
@ -32,14 +37,6 @@ sub Arg {
$ARGV[int($_[0])]; $ARGV[int($_[0])];
} }
sub plotHeader
{
my ($xcounter, $samples, $numberOfStreams, $pipe) = @_;
#print "stream $streamIdx: ";
print $pipe "set xrange [".($xcounter-$samples).":".($xcounter+1)."]\n";
print $pipe 'plot ' . join(', ' , ('"-" notitle') x $numberOfStreams) . "\n";
}
sub main { sub main {
my $argIdx = 0; my $argIdx = 0;
my $numberOfStreams = Arg($argIdx++); my $numberOfStreams = Arg($argIdx++);
@ -69,44 +66,64 @@ sub main {
print PIPE "set grid\n"; print PIPE "set grid\n";
for(my $i=0; $i<$numberOfStreams; $i++) { for(my $i=0; $i<$numberOfStreams; $i++) {
my @data = []; push @buffers, [];
push @buffers, @data;
} }
my $streamIdx = 0; my $streamIdx = 0;
select((select(STDOUT), $| = 1)[0]); select((select(STDOUT), $| = 1)[0]);
my $xcounter = 0; my $xlast = 0;
while(<>) { while(<>)
chomp; {
my $line = $_; chomp;
plotHeader($xcounter, $samples, $numberOfStreams, *PIPE) if($streamIdx == 0); my $line = $_;
foreach my $point ($line =~ /([-]?[0-9\.]+)/g) foreach my $point ($line =~ /([-]?[0-9\.]+)/g) {
{ my $buf = $buffers[$streamIdx];
my $buf = $buffers[$streamIdx];
# data buffering (up to stream sample size) # data buffering (up to stream sample size)
push @{$buf}, $point; push @{$buf}, $point;
shift @{$buf} if(@{$buf} > $samples && $options{"stream"});
my $cnt = 0; $streamIdx++;
for my $elem (reverse @{$buf}) { if ($streamIdx == $numberOfStreams) {
#print " ".$elem; $streamIdx = 0;
print PIPE ($xcounter-$cnt)." ".$elem."\n"; plotStoredData($xlast, $samples, $numberOfStreams, *PIPE, \@buffers) if($options{"stream"});
$cnt++; $xlast++;
}
#print "\n";
print PIPE "e\n";
if ($cnt>=$samples) {
shift @{$buf};
}
$streamIdx++;
if ($streamIdx == $numberOfStreams) {
$streamIdx = 0;
$xcounter++;
}
} }
}
} }
print PIPE "exit;\n";
close PIPE; if($options{"stream"})
{
print PIPE "exit;\n";
close PIPE;
}
else
{
$samples = @{$buffers[0]};
plotStoredData($xlast, $samples, $numberOfStreams, *PIPE, \@buffers);
}
sleep 100000;
} }
sub plotStoredData
{
my ($xlast, $samples, $numberOfStreams, $pipe, $buffers) = @_;
my $x0 = $xlast - $samples + 1;
print $pipe "set xrange [$x0:$xlast]\n";
print $pipe 'plot ' . join(', ' , ('"-" notitle') x $numberOfStreams) . "\n";
foreach my $buf (@{$buffers})
{
# if the buffer isn't yet complete, skip the appropriate number of points
my $x = $x0 + $samples - @{$buf};
for my $elem (@{$buf}) {
print $pipe "$x $elem\n";
$x++;
}
print PIPE "e\n";
}
}
main; main;