[devtools] ExamineLog command does not fail on strange input and outputs to csv
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Sun, 29 Mar 2009 19:06:49 +0200
changeset 1188 6937dfb242fb
parent 1187 450c435d69b9
child 1189 8a075bc94563
[devtools] ExamineLog command does not fail on strange input and outputs to csv
devtools/devctl.py
--- a/devtools/devctl.py	Fri Mar 27 12:27:43 2009 +0100
+++ b/devtools/devctl.py	Sun Mar 29 19:06:49 2009 +0200
@@ -513,17 +513,20 @@
             raise BadCommandUsage("no argument expected")
         import re
         requests = {}
-        for line in sys.stdin:
+        for lineno, line in enumerate(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 )
+            try:
+                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 )
+            except Exception, exc:
+                sys.stderr.write('Line %s: %s\n' % (lineno, exc))
 
         stat = []
         for rql, times in requests.items():
@@ -531,8 +534,9 @@
 
         stat.sort()
         stat.reverse()
+        print 'Time ; Occurences ; Query'
         for time, occ, rql in stat:
-            print time, occ, rql
+            print time, ';', occ, ';', rql
         
 register_commands((UpdateCubicWebCatalogCommand,
                    UpdateTemplateCatalogCommand,