Import TBBT (NFS trace replay).
[bluesky.git] / TBBT / trace_init / common.pl
diff --git a/TBBT/trace_init/common.pl b/TBBT/trace_init/common.pl
new file mode 100755 (executable)
index 0000000..5959ee1
--- /dev/null
@@ -0,0 +1,61 @@
+#\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_timeagg,v 1.4 2003/07/10 20:13:31 ellard Exp $\r
+\r
+# Allows rounding of the start time, so that minor clock drift doesn't\r
+# make trace periods appear to begin at funny times (i.e.  one or two\r
+# seconds after midnight, instead of midnight).\r
+#\r
+# This is only meant to help with SMALL amounts of drift.  Trying to\r
+# use this to correct for anything more than a small fraction of the\r
+# sample interval is asking for trouble.\r
+\r
+require 'timelocal.pl';\r
+\r
+sub findStartTime {\r
+       my ($time, $rounding) = @_;\r
+\r
+       my $new_time = int ($time);\r
+\r
+       if (defined $rounding && $rounding != 0) {\r
+               $rounding = int ($rounding);\r
+\r
+               my $leftover = $new_time % $rounding;\r
+\r
+               if ($leftover > $rounding / 2) {\r
+                       $new_time += $rounding;\r
+               }\r
+\r
+               $new_time -= ($new_time % $rounding);\r
+       }\r
+\r
+       return $new_time;\r
+}\r
+\r
+1;\r