2 # Copyright (c) 2002-2003
\r
3 # The President and Fellows of Harvard College.
\r
5 # Redistribution and use in source and binary forms, with or without
\r
6 # modification, are permitted provided that the following conditions
\r
8 # 1. Redistributions of source code must retain the above copyright
\r
9 # notice, this list of conditions and the following disclaimer.
\r
10 # 2. Redistributions in binary form must reproduce the above copyright
\r
11 # notice, this list of conditions and the following disclaimer in the
\r
12 # documentation and/or other materials provided with the distribution.
\r
13 # 3. Neither the name of the University nor the names of its contributors
\r
14 # may be used to endorse or promote products derived from this software
\r
15 # without specific prior written permission.
\r
17 # THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
\r
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
\r
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
23 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
\r
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
\r
29 # $Id: ns_timeagg,v 1.4 2003/07/10 20:13:31 ellard Exp $
\r
31 # Allows rounding of the start time, so that minor clock drift doesn't
\r
32 # make trace periods appear to begin at funny times (i.e. one or two
\r
33 # seconds after midnight, instead of midnight).
\r
35 # This is only meant to help with SMALL amounts of drift. Trying to
\r
36 # use this to correct for anything more than a small fraction of the
\r
37 # sample interval is asking for trouble.
\r
39 require 'timelocal.pl';
\r
42 my ($time, $rounding) = @_;
\r
44 my $new_time = int ($time);
\r
46 if (defined $rounding && $rounding != 0) {
\r
47 $rounding = int ($rounding);
\r
49 my $leftover = $new_time % $rounding;
\r
51 if ($leftover > $rounding / 2) {
\r
52 $new_time += $rounding;
\r
55 $new_time -= ($new_time % $rounding);
\r