changeset 40141:8643219146e1

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.
author Boris Feld <boris.feld@octobus.net>
date Mon, 01 Oct 2018 17:53:47 +0200
parents 46f9b1d2daf0
children 25ce80ce84c5
files contrib/perf.py tests/test-contrib-perf.t
diffstat 2 files changed, 45 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Mon Oct 01 17:37:53 2018 +0200
+++ b/contrib/perf.py	Mon Oct 01 17:53:47 2018 +0200
@@ -307,7 +307,7 @@
         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]
--- a/tests/test-contrib-perf.t	Mon Oct 01 17:37:53 2018 +0200
+++ b/tests/test-contrib-perf.t	Mon Oct 01 17:53:47 2018 +0200
@@ -207,6 +207,50 @@
   ! 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
 ----------------------------------------