[PATCH 2 of 4] profiling: Adding profiling.output config variable

Nicolas Dumazet nicdumz at gmail.com
Thu Apr 2 04:31:45 CDT 2009


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1238655690 -32400
# Node ID 682b8c4edf4cbf285a09c483a0cc48df76c76003
# Parent  506f038fa0e7c714dbe6b51e478b1bb8467a4177
profiling: Adding profiling.output config variable

If specified, outputs profiling data to the said file.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -380,6 +380,7 @@
 
     if options['profile'] or options['lsprof']:
         format = ui.config('profiling', 'format')
+        output = ui.config('profiling', 'output')
 
         if format and not format in ['hotshot', 'lsprof']:
             ui.warning(_("Unknown profiling format '%s'"
@@ -393,6 +394,10 @@
             else:
                 # options['lsprof']
                 format = 'lsprof'
+
+        if output:
+            output = os.path.expanduser(output)
+            output = ui.expandpath(output)
 
         if format == 'hotshot':
             import hotshot, hotshot.stats
@@ -412,7 +417,10 @@
                 stats = hotshot.stats.load("hg.prof")
                 stats.strip_dirs()
                 stats.sort_stats('time', 'calls')
-                stats.print_stats(40)
+                if output:
+                    stats.dump_stats(output)
+                else:
+                    stats.print_stats(40)
         elif format == 'lsprof':
             try:
                 from mercurial import lsprof
@@ -428,6 +436,13 @@
                 p.disable()
                 stats = lsprof.Stats(p.getstats())
                 stats.sort()
-                stats.pprint(top=10, file=sys.stderr, climit=5)
+                if output:
+                    ostream = open(output, 'wb')
+                else:
+                    ostream = sys.stderr
+                stats.pprint(top=10, file=ostream, climit=5)
+
+                if output:
+                    ostream.close()
     else:
         return checkargs()


More information about the Mercurial-devel mailing list