1abb0f93cSkardel#! @PATH_PERL@ -w 2*eabc0478Schristos# @configure_input@ 3cdfa2a7eSchristos# Id 4abb0f93cSkardel# 5abb0f93cSkardel# Use Gnuplot to display data in summary files produced by summary.pl. 6abb0f93cSkardel# This script requires GNUPLOT 3.7! 7abb0f93cSkardel# 8abb0f93cSkardel# Copyright (c) 1997, 1999 by Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de> 9abb0f93cSkardel# 10abb0f93cSkardel# This program is free software; you can redistribute it and/or modify 11abb0f93cSkardel# it under the terms of the GNU General Public License as published by 12abb0f93cSkardel# the Free Software Foundation; either version 2 of the License, or 13abb0f93cSkardel# (at your option) any later version. 14abb0f93cSkardel# 15abb0f93cSkardel# This program is distributed in the hope that it will be useful, but 16abb0f93cSkardel# WITHOUT ANY WARRANTY; without even the implied warranty of 17abb0f93cSkardel# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18abb0f93cSkardel# General Public License for more details. 19abb0f93cSkardel# 20abb0f93cSkardel# You should have received a copy of the GNU General Public License 21abb0f93cSkardel# along with this program; if not, write to the Free Software 22abb0f93cSkardel# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 238585484eSchristospackage plot_summary; 248585484eSchristosuse 5.006_000; 25abb0f93cSkardeluse strict; 26abb0f93cSkardeluse Time::Local; 27abb0f93cSkardel 288585484eSchristosmy ($identifier, $offset_limit, $gnuplot_terminal, $wait_after_plot, 298585484eSchristos $output_file, $output_file_number); 30abb0f93cSkardel 318585484eSchristosexit run(@ARGV) unless caller; 32abb0f93cSkardel 338585484eSchristossub run { 348585484eSchristos my $opts; 358585484eSchristos if (!processOptions(\@_, $opts)) { 368585484eSchristos usage(1); 37abb0f93cSkardel } 38abb0f93cSkardel 398585484eSchristos $identifier = $opts->{'identifier'}; 408585484eSchristos if (!$identifier) { 418585484eSchristos $identifier = "host".`hostname`; 42abb0f93cSkardel chomp $identifier; 438585484eSchristos } 448585484eSchristos $offset_limit = $opts->{'offset-limit'}; 458585484eSchristos $output_file = $opts->{'output-file'}; 468585484eSchristos $output_file_number = 1; 478585484eSchristos $gnuplot_terminal = $opts->{'plot-terminal'} 488585484eSchristos || ( $ENV{DISPLAY} ? "x11" : "dumb" ); 498585484eSchristos $wait_after_plot = !$opts->{'dont-wait'}; 508585484eSchristos 51abb0f93cSkardel die "illegal offset-limit: $offset_limit" unless $offset_limit > 0.0; 52abb0f93cSkardel $offset_limit *= 1e6; # scale to microseconds 53abb0f93cSkardel 548585484eSchristos my $summary_dir = $opts->{'directory'}; 558585484eSchristos 568585484eSchristos my $loop_summary ="$summary_dir/loop_summary"; 578585484eSchristos my $peer_summary ="$summary_dir/peer_summary"; 588585484eSchristos my $clock_summary="$summary_dir/clock_summary"; 598585484eSchristos 608585484eSchristos my @peer_list = @{$opts->{'peer'}}; 618585484eSchristos 628585484eSchristos do_loop($loop_summary); 638585484eSchristos do_peer($peer_summary, $_) for @peer_list; 648585484eSchristos} 658585484eSchristos 66abb0f93cSkardel# return the smallest value in the given list 67abb0f93cSkardelsub min 68abb0f93cSkardel{ 69abb0f93cSkardel my ($result, @rest) = @_; 70abb0f93cSkardel map { $result = $_ if ($_ < $result) } @rest; 71abb0f93cSkardel return($result); 72abb0f93cSkardel} 73abb0f93cSkardel 74abb0f93cSkardel# return the largest value in the given list 75abb0f93cSkardelsub max 76abb0f93cSkardel{ 77abb0f93cSkardel my ($result, @rest) = @_; 78abb0f93cSkardel map { $result = $_ if ($_ > $result) } @rest; 79abb0f93cSkardel return($result); 80abb0f93cSkardel} 81abb0f93cSkardel 82abb0f93cSkardel# maybe open alternate output file 83abb0f93cSkardelsub open_output 84abb0f93cSkardel{ 85abb0f93cSkardel my $file; 86abb0f93cSkardel if ($output_file) { 87abb0f93cSkardel while ( -r ($file = "$output_file$output_file_number") ) { 88abb0f93cSkardel ++$output_file_number; 89abb0f93cSkardel } 90abb0f93cSkardel open TOUCH, ">$file" and close TOUCH or die "$file: $!"; 91abb0f93cSkardel print "set output \"$file\"\n"; 92abb0f93cSkardel } 93abb0f93cSkardel} 94abb0f93cSkardel 95abb0f93cSkardel# make Gnuplot wait 96abb0f93cSkardelsub maybe_add_pause 97abb0f93cSkardel{ 98abb0f93cSkardel print "pause -1 \"Press key to continue...\"\n" if $wait_after_plot; 99abb0f93cSkardel} 100abb0f93cSkardel 101abb0f93cSkardel# plot data from loop summary 102abb0f93cSkardelsub do_loop 103abb0f93cSkardel{ 104abb0f93cSkardel my $fname = shift; 105abb0f93cSkardel my $line; 106abb0f93cSkardel my $out_file = "/tmp/tempdata$$"; 107abb0f93cSkardel my $cmd_file = "/tmp/tempcmd$$"; 108abb0f93cSkardel my ($first_day, $day_out) = ("", 0); 109abb0f93cSkardel my ($lower_bound, $upper_bound, $rms); 110abb0f93cSkardel my ($min_offs, $max_offs) = (1e9, -1e9); 111abb0f93cSkardel my ($min_rms, $max_rms) = (1e9, -1e9); 112abb0f93cSkardel open INPUT, "$fname" or die "$fname: $!"; 113abb0f93cSkardel open OUTPUT, ">$out_file" or die "$out_file: $!"; 114abb0f93cSkardel my @Fld; 115abb0f93cSkardel while (<INPUT>) { 116abb0f93cSkardel chop; # strip record separator 117abb0f93cSkardel @Fld = split; 118abb0f93cSkardel if ($#Fld == 0) { 119abb0f93cSkardel# loops.19960405 120abb0f93cSkardel $_ = $Fld[0]; s/.*([12]\d{3}[01]\d[0-3]\d)$/$1/; 121abb0f93cSkardel m/(\d{4})(\d{2})(\d{2})/; 122abb0f93cSkardel $line = timegm(59, 59, 23, $3, $2 - 1, $1 - 1900, 0, 0, 0); 123abb0f93cSkardel $line = int $line / 86400; # days relative to 1970 124abb0f93cSkardel $first_day = "$1-$2-$3 ($line)" unless $day_out; 125abb0f93cSkardel next; 126abb0f93cSkardel } 127abb0f93cSkardel if ($#Fld != 8) { 128abb0f93cSkardel warn "Illegal number of fields in file $fname, line $."; 129abb0f93cSkardel next; 130abb0f93cSkardel } 131abb0f93cSkardel# loop 216, 856106+/-874041.5, rms 117239.8, freq 67.52+/-10.335, var 4.850 132abb0f93cSkardel $_ = $Fld[1]; s/,/ /; $line .= " $_"; 133abb0f93cSkardel $_ = $Fld[2]; m:(.+?)\+/-(.+),:; 134abb0f93cSkardel $lower_bound = $1 - $2; 135abb0f93cSkardel $upper_bound = $1 + $2; 136abb0f93cSkardel $line .= "$1 $lower_bound $upper_bound"; 137abb0f93cSkardel $min_offs = min($min_offs, $lower_bound); 138abb0f93cSkardel $max_offs = max($max_offs, $upper_bound); 139abb0f93cSkardel $_ = $Fld[4]; s/,/ /; $rms = $_; 140abb0f93cSkardel $min_rms = min($min_rms, $rms); 141abb0f93cSkardel $max_rms = max($max_rms, $rms); 142abb0f93cSkardel $line .= " $rms"; 143abb0f93cSkardel $_ = $Fld[6]; m:(.+?)\+/-(.+),:; 144abb0f93cSkardel $line .= " $1 " . ($1-$2) . " " . ($1+$2); 145abb0f93cSkardel $line .= " $Fld[8]"; 146abb0f93cSkardel print OUTPUT "$line\n"; 147abb0f93cSkardel $day_out = 1; 148abb0f93cSkardel# 9621 216 856106 -17935.5 1730147.5 117239.8 67.52 57.185 77.855 4.850 149abb0f93cSkardel } 150abb0f93cSkardel close INPUT; 151abb0f93cSkardel close OUTPUT or die "close failed on $out_file: $!"; 152abb0f93cSkardel my $ylimit = "["; 153abb0f93cSkardel if ($min_offs < -$offset_limit) { 154abb0f93cSkardel $ylimit .= "-$offset_limit"; 155abb0f93cSkardel } 156abb0f93cSkardel $ylimit .= ":"; 157abb0f93cSkardel if ($max_offs > $offset_limit) { 158abb0f93cSkardel $ylimit .= "$offset_limit"; 159abb0f93cSkardel } 160abb0f93cSkardel if ( $ylimit eq "[:" ) { 161abb0f93cSkardel $ylimit = ""; 162abb0f93cSkardel } else { 163abb0f93cSkardel $ylimit = "[] $ylimit]"; 164abb0f93cSkardel } 165abb0f93cSkardel# build command file for GNUplot 166abb0f93cSkardel open OUTPUT, "> $cmd_file" or die "$cmd_file: $!"; 167abb0f93cSkardel my $oldfh = select OUTPUT; 168abb0f93cSkardel print "set term $gnuplot_terminal\n"; 169abb0f93cSkardel open_output; 170abb0f93cSkardel print "set grid\n"; 171abb0f93cSkardel print "set title \"Loop Summary for $identifier: " . 172abb0f93cSkardel "Daily mean values since $first_day\\n" . 173abb0f93cSkardel "(Offset limit is $offset_limit microseconds)\"\n"; 174abb0f93cSkardel print "set ylabel \"[us]\"\n"; 1758585484eSchristos print "set style data yerrorbars\n"; 176abb0f93cSkardel print "set multiplot\n"; 177abb0f93cSkardel print "set size 1, 0.5\n"; 178abb0f93cSkardel print "set lmargin 8\n"; 179abb0f93cSkardel print "set origin 0, 0.5\n"; 180abb0f93cSkardel print "plot $ylimit \"$out_file\"" . 181abb0f93cSkardel " using 1:3:4:5 title \"mean offset\", "; 182abb0f93cSkardel print "\"$out_file\" using 1:(\$3-\$6/2) " . 183abb0f93cSkardel "title \"(sigma low)\" with lines, "; 184abb0f93cSkardel print "\"$out_file\" using 1:3 smooth bezier " . 185abb0f93cSkardel "title \"(Bezier med)\" with lines, "; 186abb0f93cSkardel print "\"$out_file\" using 1:(\$3+\$6/2) " . 187abb0f93cSkardel "title \"(sigma high)\" with lines\n"; 188abb0f93cSkardel print "set ylabel \"[ppm]\"\n"; 189abb0f93cSkardel print "set origin 0, 0.0\n"; 190abb0f93cSkardel print "set title\n"; 191abb0f93cSkardel print "set xlabel \"Days relative to 1970\"\n"; 192abb0f93cSkardel print "plot \"$out_file\" using 1:7:8:9 title \"mean frequency\", "; 193abb0f93cSkardel print "\"$out_file\" using 1:(\$7-\$10/2) " . 194abb0f93cSkardel "title \"(sigma low)\" with lines, "; 195abb0f93cSkardel print "\"$out_file\" using 1:7 smooth bezier " . 196abb0f93cSkardel "title \"(Bezier med)\" with lines, "; 197abb0f93cSkardel print "\"$out_file\" using 1:(\$7+\$10/2) " . 198abb0f93cSkardel "title \"(sigma high)\" with lines\n"; 199abb0f93cSkardel print "set nomultiplot\n"; 200abb0f93cSkardel maybe_add_pause; 201abb0f93cSkardel 202abb0f93cSkardel $ylimit = "["; 203abb0f93cSkardel if ($min_rms < -$offset_limit) { 204abb0f93cSkardel $ylimit .= "-$offset_limit"; 205abb0f93cSkardel } 206abb0f93cSkardel $ylimit .= ":"; 207abb0f93cSkardel if ($max_rms > $offset_limit) { 208abb0f93cSkardel $ylimit .= "$offset_limit"; 209abb0f93cSkardel } 210abb0f93cSkardel if ( $ylimit eq "[:" ) { 211abb0f93cSkardel $ylimit =""; 212abb0f93cSkardel } else { 213abb0f93cSkardel $ylimit = "[] $ylimit]"; 214abb0f93cSkardel } 215abb0f93cSkardel 216abb0f93cSkardel open_output; 217abb0f93cSkardel print "set title \"Loop Summary for $identifier: " . 218abb0f93cSkardel "Standard deviation since $first_day\\n" . 219abb0f93cSkardel "(Offset limit is $offset_limit microseconds)\"\n"; 220abb0f93cSkardel print "set xlabel\n"; 221abb0f93cSkardel print "set ylabel \"[us]\"\n"; 222abb0f93cSkardel print "set origin 0, 0.5\n"; 2238585484eSchristos print "set style data linespoints\n"; 224abb0f93cSkardel print "set multiplot\n"; 225abb0f93cSkardel print "plot $ylimit \"$out_file\" using 1:6 title \"Offset\", "; 226abb0f93cSkardel print "\"$out_file\" using 1:6 smooth bezier " . 227abb0f93cSkardel "title \"(Bezier)\" with lines\n"; 228abb0f93cSkardel print "set title\n"; 229abb0f93cSkardel print "set origin 0, 0.0\n"; 230abb0f93cSkardel print "set xlabel \"Days relative to 1970\"\n"; 231abb0f93cSkardel print "set ylabel \"[ppm]\"\n"; 232abb0f93cSkardel print "plot \"$out_file\" using 1:10 title \"Frequency\", "; 233abb0f93cSkardel print "\"$out_file\" using 1:10 smooth bezier " . 234abb0f93cSkardel "title \"(Bezier)\" with lines\n"; 235abb0f93cSkardel print "set nomultiplot\n"; 236abb0f93cSkardel maybe_add_pause; 237abb0f93cSkardel 238abb0f93cSkardel close OUTPUT or die "close failed on $cmd_file: $!"; 239abb0f93cSkardel select $oldfh; 240abb0f93cSkardel print `gnuplot $cmd_file`; 241abb0f93cSkardel unlink $cmd_file; 242abb0f93cSkardel unlink $out_file; 243abb0f93cSkardel} 244abb0f93cSkardel 245abb0f93cSkardel# plot data form peer summary 246abb0f93cSkardelsub do_peer 247abb0f93cSkardel{ 248abb0f93cSkardel my $fname = shift; 249abb0f93cSkardel my $peer = shift; 250abb0f93cSkardel my $out_file = "/tmp/tempdata$$"; 251abb0f93cSkardel my $cmd_file = "/tmp/tempcmd$$"; 252abb0f93cSkardel my $line; 253abb0f93cSkardel my ($first_day, $day_out) = ("", 0); 254abb0f93cSkardel open INPUT, "$fname" or die "$fname: $!"; 255abb0f93cSkardel open OUTPUT, ">$out_file" or die "$out_file: $!"; 256abb0f93cSkardel my @Fld; 257abb0f93cSkardel while (<INPUT>) { 258abb0f93cSkardel chop; # strip record separator 259abb0f93cSkardel @Fld = split; 260abb0f93cSkardel if ($#Fld == 0) { 261abb0f93cSkardel# peers.19960405 262abb0f93cSkardel $_ = $Fld[0]; s/.*([12]\d{3}[01]\d[0-3]\d)$/$1/; 263abb0f93cSkardel m/(\d{4})(\d{2})(\d{2})/ or next; 264abb0f93cSkardel $line = timegm(59, 59, 23, $3, $2 - 1, $1 - 1900, 0, 0, 0); 265abb0f93cSkardel $line = int $line / 86400; # days relative to 1970 266abb0f93cSkardel $first_day = "$1-$2-$3 ($line)" unless $day_out; 267abb0f93cSkardel next; 268abb0f93cSkardel } 269abb0f93cSkardel if ($#Fld != 7) { 270abb0f93cSkardel warn "Illegal number of fields in file $fname, line $."; 271abb0f93cSkardel next; 272abb0f93cSkardel } 273abb0f93cSkardel next if ($Fld[0] ne $peer); 274abb0f93cSkardel# ident cnt mean rms max delay dist disp 275abb0f93cSkardel# 127.127.8.1 38 30.972 189.867 1154.607 0.000 879.760 111.037 276abb0f93cSkardel $Fld[0] = $line; 277abb0f93cSkardel print OUTPUT join(' ', @Fld) . "\n"; 278abb0f93cSkardel# 9969 38 30.972 189.867 1154.607 0.000 879.760 111.037 279abb0f93cSkardel $day_out = 1; 280abb0f93cSkardel } 281abb0f93cSkardel close INPUT; 282abb0f93cSkardel close OUTPUT or die "close failed on $out_file: $!"; 283abb0f93cSkardel die "no data found for peer $peer" if !$day_out; 284abb0f93cSkardel open OUTPUT, "> $cmd_file" or die "$cmd_file: $!"; 285abb0f93cSkardel my $oldfh = select OUTPUT; 286abb0f93cSkardel print "set term $gnuplot_terminal\n"; 287abb0f93cSkardel open_output; 288abb0f93cSkardel print "set grid\n"; 289abb0f93cSkardel print "set multiplot\n"; 290abb0f93cSkardel print "set lmargin 8\n"; 291abb0f93cSkardel print "set size 1, 0.34\n"; 292abb0f93cSkardel print "set origin 0, 0.66\n"; 293abb0f93cSkardel print "set title " . 294abb0f93cSkardel "\"Peer Summary for $peer on $identifier since $first_day\"\n"; 2958585484eSchristos print "set style data linespoints\n"; 296abb0f93cSkardel print "set ylabel \"[us]\"\n"; 297abb0f93cSkardel print "plot \"$out_file\" using 1:3 title \"mean offset\", "; 298abb0f93cSkardel print "\"$out_file\" using 1:3 smooth bezier " . 299abb0f93cSkardel "title \"(Bezier)\" with lines, "; 300abb0f93cSkardel print "\"$out_file\" using 1:(\$3-\$7/2) " . 301abb0f93cSkardel "title \"(sigma low)\" with lines, "; 302abb0f93cSkardel print "\"$out_file\" using 1:(\$3+\$7/2) " . 303abb0f93cSkardel "title \"(sigma high)\" with lines\n"; 304abb0f93cSkardel print "set title\n"; 305abb0f93cSkardel print "set origin 0, 0.34\n"; 306abb0f93cSkardel print "set size 1, 0.32\n"; 307abb0f93cSkardel print "set ylabel\n"; 308abb0f93cSkardel print "plot \"$out_file\" using 1:7 title \"dist\", "; 309abb0f93cSkardel print "\"$out_file\" using 1:7 smooth bezier " . 310abb0f93cSkardel "title \"(Bezier)\" with lines\n"; 311abb0f93cSkardel print "set origin 0, 0.00\n"; 312abb0f93cSkardel print "set size 1, 0.35\n"; 313abb0f93cSkardel print "set xlabel \"Days relative to 1970\"\n"; 314abb0f93cSkardel print "plot \"$out_file\" using 1:8 title \"disp\", "; 315abb0f93cSkardel print "\"$out_file\" using 1:8 smooth bezier " . 316abb0f93cSkardel "title \"(Bezier)\" with lines\n"; 317abb0f93cSkardel print "set nomultiplot\n"; 318abb0f93cSkardel maybe_add_pause; 319abb0f93cSkardel 320abb0f93cSkardel select $oldfh; 321abb0f93cSkardel close OUTPUT or die "close failed on $cmd_file: $!"; 322abb0f93cSkardel print `gnuplot $cmd_file`; 323abb0f93cSkardel unlink $cmd_file; 324abb0f93cSkardel unlink $out_file; 325abb0f93cSkardel} 326abb0f93cSkardel 3278585484eSchristos@plot_summary_opts@ 328abb0f93cSkardel 3298585484eSchristos1; 3308585484eSchristos__END__ 331