PageRenderTime 89ms CodeModel.GetById 40ms app.highlight 9ms RepoModel.GetById 31ms app.codeStats 6ms

/historical/sqllog_stats.py

https://bitbucket.org/lindenlab/apiary/
Python | 110 lines | 69 code | 17 blank | 24 comment | 6 complexity | 90a942371ce9c3a36af7c0abcbedb945 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 sys
 27
 28from sqllog import *
 29from stattools import StatValue
 30
 31
 32class StatSequences(FollowSequences):
 33    def __init__(self):
 34        FollowSequences.__init__(self)
 35        self.num_events = 0
 36        self.num_sequences = 0
 37        self.count_active_sequences = 0
 38        self.num_forced_end = 0
 39        self.stat_active_sequences = StatValue()
 40        self.stat_response_time = StatValue()
 41        self.stat_response_time_long = StatValue()
 42        self.stat_inter_query_time = StatValue()
 43        self.stat_inter_query_time_long = StatValue()
 44        self.stat_sequence_time = StatValue()
 45        self.stat_sequence_time_long = StatValue()
 46        
 47    
 48    def addingSequence(self, s, e):
 49        self.num_sequences += 1
 50        self.count_active_sequences += 1
 51    
 52    def notingEvent(self, s, e):
 53        self.num_events += 1
 54        self.stat_active_sequences.sample(self.count_active_sequences)
 55        
 56        stat_short = self.stat_inter_query_time
 57        stat_long = self.stat_inter_query_time_long        
 58        if e.state == Event.Response:
 59            stat_short = self.stat_response_time
 60            stat_long = self.stat_response_time_long
 61
 62        t = s.timeto(e)
 63        if t is not None:
 64            t = float(t)
 65            if t < 1.0:
 66                stat_short.sample(t)
 67            else:
 68                stat_long.sample(t)
 69        pass
 70    
 71    def forcedEnd(self, s, e):
 72        self.num_forced_end += 1
 73        
 74    def removingSequence(self, s, e):
 75        self.count_active_sequences -= 1
 76        t = float(s.time())
 77        if t < 1.0:
 78            self.stat_sequence_time.sample(t)
 79        else:
 80            self.stat_sequence_time_long.sample(t)
 81            
 82    def format(self, stat):
 83        return stat.format("%8d", "%8.2f")
 84        
 85    def writestats(self):
 86        print "%30s:   %8d" % ('num_events', self.num_events)
 87        print "%30s:   %8d" % ('num_sequences', self.num_sequences)
 88        print "%30s:   %8d" % ('num_forced_end', self.num_forced_end)
 89        print "%30s: %s" % ('stat_active_sequences',
 90                                self.format(self.stat_active_sequences))
 91        print "%30s: %s" % ('stat_response_time <1s',
 92                                self.format(self.stat_response_time))
 93        print "%30s: %s" % ('stat_response_time_long >1s',
 94                                self.format(self.stat_response_time_long))
 95        print "%30s: %s" % ('stat_inter_query_time <1s',
 96                                self.format(self.stat_inter_query_time))
 97        print "%30s: %s" % ('stat_inter_query_time_long >1s',
 98                                self.format(self.stat_inter_query_time_long))
 99        print "%30s: %s" % ('stat_sequence_time <1s',
100                                self.format(self.stat_sequence_time))
101        print "%30s: %s" % ('stat_sequence_time >1s',
102                                self.format(self.stat_sequence_time_long))
103
104
105
106
107if __name__ == '__main__':
108    f = StatSequences()
109    f.replay(input_events(sys.argv[1:]))
110    f.writestats()