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.

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

mercurial