diff mercurial/dispatch.py @ 8022:4f3fdfaa3874

profiling: Adding profiling.output config variable If specified, outputs profiling data to the said file. Prints to stderr by default
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Wed, 08 Apr 2009 14:19:41 +0200
parents 1c2cf2e5dc9b
children fd9debb3ea1b
line wrap: on
line diff
--- a/mercurial/dispatch.py	Wed Apr 08 14:18:20 2009 +0200
+++ b/mercurial/dispatch.py	Wed Apr 08 14:19:41 2009 +0200
@@ -379,6 +379,15 @@
             raise error.ParseError(cmd, _("invalid arguments"))
 
     if options['profile']:
+        output = ui.config('profiling', 'output')
+
+        if output:
+            path = os.path.expanduser(output)
+            path = ui.expandpath(path)
+            ostream = open(path, 'wb')
+        else:
+            ostream = sys.stderr
+
         try:
             from mercurial import lsprof
         except ImportError:
@@ -393,6 +402,9 @@
             p.disable()
             stats = lsprof.Stats(p.getstats())
             stats.sort()
-            stats.pprint(top=10, file=sys.stderr, climit=5)
+            stats.pprint(top=10, file=ostream, climit=5)
+
+            if output:
+                ostream.close()
     else:
         return checkargs()