# HG changeset patch # User Sylvain Thenault # Date 1231435599 -3600 # Node ID 89225b187eb856402a173a4b9c77e233cdb80ac7 # Parent 0c931b2e2a68b481b439e8d8f53cd475cc3938d7 turn exlog into a cw-ctl command diff -r 0c931b2e2a68 -r 89225b187eb8 devtools/devctl.py --- a/devtools/devctl.py Thu Jan 08 16:56:23 2009 +0100 +++ b/devtools/devctl.py Thu Jan 08 18:26:39 2009 +0100 @@ -176,6 +176,7 @@ add_msg(w, '%s_description' % objid) add_msg(w, objid) done.add(objid) + def defined_in_library(libschema, etype, rtype, tetype, x): """return true if the given relation definition exists in cubicweb's library""" @@ -478,9 +479,54 @@ break return includes + +class ExamineLogCommand(Command): + """Examine a rql log file. + + usage: python exlog.py < rql.log + + will print out the following table + + total execution time || number of occurences || rql query + + sorted by descending total execution time + + chances are the lines at the top are the ones that will bring + the higher benefit after optimisation. Start there. + """ + name = 'exlog' + options = ( + ) + + def run(self, args): + if args: + raise BadCommandUsage("no argument expected") + import re + requests = {} + for line in sys.stdin: + if not ' WHERE ' in line: + continue + #sys.stderr.write( line ) + rql, time = line.split('--') + rql = re.sub("(\'\w+': \d*)", '', rql) + req = requests.setdefault(rql, []) + time.strip() + chunks = time.split() + cputime = float(chunks[-3]) + req.append( cputime ) + + stat = [] + for rql, times in requests.items(): + stat.append( (sum(times), len(times), rql) ) + + stat.sort() + stat.reverse() + for time, occ, rql in stat: + print time, occ, rql register_commands((UpdateCubicWebCatalogCommand, UpdateTemplateCatalogCommand, LiveServerCommand, NewCubeCommand, + ExamineLogCommand, )) diff -r 0c931b2e2a68 -r 89225b187eb8 devtools/exlog.py --- a/devtools/exlog.py Thu Jan 08 16:56:23 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -""" -usage: python exlog.py < rql.log - -will print out the following table - - total execution time || number of occurences || rql query - -sorted by descending total execution time - -chances are the lines at the top are the ones that will bring -the higher benefit after optimisation. Start there. -""" -import sys, re - -def run(): - requests = {} - for line in sys.stdin: - if not ' WHERE ' in line: - continue - #sys.stderr.write( line ) - rql, time = line.split('--') - rql = re.sub("(\'\w+': \d*)", '', rql) - req = requests.setdefault(rql, []) - time.strip() - chunks = time.split() - cputime = float(chunks[-3]) - req.append( cputime ) - - stat = [] - for rql, times in requests.items(): - stat.append( (sum(times), len(times), rql) ) - - stat.sort() - stat.reverse() - for time, occ, rql in stat: - print time, occ, rql - -if __name__ == '__main__': - run()