Patchwork [2,of,8] perf: fix -T json

login
register
mail settings
Submitter Boris Feld
Date Oct. 11, 2018, 8:01 a.m.
Message ID <902b76fa8a8540987dc3.1539244905@localhost.localdomain>
Download mbox | patch
Permalink /patch/35625/
State Accepted
Headers show

Comments

Boris Feld - Oct. 11, 2018, 8:01 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1538409227 -7200
#      Mon Oct 01 17:53:47 2018 +0200
# Node ID 902b76fa8a8540987dc34456fb1dd54a0144b28c
# Parent  8eaff9311fa407d89854d6e60938200939a0a506
# EXP-Topic revlog-perf
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 902b76fa8a85
perf: fix -T json

The previous code was mixing formatting and data, breaking `-T json` with
unexpected data. We fix the issue and add a test to prevent future regression.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -307,7 +307,7 @@  def _timer(fm, func, title=None, display
         fm.write(prefix + b'comb', b' comb %f', entry[1] + entry[2])
         fm.write(prefix + b'user', b' user %f', entry[1])
         fm.write(prefix + b'sys',  b' sys %f', entry[2])
-        fm.write(prefix + b'count',  b' (%s of %d)', role, count)
+        fm.write(prefix + b'count',  b' (%s of %%d)' % role, count)
         fm.plain(b'\n')
     results.sort()
     min_val = results[0]
diff --git a/tests/test-contrib-perf.t b/tests/test-contrib-perf.t
--- a/tests/test-contrib-perf.t
+++ b/tests/test-contrib-perf.t
@@ -207,6 +207,50 @@  detailed output:
   ! wall * comb * user * sys * (avg of *) (glob)
   ! wall * comb * user * sys * (median of *) (glob)
 
+test json output
+----------------
+
+normal output:
+
+  $ hg perfheads --template json --config perf.stub=no
+  [
+   {
+    "comb": *, (glob)
+    "count": *, (glob)
+    "sys": *, (glob)
+    "user": *, (glob)
+    "wall": * (glob)
+   }
+  ]
+
+detailed output:
+
+  $ hg perfheads --template json --config perf.all-timing=yes --config perf.stub=no
+  [
+   {
+    "avg.comb": *, (glob)
+    "avg.count": *, (glob)
+    "avg.sys": *, (glob)
+    "avg.user": *, (glob)
+    "avg.wall": *, (glob)
+    "comb": *, (glob)
+    "count": *, (glob)
+    "max.comb": *, (glob)
+    "max.count": *, (glob)
+    "max.sys": *, (glob)
+    "max.user": *, (glob)
+    "max.wall": *, (glob)
+    "median.comb": *, (glob)
+    "median.count": *, (glob)
+    "median.sys": *, (glob)
+    "median.user": *, (glob)
+    "median.wall": *, (glob)
+    "sys": *, (glob)
+    "user": *, (glob)
+    "wall": * (glob)
+   }
+  ]
+
 Check perf.py for historical portability
 ----------------------------------------