📄 ntploopwatch
字号:
$i = &lr_sigma('offs'); $m = &lr_mean('offs'); print "mean offset: $m sigma: $i\n" if $verbose > 2; if (($maxoffs - $minoffs) > $MinClip) { $f = (&abs($minoffs) < &abs($maxoffs)) ? $FuzzLow : $FuzzBig; $miny = (($m - $minoffs) <= ($f * $i)) ? $minoffs : ($m - $f * $i); $f = ($f == $FuzzLow) ? $FuzzBig : $FuzzLow; $maxy = (($maxoffs - $m) <= ($f * $i)) ? $maxoffs : ($m + $f * $i); } else { $miny = $minoffs; $maxy = $maxoffs; } ($maxy-$miny) == 0 && (($maxy,$miny) = (($maxoffs - $minoffs) > 0) ? ($maxoffs,$minoffs) : ($MinClip,-$MinClip)); $maxy = $MaxY if defined($MaxY) && $MaxY < $maxy; $miny = $MinY if defined($MinY) && $MinY > $miny; print "offset min clipped from $minoffs to $miny\n" if $verbose > 2 && $minoffs != $miny; print "offset max clipped from $maxoffs to $maxy\n" if $verbose > 2 && $maxoffs != $maxy; } if ($showfreq) { local($i,$m); $minfreq = &min(@freq); $maxfreq = &max(@freq); $i = $[; &lr_sample(($time[$i]-$timebase)/3600,$freq[$i]-$minfreq,'freq'), $i++ while $i <= $#time; $i = &lr_sigma('freq'); $m = &lr_mean('freq') + $minfreq; print "mean frequency: $m sigma: $i\n" if $verbose > 2; if (defined($maxy)) { local($s) = ($maxfreq - $minfreq) ? ($maxy - $miny) / ($maxfreq - $minfreq) : 1; if (defined($freqbase)) { $FreqScale = 1; $FreqScaleInv = ""; } else { $FreqScale = 1; $FreqScale = 10 ** int(log($s)/log(10) - 0.8); $FreqScaleInv = ("$FreqScale" =~ /^10(0*)$/) ? "0.${1}1" : ($FreqScale == 1 ? "" : (1/$FreqScale)); $freqbase = $m * $FreqScale; $freqbase -= &lr_mean('offs'); ;# round resulting freqbase ;# to precision of min max difference $s = int(log(($maxfreq-$minfreq)*$FreqScale)/log(10))-1; $s = 10 ** $s; $freqbase = int($freqbase / $s) * $s; } } else { $FreqScale = 1; $FreqScaleInv = ""; $freqbase = $m unless defined($freqbase); if (($maxfreq - $minfreq) > $MinClip) { $f = (&abs($minfreq) < &abs($maxfreq)) ? $FuzzLow : $FuzzBig; $miny = (($freqbase - $minfreq) <= ($f * $i)) ? ($minfreq-$freqbase) : (- $f * $i); $f = ($f == $FuzzLow) ? $FuzzBig : $FuzzLow; $maxy = (($maxfreq - $freqbase) <= ($f * $i)) ? ($maxfreq-$freqbase) : ($f * $i); } else { $miny = $minfreq - $freqbase; $maxy = $maxfreq - $freqbase; } ($maxy - $miny) == 0 && (($maxy,$miny) = (($maxfreq - $minfreq) > 0) ? ($maxfreq-$freqbase,$minfreq-$freqbase) : (0.5,-0.5)); $maxy = $MaxY if defined($MaxY) && $MaxY < $maxy; $miny = $MinY if defined($MinY) && $MinY > $miny; print("frequency min clipped from ",$minfreq-$freqbase, " to $miny\n") if $verbose > 2 && $miny != ($minfreq - $freqbase); print("frequency max clipped from ",$maxfreq-$freqbase, " to $maxy\n") if $verbose > 2 && $maxy != ($maxfreq - $freqbase); } $LastFreqBaseString = sprintf("%g",$freqbase >= 0 ? $freqbase : -$freqbase); $LastFreqBase = $freqbase; print "LastFreqBaseString now \"$LastFreqBaseString\"\n" if $verbose > 5; } else { $FreqScale = 1; $FreqScaleInv = ""; $LastFreqBase = 0; $LastFreqBaseString = ""; } if ($showcmpl) { $mincmpl = &min(@cmpl); $maxcmpl = &max(@cmpl); if (!defined($cmplscale)) { if (defined($maxy)) { local($cmp) = (&abs($miny) > &abs($maxy)) ? &abs($miny) : $maxy; $cmplscale = $cmp == $maxy ? 1 : -1; foreach (0.01, 0.02, 0.05, 0.1, 0.2, 0.25, 0.4, 0.5, 1, 2, 4, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000) { $cmplscale *= $_, last if $maxcmpl/$_ <= $cmp; } } else { $cmplscale = 1; $miny = $mincmpl ? 0 : -$MinClip; $maxy = $maxcmpl+$MinClip; } } $LastCmplScale = $cmplscale; } else { $LastCmplScale = 1; } print "creating plot command input file\n" if $verbose > 2; print OUT ("# preprocessed NTP statistics file for $STATHOST\n"); print OUT ("# timebase is: ",&ctime($LastTimeBase)) if defined($LastTimeBase); print OUT ("# frequency is offset by ", ($LastFreqBase >= 0 ? "+" : "-"), "$LastFreqBaseString [${FreqScaleInv}ppm]\n"); print OUT ("# compliance is scaled by $LastCmplScale\n"); print OUT ("# time [h]\toffset [ms]\tfrequency [${FreqScaleInv}ppm]\tcompliance\n"); printf OUT ("%s%lf\t%lf\t%lf\t%lf\n", (shift(@break) ? "\n" : ""), (shift(@time) - $LastTimeBase)/3600, shift(@offs), shift(@freq) * $FreqScale - $LastFreqBase, shift(@cmpl) / $LastCmplScale) while(@time); } else { ;# prevent plotcmd from processing empty file print "Creating plot command dummy...\n" if $verbose > 2; print OUT "# dummy samples\n0 1 2 3\n1 1 2 3\n"; &lr_sample(0,1,'offs'); &lr_sample(1,1,'offs'); &lr_sample(0,2,'freq'); &lr_sample(1,2,'freq'); @time = (0, 1); $maxtime = 1; $mintime = 0; @offs = (1, 1); $maxoffs = 1; $minoffs = 1; @freq = (2, 2); $maxfreq = 2; $minfreq = 2; @cmpl = (3, 3); $maxcmpl = 3; $mincmpl = 3; $LastCnt = 2; $LastFreqBase = 0; $LastCmplScale = 1; $LastTimeBase = 0; $miny = -$MinClip; $maxy = 3 + $MinClip; } close(OUT); print "plot command input file created\n" if $verbose > 2; if (($fpos[$[] eq 'cnt' && @loffset >= $cnt) || ($fpos[$[] eq 'start' && $time[$[] <= $StartTime) || ($fpos[$[] eq 'end')) { return ($fpos[$[],$filekey[$[],$loffset[$[]); } else # found to few lines - next time start search earlier in file { if ($fpos[$[] eq 'start') { ;# the timestamps we got for F_first and F_last guaranteed ;# that no file is left out ;# the only thing that could happen is: ;# we guessed the starting point wrong ;# compute a new guess from the first record found ;# if this equals our last guess use data of first record ;# otherwise try new guess if ($fpos[$[+1] eq $filekey[$[] && $loffset[$[] > $fpos[$[+2]) { local($noff); $noff = $loffset[$[] - ($cnt - @loffset + 1) * $RecordSize; $noff = 0 if $noff < 0; return (@fpos[$[,$[+1], ($noff == $fpos[$[+2]) ? $loffset[$[] : $noff); } return ($fpos[$[],$filekey[$[],$loffset[$[]); } elsif ($fpos[$[] eq 'end' || $fpos[$[] eq 'cnt') { ;# try to start earlier in file ;# if we already started at the beginning ;# try to use previous file ;# this assumes distance to better starting point is at most one file ;# the primary guess at top of genfile() should usually allow this ;# assumption ;# if the offset of the first sample used is within ;# a different file than we guessed it must have occured later ;# in the sequence of files ;# this only can happen if our starting file did not contain ;# a valid sample from the starting point we guessed ;# however this does not invalidate our assumption, no check needed local($noff,$key); if ($fpos[$[+2] > 0) { $noff = $fpos[$[+2] - $RecordSize * ($cnt - @loffset + 1); $noff = 0 if $noff < 0; return (@fpos[$[,$[+1],$noff); } else { if ($fpos[$[+1] eq $F_files[$[]) { ;# first file - and not enough samples ;# use data of first sample return ($fpos[$[], $filekey[$[], $loffset[$[]); } else { ;# search key of previous file $key = $F_files[$[]; @F = reverse(@F_files); while ($_ = shift(@F)) { if ($_ eq $fpos[$[+1]) { $key = shift(@F) if @F; last; } } $noff = int($F_size{$key} / $RecordSize); $noff -= $cnt - @loffset; $noff = 0 if $noff < 0; $noff *= $RecordSize; return ($fpos[$[], $key, $noff); } } } else { return (); } return 0 if @loffset <= 1 || ($loffset[$#loffset] - $loffset[$[]) <= 1; ;# EOF - 1.1 * avg(line) * $cnt local($val) = $loffset[$#loffset] - $cnt * 11 * (($loffset[$#loffset] - $loffset[$[]) / @loffset) / 10; return ($val < 0) ? 0 : $val; }};# initial setup of plotprint "initialize plotting\n" if $verbose;if (defined($PrintIt)){ if ($PrintIt =~ m,/,) { print "Saving plot to file $PrintIt\n"; print PLOT "set output '$PrintIt'\n"; } else { print "Printing plot on printer $PrintIt\n"; print PLOT "set output '| lpr -P$PrintIt -h'\n"; } print PLOT "set terminal postscript landscape color solid 'Helvetica' 10\n";}print PLOT "set grid\n";print PLOT "set tics out\n";print PLOT "set format y '%g '\n";printf PLOT "set time 47\n" unless defined($PrintIt);@filepos =();while(1){ print &ctime(time) if $verbose; ;# update diplay characteristics &read_config;# unless defined($PrintIt); unlink($tmpfile); @filepos = &genfile($samples,$srcprefix,$tmpfile,@filepos); ;# make plotcmd display samples &make_doplot; print "Displaying plot...\n" if $verbose > 1; print "command for plot sub process:\n$doplot----\n" if $verbose > 3; print PLOT $doplot;}continue{ if (defined($PrintIt)) { delete $SIG{'CHLD'}; print PLOT "quit\n"; close(PLOT); if ($PrintIt =~ m,/,) { print "Plot saved to file $PrintIt\n"; } else { print "Plot spooled to printer $PrintIt\n"; } unlink($tmpfile); exit(0); } ;# wait $delay seconds print "waiting $delay seconds ..." if $verbose > 2; sleep($delay); print " continuing\n" if $verbose > 2; undef($LastFreqBaseString);}sub date_time_spec2seconds{ local($_) = @_; ;# a date_time_spec consistes of: ;# YYYY-MM-DD_HH:MM:SS.ms ;# values can be omitted from the beginning and default than to ;# values of current date ;# values omitted from the end default to lowest possible values local($time) = time; local($sec,$min,$hour,$mday,$mon,$year) = localtime($time); local($last) = (); s/^\D*(.*\d)\D*/\1/; # strip off garbage PARSE: { if (s/^(\d{4})(-|$)//) { if ($1 < 1970) { warn("$0: can not handle years before 1970 - year $1 ignored\n"); return undef; } elsif ( $1 >= 2070) { warn("$0: can not handle years past 2070 - year $1 ignored\n"); return undef; } else { $year = $1 % 100; # 0<= $year < 100 ;# - interpreted 70 .. 99,00 .. 69 } $last = $[ + 5; last PARSE if $_ eq ''; warn("$0: bad date_time_spec: \"$_\" found after YEAR\n"), return(undef) if $2 eq ''; } if (s/^(\d{1,2})(-|$)//) { warn("$0: implausible month $1\n"),return(undef) if $1 < 1 || $1 > 12; $mon = $1 - 1; $last = $[ + 4; last PARSE if $_ eq ''; warn("$0: bad date_time_spec: \"$_\" found after MONTH\n"), return(undef) if $2 eq ''; } else { warn("$0: bad date_time_spec \"$_\"\n"),return(undef) if defined($last); } if (s/^(\d{1,2})([_ ]|$)//) { warn("$0: implausible month day $1 for month ".($mon+1)." (". $MaxNumDaysPerMonth[$mon].")$mon\n"), return(undef) if $1 < 1 || $1 > $MaxNumDaysPerMonth[$mon]; $mday = $1; $last = $[ + 3; last PARSE if $_ eq ''; warn("$0: bad date_time_spec \"$_\" found after MDAY\n"), return(undef) if $2 eq ''; } else { warn("$0: bad date_time_spec \"$_\"\n"), return undef if defined($last); } ;# now we face a problem: ;# if ! defined($last) a prefix of "07:" ;# can be either 07:MM or 07:ss ;# to get the second interpretation make the user add ;# a msec fraction part and check for this special case if (! defined($last) && s/^(\d{1,2}):(\d{1,2}\.\d+)//) { warn("$0: implausible minute $1\n"), return undef if $1 < 0 || $1 >= 60; warn("$0: implausible second $1\n"), return undef if $2 < 0 || $2 >= 60; $min = $1; $sec = $2; $last = $[ + 1; last PARSE if $_ eq ''; warn("$0: bad date_time_spec \"$_\" after SECONDS\n"); return undef; } if (s/^(\d{1,2})(:|$)//) { warn("$0: implausible hour $1\n"), return undef if $1 < 0 || $1 > 24; $hour = $1; $last = $[ + 2; last PARSE if $_ eq ''; warn("$0: bad date_time_spec found \"$_\" after HOUR\n"), return undef if $2 eq ''; } else { warn("$0: bad date_time_spec \"$_\"\n"), return undef if defined($last); } if (s/^(\d{1,2})(:|$)//) { warn("$0: implausible minute $1\n"), return undef if $1 < 0 || $1 >=60; $min = $1; $last = $[ + 1; last PARSE if $_ eq ''; warn("$0: bad date_time_spec found \"$_\" after MINUTE\n"), return undef if $2 eq ''; } else { warn("$0: bad date_time_spec \"$_\"\n"), return undef if defined($last); } if (s/^(\d{1,2}(\.\d+)?)//) { warn("$0: implausible second $1\n"), return undef if $1 < 0 || $1 >=60; $sec = $1; $last = $[; last PARSE if $_ eq ''; warn("$0: bad date_time_spec found \"$_\" after SECOND\n"); return undef; } } return $time unless defined($last); $sec = 0 if $last > $[; $min = 0 if $last > $[ + 1; $hour = 0 if $last > $[ + 2; $mday = 1 if $last > $[ + 3; $mon = 0 if $last > $[ + 4; local($rtime) = &timelocal($sec,$min,$hour,$mday,$mon,$year, 0,0, 0); ;# $rtime may be off if daylight savings time is in effect at given date return $rtime + ($sec - int($sec)) if $hour == (localtime($rtime))[$[+2]; return &timelocal($sec,$min,$hour,$mday,$mon,$year, 0,0, 1) + ($sec - int($sec));}sub min{ local($m) = shift; grep((($m > $_) && ($m = $_),0),@_); $m;}sub max{ local($m) = shift; grep((($m < $_) && ($m = $_),0),@_); $m;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -