PageRenderTime 1238ms CodeModel.GetById 1227ms RepoModel.GetById 0ms app.codeStats 0ms

/historical/sqllog_lengths.py

https://bitbucket.org/lindenlab/apiary/
Python | 61 lines | 27 code | 10 blank | 24 comment | 4 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. import bisect
  26. import sys
  27. from sqllog import *
  28. from stattools import StatValue
  29. class SequenceLengths(FollowSequences):
  30. def __init__(self):
  31. FollowSequences.__init__(self)
  32. self.num_sequences = 0
  33. self.bucket_times = [ float(1<<i) for i in xrange(16) ]
  34. self.bucket_counts = [ 0 for i in self.bucket_times ]
  35. def addingSequence(self, s, e):
  36. self.num_sequences += 1
  37. def notingEvent(self, s, e):
  38. pass
  39. def removingSequence(self, s, e):
  40. t = float(s.time())
  41. i = bisect.bisect_left(self.bucket_times, t)
  42. self.bucket_counts[i] += 1
  43. def writestats(self):
  44. print "%30s: %8d" % ('num_sequences', self.num_sequences)
  45. print "Histogram of sequence lengths (log scale):"
  46. for i in xrange(len(self.bucket_times)):
  47. print "%30.1f: %8d" % (self.bucket_times[i], self.bucket_counts[i])
  48. if __name__ == '__main__':
  49. f = SequenceLengths()
  50. f.replay(input_events(sys.argv[1:]))
  51. f.writestats()