From f0c0563760797f0557d3804297f229a33efee5a3 Mon Sep 17 00:00:00 2001 From: hadaq Date: Fri, 26 Feb 2021 14:32:15 +0100 Subject: [PATCH] add forked draw function to HPlot --- tools/HPlot.pm | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/tools/HPlot.pm b/tools/HPlot.pm index 01565f1..3080cfe 100755 --- a/tools/HPlot.pm +++ b/tools/HPlot.pm @@ -28,14 +28,14 @@ sub plot_write { } else { print $file $str."\n"; -# print $str."\n"; + # print $str."\n"; } if(defined $save) {$plotstring->{$save} .= $str;} } sub makeTimeString{ - return strftime("set label 100 \"%H:%M:%S\" at screen 0.02,0.02 left tc rgb \"#000044\" font \"monospace,8\"\n", localtime()) + return strftime("set label 100 \"%H:%M:%S\" at screen 0.99,0.02 right tc rgb \"#000044\" font \"monospace,8\"\n", localtime()) } sub setranges { @@ -56,7 +56,8 @@ sub PlotInit { my $name = $c->{name}; - my $fn = "gnuplot 2>1"; + my $fn = "gnuplot 2>&1"; + #my $fn = "gnuplot"; #my $fh = new FileHandle ("|$fn") or die "error: no gnuplot"; open my $fh, "|$fn" or die "error: no gnuplot"; $fh->autoflush(1); @@ -236,9 +237,22 @@ sub PlotInit { } +sub PlotDrawFork { + my($name) = @_; + waitpid($p->{$name}->{pid},0) if $p->{$name}->{pid}; + my $pid = fork; + unless ($pid) {PlotDraw($name);exit;} + $p->{$name}->{pid} = $pid; + $p->{$name}->{run}++; +} + sub PlotDraw { my($name) = @_; + if(!defined $p->{$name}) { + print "PlotDraw called with non existing plot name: \"$name\", typo? Exiting!\n"; + exit; + } if($p->{$name}->{buffer} && -e $p->{$name}->{file}."tmp.png") { rename $p->{$name}->{file}."tmp.png", $p->{$name}->{file}.".png"; } @@ -270,10 +284,10 @@ sub PlotDraw { for(my $j=0; $j<$p->{$name}->{curves}; $j++) { for(my $i=$p->{$name}->{entries}-$realentries; $i< $p->{$name}->{entries}; $i++) { plot_write($p->{$name}->{fh},' '.(($p->{$name}->{value}->[$j]->[$i]||0)/($p->{$name}->{yscale}||1))); #?? maybe without ||0 - } - plot_write($p->{$name}->{fh},"e"); } + plot_write($p->{$name}->{fh},"e"); } + } if($p->{$name}->{type} == TYPE_HEATMAP) { @@ -315,7 +329,12 @@ sub PlotDraw { sub PlotAdd { my($name,$value,$curve) = @_; + if(!defined $p->{$name}) { + print "PlotAdd called with non existing plot name: \"$name\", typo? Exiting!\n"; + exit; + } $curve = 0 unless $curve; + #print Dumper $p; push(@{$p->{$name}->{value}->[$curve]},$value||0); shift(@{$p->{$name}->{value}->[$curve]}); @@ -323,6 +342,11 @@ sub PlotAdd { sub PlotFill { my($name,$value,$slot,$curve,$add) = @_; + if(!defined $p->{$name}) { + print "PlotFill called with non existing plot name: \"$name\", typo? Exiting!\n"; + exit; + } + $curve = 0 unless $curve; if($add) { $p->{$name}->{value}->[$curve]->[$slot] += $value||0; -- 2.43.0