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

login
register
mail settings
Submitter Matt Harbison
Date Oct. 24, 2018, 3:37 a.m.
Message ID <3662c0ac3ab4b256ecab.1540352240@Envy>
Download mbox | patch
Permalink /patch/36260/
State New
Headers show

Comments

Matt Harbison - Oct. 24, 2018, 3:37 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@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.
Yuya Nishihara - Oct. 24, 2018, 10:55 a.m.
On Tue, 23 Oct 2018 23:37:20 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@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.

Sounds like we should change the default back to 'cpu' globally, or at least
on Windows.

Patch

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''))