3 # Copyright (c) 2002-2003
\r
4 # The President and Fellows of Harvard College.
\r
6 # Redistribution and use in source and binary forms, with or without
\r
7 # modification, are permitted provided that the following conditions
\r
9 # 1. Redistributions of source code must retain the above copyright
\r
10 # notice, this list of conditions and the following disclaimer.
\r
11 # 2. Redistributions in binary form must reproduce the above copyright
\r
12 # notice, this list of conditions and the following disclaimer in the
\r
13 # documentation and/or other materials provided with the distribution.
\r
14 # 3. Neither the name of the University nor the names of its contributors
\r
15 # may be used to endorse or promote products derived from this software
\r
16 # without specific prior written permission.
\r
18 # THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
\r
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
\r
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
\r
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
\r
30 # $Id: ns_tsplit,v 1.4 2003/07/26 20:52:04 ellard Exp $
\r
36 $ProgDir =~ /(^.*)\//;
\r
42 # Set the default start and end times.
\r
44 $DEF_BEGIN_TIME = "20000101:00:00:00";
\r
45 $DEF_END_TIME = "20360101:00:00:00";
\r
47 # The range includes everything from the start time up to and less
\r
48 # than the end time (so if you want one day, it is correct to go
\r
49 # midnight to midnight, instead of going until 23:59:59).
\r
53 Usage: $0 [options] rangeSpec... - [table.ns [table.ns...]]
\r
55 Command line options:
\r
57 -h Print usage message and exit.
\r
59 Any number of time range specifier can be provided. The special
\r
60 symbol "-" is used to separated the time specifiers from the input
\r
61 file names. If input is taken from stdin, then the "-" may be
\r
64 The basic time range specification format is: StartTime-EndTime where
\r
65 StartTime and EndTime have the form YYMMDD[:HH[:MM[:SS]]]. All
\r
66 records from the input that have a timestamp greater than or equal to
\r
67 StartTime and less than EndTime are printed to stdout.
\r
69 If StartTime is omitted, $DEF_BEGIN_TIME is used.
\r
70 If EndTime is omitted, $DEF_END_TIME is used.
\r
72 Note that omitting both the StartTime and EndTime results in a rangeSpec
\r
73 of "-", which is the special symbol that marks the end of the rangeSpecs.
\r
76 $cmdline = "$0 " . join (' ', @ARGV);
\r
78 if (! getopts ($Options)) {
\r
79 print STDERR "$0: Incorrect usage.\n";
\r
80 print STDERR $Usage;
\r
83 if (defined $opt_h) {
\r
91 while ($ts = shift @ARGV) {
\r
92 last if ($ts eq '-');
\r
94 my ($ts_s, $ts_e) = split (/-/, $ts);
\r
98 $ts_s = $DEF_START_TIME;
\r
100 $s = &ts2secs ($ts_s);
\r
101 if (! defined $s) {
\r
102 print STDERR "Failed to translate ($ts_s)\n";
\r
105 push @StartTimes, $s;
\r
108 $ts_e = $DEF_END_TIME;
\r
110 $s = &ts2secs ($ts_e);
\r
111 if (! defined $s) {
\r
112 print STDERR "Failed to translate ($ts_e)\n";
\r
116 push @EndTimes, $s;
\r
119 print "#cmdline $cmdline\n";
\r
127 my ($type, $time, $client, $fh, $euid, $egid, @vals) = split (' ', $l);
\r
129 next unless ($type eq 'C');
\r
131 # Something wrong with the input?
\r
133 next if (@vals == 0);
\r
135 if (saveRecord ($time)) {
\r
145 for (my $i = 0; $i < @StartTimes ; $i++) {
\r
146 if (($StartTimes[$i] <= $t) && ($t < $EndTimes[$i])) {
\r
156 # The basic time specification format is: YYMMDD[:HH[:MM[:SS]]].
\r
158 # To make a time range, join two time specs with a -.
\r
160 # The data spec is Y2.01K compliant... I'm assuming that all the
\r
161 # traces processed by this tool will be gathered before 2010. If
\r
162 # anyone is still gathering NFSv3 traces in 2010, I'm sorry.
\r
166 my ($hour, $min, $sec) = (0, 0, 0);
\r
168 my (@d) = split (/:/, $ts);
\r
170 if ($d[0] =~ /([0-9][0-9])([0-2][0-9])([0-3][0-9])/) {
\r
180 if ($d[1] =~ /([0-2][0-9])/) {
\r
189 if ($d[2] =~ /([0-5][0-9])/) {
\r
198 if ($d[3] =~ /([0-5][0-9])/) {
\r
206 my $s = timelocal ($sec, $min, $hour, $day, $mon, $year,
\r
207 undef, undef, undef);
\r
209 my ($s2, $m2, $h2, $md2, $mon2, $y2, $isdst) = localtime ($s);
\r
210 if (($s2 != $sec) || $min != $m2 || $hour != $h2 || $day != $md2) {
\r
211 print "failed 1!\n";
\r
213 if (($mon != $mon2) || $year != $y2) {
\r
214 print "failed 2!\n";
\r