/toolkit/content/tests/fennec-tile-testapp/logread.py

http://github.com/zpao/v8monkey · Python · 104 lines · 87 code · 15 blank · 2 comment · 20 complexity · 7ed39c39d12799e8eb14dd1784962ee6 MD5 · raw file

  1. #!/usr/bin/python
  2. import re, sys
  3. interesting_re = re.compile("(js_Execute|CallHook) ([^ ]+) ([^ ]+ )?([^ ]+ms)")
  4. class Entry:
  5. def __init__(self, kind, depth, file, linenum, func, timetaken):
  6. self.kind = kind
  7. self.depth = depth
  8. self.file = file
  9. self.linenum = linenum
  10. self.func = func
  11. self.timetaken = timetaken
  12. self.calls = 0
  13. self.duration = 0
  14. def __str__(self):
  15. return " ".join(map(str,[self.kind, self.depth, self.file, self.linenum, self.func, self.timetaken]))
  16. def id(self):
  17. if self.kind == "js_Execute":
  18. return self.file
  19. else:
  20. if self.file and self.linenum:
  21. strout = "%s:%d" % (self.file, self.linenum)
  22. if self.func:
  23. strout = "%s %s" % (self.func, strout)
  24. return strout
  25. elif self.func:
  26. return self.func
  27. else:
  28. print("No clue what my id is:"+self)
  29. def call(self, timetaken):
  30. self.calls += 1
  31. self.duration += timetaken
  32. def parse_line(line):
  33. m = interesting_re.search(line)
  34. if not m:
  35. return None
  36. ms_index = line.find("ms")
  37. depth = m.start() - ms_index - 3
  38. kind = m.group(1)
  39. func = None
  40. file = None
  41. linenum = None
  42. if kind == "CallHook":
  43. func = m.group(2)
  44. file = m.group(3)
  45. colpos = file.rfind(":")
  46. (file,linenum) = file[:colpos], file[colpos+1:-1]
  47. if linenum == "0":
  48. linenum = None
  49. else:
  50. linenum = int(linenum)
  51. offset = 1
  52. else:
  53. file = m.group(3)
  54. timetaken = None
  55. try:
  56. timetaken = float(m.group(4)[:-2])
  57. except:
  58. return None
  59. return Entry(kind, depth, file, linenum, func, timetaken)
  60. def compare(x,y):
  61. diff = x[1].calls - y[1].calls
  62. if diff == 0:
  63. return int(x[1].duration - y[1].duration)
  64. elif diff > 0:
  65. return 1
  66. elif diff < 0:
  67. return -1
  68. def frequency(ls):
  69. dict = {}
  70. for item in ls:
  71. id = item.id()
  72. stat = None
  73. if not id in dict:
  74. stat = dict[id] = item
  75. else:
  76. stat = dict[id]
  77. stat.call(item.timetaken)
  78. ls = dict.items()
  79. ls.sort(compare)
  80. ls = filter(lambda (_,item): item.duration > 20, ls)
  81. # ls = filter(lambda (_,item): item.file and item.file.find("browser.js") != -1 and item.linenum <= 1223 and item.linenum >1067, ls)
  82. for key, item in ls:
  83. print(item.calls,key, str(item.duration)+"ms")
  84. def go():
  85. file = sys.argv[1]
  86. ls = filter(lambda x: x != None, map(parse_line, open(file).readlines()))
  87. frequency(ls)
  88. print ls[0]
  89. go()