chiark / gitweb /
Log subprocess calls during performance testing
authorKarl Hasselström <kha@treskal.com>
Wed, 23 Jul 2008 21:29:10 +0000 (23:29 +0200)
committerKarl Hasselström <kha@treskal.com>
Thu, 24 Jul 2008 22:03:14 +0000 (00:03 +0200)
Log each command's subprocess calls to a separate file.

Signed-off-by: Karl Hasselström <kha@treskal.com>
perf/perftest.py

index 70727727a8edffdf56ec16bab84bd4edf40e7f51..e5ed04bf9cce08a2033342727109dcec7526b99c 100644 (file)
@@ -1,4 +1,4 @@
-import datetime, subprocess, sys
+import datetime, os, os.path, subprocess, sys
 
 def duration(t1, t2):
     d = t2 - t1
@@ -8,8 +8,16 @@ class Run(object):
     def __init__(self):
         self.__cwd = None
         self.__log = []
+    def __logfile(self, cmd):
+        fn = os.path.join(os.getcwd(), '%04d.log' % len(self.__log))
+        f = open(fn, 'w')
+        f.write(' '.join(cmd) + '\n' + '-'*70 + '\n\n')
+        f.close()
+        return fn
     def __call__(self, *cmd, **args):
-        kwargs = { 'cwd': self.__cwd }
+        env = dict(os.environ)
+        env['STGIT_SUBPROCESS_LOG'] = 'profile:' + self.__logfile(cmd)
+        kwargs = { 'cwd': self.__cwd, 'env': env }
         if args.get('capture_stdout', False):
             kwargs['stdout'] = subprocess.PIPE
         start = datetime.datetime.now()