Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / TBBT / trace_init / counts.pl
1 #\r
2 # Copyright (c) 2003\r
3 #      The President and Fellows of Harvard College.\r
4 #\r
5 # Redistribution and use in source and binary forms, with or without\r
6 # modification, are permitted provided that the following conditions\r
7 # are met:\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
16 #\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
27 # SUCH DAMAGE.\r
28 #\r
29 # $Id: counts.pl,v 1.9 2003/07/28 14:27:16 ellard Exp $\r
30 \r
31 package counts;\r
32 \r
33 @OpList         = ();\r
34 %KeysSeen       = ();\r
35 \r
36 %OpCounts       = ();\r
37 \r
38 sub init {\r
39         my (@oplist) = @_;\r
40 \r
41         @OpList = @oplist;\r
42 }\r
43 \r
44 sub printTitle {\r
45         my ($out) = @_;\r
46 \r
47         my $str = "#C time client fh euid egid";\r
48 \r
49         foreach my $op ( @OpList ) {\r
50                 $str .= " $op";\r
51         }\r
52         $str .= "\n";\r
53 \r
54         print $out $str;\r
55\r
56 \r
57 sub printOps {\r
58         my ($start_time, $out) = @_;\r
59         my ($k, $str, $op, $nk);\r
60 \r
61         my @allkeys = sort keys %KeysSeen;\r
62 \r
63         foreach $k ( @allkeys ) {\r
64                 my $tot = "$k,TOTAL";\r
65 \r
66                 if ($main::OMIT_ZEROS &&\r
67                         (! exists $OpCounts{$tot} || $OpCounts{$tot} == 0)) {\r
68                         next;\r
69                 }\r
70 \r
71                 $str = sprintf ("C %s %s", $start_time, &key::key2str ($k));\r
72 \r
73                 foreach $op ( @OpList ) {\r
74                         $nk = "$k,$op";\r
75                         if (exists $OpCounts{$nk}) {\r
76                                 if ($op eq 'readM' || $op eq 'writeM') {\r
77                                         $str .= sprintf (" %.3f",\r
78                                                 $OpCounts{$nk} / (1024 * 1024));\r
79                                 }\r
80                                 else {\r
81                                         $str .= " $OpCounts{$nk}"\r
82                                 }\r
83                         }\r
84                         else {\r
85                                 $str .= " 0";\r
86                         }\r
87                 }\r
88                 $str .= "\n";\r
89                 print $out $str;\r
90         }\r
91 }\r
92 \r
93 sub resetOpCounts {\r
94 \r
95         # Clear the counts on everything we've seen.\r
96 \r
97         foreach my $op ( keys %OpCounts ) {\r
98                 $OpCounts{$op} = 0;\r
99         }\r
100 }\r
101 \r
102 1;\r
103 \r