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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial