From a48b8345128afd5d583ea9bda29b2edb2915bf5c Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Thu, 9 Feb 2017 12:20:57 -0800 Subject: [PATCH 1/5] getRangeSize() function added to ocnsolidate that logic --- bin/feedgnuplot | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/bin/feedgnuplot b/bin/feedgnuplot index ce3965a..c996d48 100755 --- a/bin/feedgnuplot +++ b/bin/feedgnuplot @@ -57,6 +57,17 @@ mainThread(); +sub getRangeSize +{ + my ($id) = @_; + + # I'd like to use //, but I guess some people are still on perl 5.8 + return + exists $options{rangesize_hash}{$id} ? + $options{rangesize_hash}{$id} : + $options{rangesize_default}; +} + sub interpretCommandline { # if I'm using a self-plotting data file with a #! line, then $ARGV[0] will contain ALL of the @@ -222,7 +233,10 @@ sub interpretCommandline # I now set up the rangesize to always be - # $options{rangesize_hash}{$id} // $options{rangesize_default} + # + # $options{rangesize_hash}{$id} // $options{rangesize_default} + # + # which is available as getRangeSize($id) if ( $options{rangesizeall} ) { $options{rangesize_default} = $options{rangesizeall}; @@ -749,20 +763,10 @@ sub mainThread while(@fields) { - if($options{dataid}) - { - $id = shift @fields; - } - else - { - $id++; - } - - # I'd like to use //, but I guess some people are still on perl 5.8 - my $rangesize = exists $options{rangesize_hash}{$id} ? - $options{rangesize_hash}{$id} : - $options{rangesize_default}; + if($options{dataid}) { $id = shift @fields; } + else { $id++; } + my $rangesize = getRangeSize($id); last if @fields < $rangesize; pushPoint(getCurve($id), @@ -886,12 +890,7 @@ sub updateCurveOptions # as 1 + rangesize). I also need to start the range at the first column # past the timefmt - # I'd like to use //, but I guess some people are still on perl 5.8 - my $rangesize = exists $options{rangesize_hash}{$id} ? - $options{rangesize_hash}{$id} : - $options{rangesize_default}; - - my @rest = map {$_ + $options{timefmt_Ncols}} (1..$rangesize); + my @rest = map {$_ + $options{timefmt_Ncols}} (1..getRangeSize($id)); $usingoptions = "using 1:" . join(':', @rest); } From 7da37a0015fd90963a1295a5485725f46da1a050 Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Thu, 9 Feb 2017 12:21:46 -0800 Subject: [PATCH 2/5] better sanity checking for histogram options --- bin/feedgnuplot | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/bin/feedgnuplot b/bin/feedgnuplot index c996d48..4e5cb17 100755 --- a/bin/feedgnuplot +++ b/bin/feedgnuplot @@ -295,6 +295,13 @@ sub interpretCommandline $options{curvestyleall} .= ' palette'; } + if ( defined $options{binwidth} && !@{$options{histogram}} ) + { + print STDERR "--binwidth doesn't make sense without any histograms\n"; + exit -1; + } + + if ( $options{'3d'} ) { if ( !$options{domain} ) @@ -327,7 +334,7 @@ sub interpretCommandline exit -1; } - if ( defined $options{binwidth} || @{$options{histogram}} ) + if ( @{$options{histogram}} ) { print STDERR "--3d does not make sense with histograms\n"; exit -1; @@ -361,6 +368,16 @@ sub interpretCommandline print STDERR "--square_xy only makes sense with --3d\n"; exit -1; } + + for my $hist_curve(@{$options{histogram}}) + { + my $hist_dim = getRangeSize($hist_curve); + if( $hist_dim != 1 ) + { + print STDERR "I only support 1D histograms, but curve '$hist_curve' has '$hist_dim'-D data\n"; + exit -1; + } + } } if(defined $options{xlen} && !$options{stream} ) @@ -921,6 +938,22 @@ sub getCurve $curveIndices{$id} = $#curves; updateCurveOptions($curves[$#curves], $id); + + + # --xlen has a meaning if we're not plotting histograms at all or if we're + # plotting ONLY histograms. If we're doing both at the same time, there's no + # consistent way to assign meaning to xlen + if ( defined $options{xlen} && + + # have at least some histograms + @{$options{histogram}} && + + # there are more curves than histogram curves, i.e. there're some + # non-histogram curves + @curves > @{$options{histogram}} ) { + print STDERR "--xlen only makes sense when plotting ONLY histograms or ONLY NON-histograms\n"; + exit -1; + } } return $curves[$curveIndices{$id}]; } From 402fa32bda28fd44ac035e7e4ed1e7a0418bbada Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Thu, 9 Feb 2017 12:27:03 -0800 Subject: [PATCH 3/5] histograms work as expected with --xlen and --monotonic --- bin/feedgnuplot | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/bin/feedgnuplot b/bin/feedgnuplot index 4e5cb17..8631195 100755 --- a/bin/feedgnuplot +++ b/bin/feedgnuplot @@ -981,6 +981,10 @@ sub setCurveAsHistogram my ($id, $str) = @_; my $curve = getCurve($id); + + # With histograms I have 2d plots with rangesize=1. I thus give gnuplot two + # values for each point: a domain and a range. For histograms I ignore the + # domain, so I get the statistics of the 2nd column: $2 $curve->{histoptions} = 'using (histbin($2)):(1.0) smooth ' . $options{histstyle}; updateCurveOptions($curve, $id); @@ -1048,7 +1052,11 @@ sub replot # seconds-since-the-epoch BACK to the timefmt. Sheesh ($xmin, $xmax) = map {Time::Piece->strptime( $_, '%s' )->strftime( $options{timefmt} ) } ($xmin, $xmax); } - sendRangeCommand( "xrange", $xmin, $xmax ); + + # if we have any histograms, then I'm not really visualizing the domain at + # all, and I don't set the range. + sendRangeCommand( "xrange", $xmin, $xmax ) + unless @{$options{histogram}}; } plotStoredData(); @@ -1297,7 +1305,12 @@ windowsize> can be given. This will create an constantly-updating, scrolling view of the recent past. C should be replaced by the desired length of the domain window to plot, in domain units (passed-in values if C<--domain> or line numbers otherwise). If the domain is a time/date via C<--timefmt>, then -C is and I in seconds. +C is and I in seconds. If we're plotting a histogram, then +C<--xlen> causes a histogram over a moving window to be computed. The subtlely +here is that with a histogram you don't actually I the domain since only +the range is analyzed. But the domain is still there, and can be utilized with +C<--xlen>. With C<--xlen> we can plot I histograms or I +I-histograms. =head3 Special data commands @@ -1531,7 +1544,12 @@ C<--xlen xxx> When using C<--stream>, sets the size of the x-window to plot. Omit this or set it to 0 to plot ALL the data. Does not make sense with 3d plots. Implies -C<--monotonic> +C<--monotonic>. If we're plotting a histogram, then C<--xlen> causes a histogram +over a moving window to be computed. The subtlely here is that with a histogram +you don't actually I the domain since only the range is analyzed. But the +domain is still there, and can be utilized with C<--xlen>. With C<--xlen> we can +plot I histograms or I I-histograms. + =item @@ -1573,8 +1591,9 @@ specified for this curve (C<--curvestyle>) or all curves (C<--with>, C<--curvestyleall>) then the default histogram style is set: filled boxes with borders. This is what the user generally wants. This works with C<--domain> and/or C<--stream>, but in those cases the x-value is used I to cull old -data because of C<--xlen> or C<--monotonic>. I.e. the x-values are I drawn -in any way. Can be passed multiple times, or passed a comma- separated list +data because of C<--xlen> or C<--monotonic>. I.e. the domain values are I +drawn in any way. Can be passed multiple times, or passed a comma- separated +list =item @@ -1915,6 +1934,17 @@ in a Thinkpad. --binwidth 10 --ymin 0 --xlabel 'File size (MB)' --ylabel Frequency +=head2 Plotting a live histogram of the ping round-trip times for the past 20 seconds + + $ ping -A -D 8.8.8.8 | + perl -anE 'BEGIN { $| = 1; } + $F[0] =~ s/[\[\]]//g or next; + $F[7] =~ s/.*=//g or next; + say "$F[0] $F[7]"' | + feedgnuplot --stream --domain --histogram 0 --binwidth 10 \ + --xlabel 'Ping round-trip time (s)' \ + --ylabel Frequency --xlen 20 + =head2 Plotting points on top of an existing image This can be done by using C<--equation> to pass arbitrary plot input to gnuplot: From 64b12e47381afebf05da6aa32e8308b1b2a53845 Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Thu, 9 Feb 2017 19:12:18 -0800 Subject: [PATCH 4/5] When plotting histograms, --xlen can coexist with --xmin/--xmax --- bin/feedgnuplot | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/feedgnuplot b/bin/feedgnuplot index 8631195..9086eeb 100755 --- a/bin/feedgnuplot +++ b/bin/feedgnuplot @@ -387,7 +387,8 @@ sub interpretCommandline } if($options{stream} && defined $options{xlen} && - ( defined $options{xmin} || defined $options{xmax})) + ( defined $options{xmin} || defined $options{xmax}) && + !defined $options{histogram}) { print STDERR "With --stream and --xlen the X bounds are set, so neither --xmin nor --xmax make sense\n"; exit -1; From a0c9e6e8bc3fca4a3be08262518a0ff1cacc08cc Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Fri, 24 Feb 2017 23:44:20 -0800 Subject: [PATCH 5/5] version bump --- Changes | 8 ++++++++ bin/feedgnuplot | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 012010d..68f8a1b 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,11 @@ +feedgnuplot (1.41) + + * Histograms: --xlen can coexist with --xmin/--xmax + * Histograms: work as expected with --xlen and --monotonic + * Histograms: better sanity checking of options + + -- Dima Kogan Fri, 24 Feb 2017 23:42:28 -0800 + feedgnuplot (1.40) * If the options couldn't be parsed I don't dump the whole manpage diff --git a/bin/feedgnuplot b/bin/feedgnuplot index 9086eeb..6d4c5f5 100755 --- a/bin/feedgnuplot +++ b/bin/feedgnuplot @@ -15,7 +15,7 @@ use Text::ParseWords; # for shellwords use Pod::Usage; use Time::Piece; -my $VERSION = 1.40; +my $VERSION = 1.41; my %options; interpretCommandline();