Commit 86239818 authored by Junxing Zhang's avatar Junxing Zhang
Browse files

Changed timediff.pl per Dave's email.

parent a5ea34cb
#! /usr/bin/perl -w
use Getopt::Std;
getopts('d');
our ($opt_d, $opt_n);
getopts('dn:');
if ($#ARGV != 0) {
print "usage: timediff.pl <remote-host>\n";
print "usage: timediff.pl [-d] [-n <sample number>] <remote-host>\n";
exit;
}
$host = $ARGV[0];
$ntptrace = "ntptrace";
$cmd = "$ntptrace";
open(PH, $cmd . "|") || die "failed to start command $cmd: $!";
while (<PH>) {
$stratum1 = $1 if (/\sstratum\s(\d+),/);
$offset1 = $1 if (/\soffset\s([-\d.]+),/);
print if ($opt_d);
$ntptrace = "/proj/tbres/bin/ntptrace";
$cmd = "$ntptrace -nv $host";
$sampnum = 20;
if ($opt_n) {
if ($opt_n !~ /^\d+$/) {
print "Error: -n option must be a positive integer!\n";
exit -1;
}
$sampnum = $opt_n;
}
close(PH) || die "$cmd failed";
if ($stratum1 != 1) {
printf("Warning: the local host only reaches stratum %d \n", $stratum1);
$mindelay = 100000;
for ($i=0; $i<$sampnum; $i++) {
open(PH, $cmd . "|") || die "failed to start command $cmd: $!";
$lineno = 1;
while (<PH>) {
print if ($opt_d);
if ($lineno == 3) {
$delay = $1 if (/\sdelay\s(-?\d+\.?\d*),/);
$offset = $1 if (/\soffset\s(-?\d+\.?\d*)$/);
last if (!$opt_d);
}
$lineno++;
}
close(PH) || die "$cmd failed";
if (!defined($delay) || !defined($offset)) {
print "Error: delay or offset is not found in the ntptrace output!\n";
exit -1;
}
if ($opt_d) {
printf("delay: %f, offset: %f \n", $delay, $offset);
printf("======================================================================\n");
}
if ($delay < $mindelay){
$mindelay = $delay;
$minoffset = $offset;
}
}
print "=======================================================================================\n" if ($opt_d);
$cmd = "$ntptrace $host";
open(PH, $cmd . "|") || die "failed to start command $cmd: $!";
while (<PH>) {
$stratum2 = $1 if (/\sstratum\s(\d+),/);
$offset2 = $1 if (/\soffset\s([-\d.]+),/);
print if ($opt_d);
}
close(PH) || die "$cmd failed";
if ($stratum2 != 1) {
printf("Warning: the remote host %s only reaches stratum %d \n", $host, $stratum2);
}
print "=======================================================================================\n" if ($opt_d);
printf("The time difference between %s and the local host is %f\n", $host, $offset1-$offset2);
printf("The min delay is %f, and the corresponding offset is %f\n", $mindelay, $minoffset);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment