[PATCH STABLE] statprof: sort by time percentage as a secondary key

Matt Harbison mharbison72 at gmail.com
Wed Oct 24 03:37:20 UTC 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1540351037 14400
#      Tue Oct 23 23:17:17 2018 -0400
# Branch stable
# Node ID 3662c0ac3ab4b256ecabb348cc91605ee8973abb
# Parent  49c7b701fdc2a8659b6f752aef507764d40ed5d0
statprof: sort by time percentage as a secondary key

On Windows, os.times() only returns user and system times.  Real elapsed time is
0.  That results in no actual times reported, an end wall time of 0.000000, and
seemingly randomly sorted stack frames.  This at least provides test stability
in test-profile.t.

diff --git a/mercurial/statprof.py b/mercurial/statprof.py
--- a/mercurial/statprof.py
+++ b/mercurial/statprof.py
@@ -501,7 +501,10 @@ def display_by_line(data, fp):
     '''Print the profiler data with each sample line represented
     as one row in a table.  Sorted by self-time per line.'''
     stats = SiteStats.buildstats(data.samples)
-    stats.sort(reverse=True, key=lambda x: x.selfseconds())
+
+    # Windows doesn't collect selfseconds, and everything is 0.  So break the
+    # tie and use selfpercent for test stability.
+    stats.sort(reverse=True, key=lambda x: (x.selfseconds(), x.selfpercent()))
 
     fp.write(b'%5.5s %10.10s   %7.7s  %-8.8s\n' % (
         b'%  ', b'cumulative', b'self', b''))


More information about the Mercurial-devel mailing list