4 # Use Gnuplot to display data in summary files produced by summary.pl.
5 # This script requires GNUPLOT 3.7!
7 # Copyright (c) 1997, 1999 by Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 my ($identifier, $offset_limit, $gnuplot_terminal, $wait_after_plot,
28 $output_file, $output_file_number);
30 exit run(@ARGV) unless caller;
34 if (!processOptions(\@_, $opts)) {
38 $identifier = $opts->{'identifier'};
40 $identifier = "host".`hostname`;
43 $offset_limit = $opts->{'offset-limit'};
44 $output_file = $opts->{'output-file'};
45 $output_file_number = 1;
46 $gnuplot_terminal = $opts->{'plot-terminal'}
47 || ( $ENV{DISPLAY} ? "x11" : "dumb" );
48 $wait_after_plot = !$opts->{'dont-wait'};
50 die "illegal offset-limit: $offset_limit" unless $offset_limit > 0.0;
51 $offset_limit *= 1e6; # scale to microseconds
53 my $summary_dir = $opts->{'directory'};
55 my $loop_summary ="$summary_dir/loop_summary";
56 my $peer_summary ="$summary_dir/peer_summary";
57 my $clock_summary="$summary_dir/clock_summary";
59 my @peer_list = @{$opts->{'peer'}};
61 do_loop($loop_summary);
62 do_peer($peer_summary, $_) for @peer_list;
65 # return the smallest value in the given list
68 my ($result, @rest) = @_;
69 map { $result = $_ if ($_ < $result) } @rest;
73 # return the largest value in the given list
76 my ($result, @rest) = @_;
77 map { $result = $_ if ($_ > $result) } @rest;
81 # maybe open alternate output file
86 while ( -r ($file = "$output_file$output_file_number") ) {
87 ++$output_file_number;
89 open TOUCH, ">$file" and close TOUCH or die "$file: $!";
90 print "set output \"$file\"\n";
97 print "pause -1 \"Press key to continue...\"\n" if $wait_after_plot;
100 # plot data from loop summary
105 my $out_file = "/tmp/tempdata$$";
106 my $cmd_file = "/tmp/tempcmd$$";
107 my ($first_day, $day_out) = ("", 0);
108 my ($lower_bound, $upper_bound, $rms);
109 my ($min_offs, $max_offs) = (1e9, -1e9);
110 my ($min_rms, $max_rms) = (1e9, -1e9);
111 open INPUT, "$fname" or die "$fname: $!";
112 open OUTPUT, ">$out_file" or die "$out_file: $!";
115 chop; # strip record separator
119 $_ = $Fld[0]; s/.*([12]\d{3}[01]\d[0-3]\d)$/$1/;
120 m/(\d{4})(\d{2})(\d{2})/;
121 $line = timegm(59, 59, 23, $3, $2 - 1, $1 - 1900, 0, 0, 0);
122 $line = int $line / 86400; # days relative to 1970
123 $first_day = "$1-$2-$3 ($line)" unless $day_out;
127 warn "Illegal number of fields in file $fname, line $.";
130 # loop 216, 856106+/-874041.5, rms 117239.8, freq 67.52+/-10.335, var 4.850
131 $_ = $Fld[1]; s/,/ /; $line .= " $_";
132 $_ = $Fld[2]; m:(.+?)\+/-(.+),:;
133 $lower_bound = $1 - $2;
134 $upper_bound = $1 + $2;
135 $line .= "$1 $lower_bound $upper_bound";
136 $min_offs = min($min_offs, $lower_bound);
137 $max_offs = max($max_offs, $upper_bound);
138 $_ = $Fld[4]; s/,/ /; $rms = $_;
139 $min_rms = min($min_rms, $rms);
140 $max_rms = max($max_rms, $rms);
142 $_ = $Fld[6]; m:(.+?)\+/-(.+),:;
143 $line .= " $1 " . ($1-$2) . " " . ($1+$2);
145 print OUTPUT "$line\n";
147 # 9621 216 856106 -17935.5 1730147.5 117239.8 67.52 57.185 77.855 4.850
150 close OUTPUT or die "close failed on $out_file: $!";
152 if ($min_offs < -$offset_limit) {
153 $ylimit .= "-$offset_limit";
156 if ($max_offs > $offset_limit) {
157 $ylimit .= "$offset_limit";
159 if ( $ylimit eq "[:" ) {
162 $ylimit = "[] $ylimit]";
164 # build command file for GNUplot
165 open OUTPUT, "> $cmd_file" or die "$cmd_file: $!";
166 my $oldfh = select OUTPUT;
167 print "set term $gnuplot_terminal\n";
170 print "set title \"Loop Summary for $identifier: " .
171 "Daily mean values since $first_day\\n" .
172 "(Offset limit is $offset_limit microseconds)\"\n";
173 print "set ylabel \"[us]\"\n";
174 print "set style data yerrorbars\n";
175 print "set multiplot\n";
176 print "set size 1, 0.5\n";
177 print "set lmargin 8\n";
178 print "set origin 0, 0.5\n";
179 print "plot $ylimit \"$out_file\"" .
180 " using 1:3:4:5 title \"mean offset\", ";
181 print "\"$out_file\" using 1:(\$3-\$6/2) " .
182 "title \"(sigma low)\" with lines, ";
183 print "\"$out_file\" using 1:3 smooth bezier " .
184 "title \"(Bezier med)\" with lines, ";
185 print "\"$out_file\" using 1:(\$3+\$6/2) " .
186 "title \"(sigma high)\" with lines\n";
187 print "set ylabel \"[ppm]\"\n";
188 print "set origin 0, 0.0\n";
190 print "set xlabel \"Days relative to 1970\"\n";
191 print "plot \"$out_file\" using 1:7:8:9 title \"mean frequency\", ";
192 print "\"$out_file\" using 1:(\$7-\$10/2) " .
193 "title \"(sigma low)\" with lines, ";
194 print "\"$out_file\" using 1:7 smooth bezier " .
195 "title \"(Bezier med)\" with lines, ";
196 print "\"$out_file\" using 1:(\$7+\$10/2) " .
197 "title \"(sigma high)\" with lines\n";
198 print "set nomultiplot\n";
202 if ($min_rms < -$offset_limit) {
203 $ylimit .= "-$offset_limit";
206 if ($max_rms > $offset_limit) {
207 $ylimit .= "$offset_limit";
209 if ( $ylimit eq "[:" ) {
212 $ylimit = "[] $ylimit]";
216 print "set title \"Loop Summary for $identifier: " .
217 "Standard deviation since $first_day\\n" .
218 "(Offset limit is $offset_limit microseconds)\"\n";
219 print "set xlabel\n";
220 print "set ylabel \"[us]\"\n";
221 print "set origin 0, 0.5\n";
222 print "set style data linespoints\n";
223 print "set multiplot\n";
224 print "plot $ylimit \"$out_file\" using 1:6 title \"Offset\", ";
225 print "\"$out_file\" using 1:6 smooth bezier " .
226 "title \"(Bezier)\" with lines\n";
228 print "set origin 0, 0.0\n";
229 print "set xlabel \"Days relative to 1970\"\n";
230 print "set ylabel \"[ppm]\"\n";
231 print "plot \"$out_file\" using 1:10 title \"Frequency\", ";
232 print "\"$out_file\" using 1:10 smooth bezier " .
233 "title \"(Bezier)\" with lines\n";
234 print "set nomultiplot\n";
237 close OUTPUT or die "close failed on $cmd_file: $!";
239 print `gnuplot $cmd_file`;
244 # plot data form peer summary
249 my $out_file = "/tmp/tempdata$$";
250 my $cmd_file = "/tmp/tempcmd$$";
252 my ($first_day, $day_out) = ("", 0);
253 open INPUT, "$fname" or die "$fname: $!";
254 open OUTPUT, ">$out_file" or die "$out_file: $!";
257 chop; # strip record separator
261 $_ = $Fld[0]; s/.*([12]\d{3}[01]\d[0-3]\d)$/$1/;
262 m/(\d{4})(\d{2})(\d{2})/ or next;
263 $line = timegm(59, 59, 23, $3, $2 - 1, $1 - 1900, 0, 0, 0);
264 $line = int $line / 86400; # days relative to 1970
265 $first_day = "$1-$2-$3 ($line)" unless $day_out;
269 warn "Illegal number of fields in file $fname, line $.";
272 next if ($Fld[0] ne $peer);
273 # ident cnt mean rms max delay dist disp
274 # 127.127.8.1 38 30.972 189.867 1154.607 0.000 879.760 111.037
276 print OUTPUT join(' ', @Fld) . "\n";
277 # 9969 38 30.972 189.867 1154.607 0.000 879.760 111.037
281 close OUTPUT or die "close failed on $out_file: $!";
282 die "no data found for peer $peer" if !$day_out;
283 open OUTPUT, "> $cmd_file" or die "$cmd_file: $!";
284 my $oldfh = select OUTPUT;
285 print "set term $gnuplot_terminal\n";
288 print "set multiplot\n";
289 print "set lmargin 8\n";
290 print "set size 1, 0.34\n";
291 print "set origin 0, 0.66\n";
293 "\"Peer Summary for $peer on $identifier since $first_day\"\n";
294 print "set style data linespoints\n";
295 print "set ylabel \"[us]\"\n";
296 print "plot \"$out_file\" using 1:3 title \"mean offset\", ";
297 print "\"$out_file\" using 1:3 smooth bezier " .
298 "title \"(Bezier)\" with lines, ";
299 print "\"$out_file\" using 1:(\$3-\$7/2) " .
300 "title \"(sigma low)\" with lines, ";
301 print "\"$out_file\" using 1:(\$3+\$7/2) " .
302 "title \"(sigma high)\" with lines\n";
304 print "set origin 0, 0.34\n";
305 print "set size 1, 0.32\n";
306 print "set ylabel\n";
307 print "plot \"$out_file\" using 1:7 title \"dist\", ";
308 print "\"$out_file\" using 1:7 smooth bezier " .
309 "title \"(Bezier)\" with lines\n";
310 print "set origin 0, 0.00\n";
311 print "set size 1, 0.35\n";
312 print "set xlabel \"Days relative to 1970\"\n";
313 print "plot \"$out_file\" using 1:8 title \"disp\", ";
314 print "\"$out_file\" using 1:8 smooth bezier " .
315 "title \"(Bezier)\" with lines\n";
316 print "set nomultiplot\n";
320 close OUTPUT or die "close failed on $cmd_file: $!";
321 print `gnuplot $cmd_file`;