devtools/exlog.py
changeset 374 89225b187eb8
parent 373 0c931b2e2a68
child 375 2901cebaf603
equal deleted inserted replaced
373:0c931b2e2a68 374:89225b187eb8
     1 """
       
     2 usage: python exlog.py < rql.log
       
     3 
       
     4 will print out the following table
       
     5 
       
     6   total execution time || number of occurences || rql query
       
     7 
       
     8 sorted by descending total execution time
       
     9 
       
    10 chances are the lines at the top are the ones that will bring
       
    11 the higher benefit after optimisation. Start there.
       
    12 """
       
    13 import sys, re
       
    14 
       
    15 def run():
       
    16     requests = {}
       
    17     for line in sys.stdin:
       
    18         if not ' WHERE ' in line:
       
    19             continue
       
    20         #sys.stderr.write( line )
       
    21         rql, time = line.split('--')
       
    22         rql = re.sub("(\'\w+': \d*)", '', rql)
       
    23         req = requests.setdefault(rql, [])
       
    24         time.strip()
       
    25         chunks = time.split()
       
    26         cputime = float(chunks[-3])
       
    27         req.append( cputime )
       
    28 
       
    29     stat = []
       
    30     for rql, times in requests.items():
       
    31         stat.append( (sum(times), len(times), rql) )
       
    32 
       
    33     stat.sort()
       
    34     stat.reverse()
       
    35     for time, occ, rql in stat:
       
    36         print time, occ, rql
       
    37 
       
    38 if __name__ == '__main__':
       
    39     run()