PageRenderTime 16ms CodeModel.GetById 7ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/historical/sqllog_lengths.py

https://bitbucket.org/lindenlab/apiary/
Python | 61 lines | 27 code | 10 blank | 24 comment | 7 complexity | a435c85d957a62da285f4b2760931207 MD5 | raw file
 1#
 2# $LicenseInfo:firstyear=2010&license=mit$
 3# 
 4# Copyright (c) 2010, Linden Research, Inc.
 5# 
 6# Permission is hereby granted, free of charge, to any person obtaining a copy
 7# of this software and associated documentation files (the "Software"), to deal
 8# in the Software without restriction, including without limitation the rights
 9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10# copies of the Software, and to permit persons to whom the Software is
11# furnished to do so, subject to the following conditions:
12# 
13# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the Software.
15# 
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22# THE SOFTWARE.
23# $/LicenseInfo$
24#
25
26import bisect
27import sys
28
29from sqllog import *
30from stattools import StatValue
31
32
33class SequenceLengths(FollowSequences):
34    def __init__(self):
35        FollowSequences.__init__(self)
36        self.num_sequences = 0
37        self.bucket_times = [ float(1<<i) for i in xrange(16) ]
38        self.bucket_counts = [ 0 for i in self.bucket_times ]        
39    
40    def addingSequence(self, s, e):
41        self.num_sequences += 1
42    
43    def notingEvent(self, s, e):
44        pass
45    
46    def removingSequence(self, s, e):
47        t = float(s.time())
48        i = bisect.bisect_left(self.bucket_times, t)
49        self.bucket_counts[i] += 1
50            
51    def writestats(self):
52        print "%30s:   %8d" % ('num_sequences', self.num_sequences)
53        print "Histogram of sequence lengths (log scale):"
54        for i in xrange(len(self.bucket_times)):
55            print "%30.1f:   %8d" % (self.bucket_times[i], self.bucket_counts[i])
56
57
58if __name__ == '__main__':
59    f = SequenceLengths()
60    f.replay(input_events(sys.argv[1:]))
61    f.writestats()