Import TBBT (NFS trace replay).
[bluesky.git] / TBBT / trace_init / ns_loc2gmt.pl
diff --git a/TBBT/trace_init/ns_loc2gmt.pl b/TBBT/trace_init/ns_loc2gmt.pl
new file mode 100755 (executable)
index 0000000..815f68f
--- /dev/null
@@ -0,0 +1,108 @@
+#!/usr/bin/perl\r
+#\r
+# Copyright (c) 2002-2003\r
+#      The President and Fellows of Harvard College.\r
+#\r
+# Redistribution and use in source and binary forms, with or without\r
+# modification, are permitted provided that the following conditions\r
+# are met:\r
+# 1. Redistributions of source code must retain the above copyright\r
+#    notice, this list of conditions and the following disclaimer.\r
+# 2. Redistributions in binary form must reproduce the above copyright\r
+#    notice, this list of conditions and the following disclaimer in the\r
+#    documentation and/or other materials provided with the distribution.\r
+# 3. Neither the name of the University nor the names of its contributors\r
+#    may be used to endorse or promote products derived from this software\r
+#    without specific prior written permission.\r
+#\r
+# THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND\r
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE\r
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+# SUCH DAMAGE.\r
+#\r
+# $Id: ns_loc2gmt,v 1.6 2003/07/28 14:27:16 ellard Exp $\r
+#\r
+# A helper application used by ns_quickview to convert from local time\r
+# to GMT.  nfsdump records time as localtime, but gnuplot only know\r
+# how to deal with dates expressed as Greenwich Mean Time (which it\r
+# then displays using the local time, for some reason).\r
+#\r
+# This is a fragile tool -- it must be run in the same time zone in\r
+# which the data was collected via nfsdump, or else it will not do the\r
+# proper conversion.  Improvements welcomed!\r
+#\r
+# The 'C' (count) and 'L' (latency) records use the second column for\r
+# dates, expressed as seconds.microseconds in localtime.  The seconds\r
+# portion is the only part of the data modified by this program. \r
+# Comment lines are passed through unaltered.\r
+#\r
+# There is no error checking.  Garbage in, garbage out.\r
+#\r
+# Note - we're throwing the microseconds away.\r
+\r
+\r
+use Getopt::Std;\r
+require 'timelocal.pl';\r
+\r
+$Usage =<< ".";\r
+\r
+Usage: $0 [options] [table1.ns [table2.ns ... ]]\r
+\r
+If no table files are specified, then the input is read from stdin.\r
+\r
+Command line options:\r
+\r
+-h             Print usage message and exit.\r
+\r
+-d secs                Time offset, in seconds, to subtract from each time\r
+               in the input tables.  Note that all times are rounded\r
+               down to the nearest second.\r
+\r
+IMPORTANT NOTE:  this must be run in the same time zone in which the\r
+data was collected via nfsdump, or else it will not do the proper\r
+conversion unless the -d option is used.\r
+\r
+.\r
+\r
+$Options = "d:";\r
+if (! getopts ($Options)) {\r
+       print STDERR "$0: Incorrect usage.\n";\r
+       print STDERR $Usage;\r
+       exit (1);\r
+}\r
+if (defined $opt_h) {\r
+       print $Usage;\r
+       exit (0);\r
+}\r
+\r
+$TimeOffset = 0;\r
+if (defined $opt_d) {\r
+       $TimeOffset = int ($opt_d);\r
+}\r
+\r
+while ($line = <>) {\r
+       if ($line =~ /^#/) {\r
+               print $line;\r
+               next;\r
+       }\r
+\r
+       @arr = split (' ', $line);\r
+\r
+       ($secs, $usec) = split (/\./, $arr[1]);\r
+       $secs -= $TimeOffset;\r
+\r
+       $arr[1] = &timegm (localtime ($secs));\r
+\r
+       print join (' ', @arr);\r
+       print "\n";\r
+}\r
+\r
+exit (0);\r
+\r