--- /dev/null
+#\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: latency.pl,v 1.8 2003/07/28 14:27:16 ellard Exp $\r
+#\r
+# latency.pl -\r
+\r
+package latency;\r
+\r
+%PendingOps = ();\r
+%OpCount = ();\r
+%OpTime = ();\r
+%KeysSeen = ();\r
+\r
+@OpList = ();\r
+\r
+sub init {\r
+ my (@oplist) = @_;\r
+\r
+ @OpList = @oplist;\r
+}\r
+\r
+# Bugs: might not recognize the actual response packets. It's an\r
+# approximation.\r
+\r
+sub update {\r
+ my ($key, $proto, $op, $xid, $client, $now) = @_;\r
+\r
+ my $uxid = "$client-$xid";\r
+\r
+ if ($proto eq 'C3' || $proto eq 'C2') {\r
+ $PendingOps{$uxid} = $now;\r
+ }\r
+ elsif (exists $PendingOps{$uxid}) {\r
+ my $elapsed = $now - $PendingOps{$uxid};\r
+\r
+ $KeysSeen{$key} = 1;\r
+\r
+ $OpTime{"$key,$op"} += $elapsed;\r
+ $OpCount{"$key,$op"}++;\r
+\r
+ $OpTime{"$key,TOTAL"} += $elapsed;\r
+ $OpCount{"$key,TOTAL"}++;\r
+\r
+ $OpTime{"$key,INTERESTING"} += $elapsed;\r
+ $OpCount{"$key,INTERESTING"}++;\r
+\r
+ delete $PendingOps{$uxid};\r
+ }\r
+}\r
+\r
+sub resetOpCounts {\r
+\r
+ my $k;\r
+\r
+ foreach $k ( keys %OpTime ) {\r
+ $OpTime{$k} = 0.0;\r
+ }\r
+ foreach $k ( keys %OpCount ) {\r
+ $OpCount{$k} = 0;\r
+ }\r
+\r
+ return ;\r
+}\r
+\r
+sub printTitle {\r
+ my $str = "#L time client euid egid fh";\r
+\r
+ foreach my $op ( @OpList ) {\r
+ $str .= " $op-cnt $op-lat";\r
+ }\r
+ $str .= "\n";\r
+\r
+ print $str;\r
+} \r
+\r
+sub printOps {\r
+ my ($start_time, $out) = @_;\r
+ my ($k, $str, $op, $nk, $latms, $cnt);\r
+\r
+ my @allkeys = sort keys %KeysSeen;\r
+\r
+ foreach $k ( @allkeys ) {\r
+ my $tot = "$k,TOTAL";\r
+\r
+ if ($main::OMIT_ZEROS &&\r
+ (! exists $OpCounts{$tot} || $OpCounts{$tot} == 0)) {\r
+ next;\r
+ }\r
+\r
+ $str = sprintf ("L %s %s", $start_time, &key::key2str ($k));\r
+\r
+ foreach $op ( @OpList ) {\r
+ $nk = "$k,$op";\r
+\r
+ if (exists $OpCount{$nk}) {\r
+ $cnt = $OpCount{"$k,$op"};\r
+ }\r
+ else {\r
+ $cnt = 0;\r
+ }\r
+\r
+ if ($cnt > 0) {\r
+ $latms = 1000 * $OpTime{$nk} / $cnt;\r
+ }\r
+ else {\r
+ $latms = -1;\r
+ }\r
+\r
+ $str .= sprintf (" %d %.4f", $cnt, $latms);\r
+ }\r
+\r
+ print $out "$str\n";\r
+ }\r
+}\r
+\r
+# Purge all the pending XID records dated earlier than $when (which is\r
+# typically at least $PRUNE_INTERVAL seconds ago). This is important\r
+# because otherwise missing XID records can pile up, eating a lot of\r
+# memory. \r
+ \r
+sub prunePending {\r
+ my ($when) = @_;\r
+\r
+ foreach my $uxid ( keys %PendingOps ) {\r
+ if ($PendingOps{$uxid} < $when) {\r
+ delete $PendingOps{$uxid};\r
+ }\r
+ }\r
+\r
+ return ;\r
+}\r
+\r
+1;\r