PageRenderTime 28ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/historical/sqllog_stats.py

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