Patchwork [8,of,9] revsetbenchmark: retrieve the benchmark value in python

login
register
mail settings
Submitter Pierre-Yves David
Date March 27, 2014, 2:49 a.m.
Message ID <9f9883d1c6dba67d5ed7.1395888549@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4087/
State Accepted
Commit bad5399c5d5f333777e4805878fd235ea74d955d
Headers show

Comments

Pierre-Yves David - March 27, 2014, 2:49 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1395884396 25200
#      Wed Mar 26 18:39:56 2014 -0700
# Node ID 9f9883d1c6dba67d5ed79f59b5d544b136f43dd4
# Parent  84e82f401d6024eff76dbb07e8f6c793b89ae035
revsetbenchmark: retrieve the benchmark value in python

We retrieve the output of the perf extension and print it ourself. This open the
door to processing of this data in the script.

Patch

diff --git a/contrib/revsetbenchmarks.py b/contrib/revsetbenchmarks.py
--- a/contrib/revsetbenchmarks.py
+++ b/contrib/revsetbenchmarks.py
@@ -12,11 +12,11 @@ 
 #
 # This script also does one run of the current version of mercurial installed
 # to compare performance.
 
 import sys
-from subprocess import check_call, check_output, CalledProcessError
+from subprocess import check_call, check_output, CalledProcessError, STDOUT
 
 
 def update(rev):
     """update the repo to a revision"""
     try:
@@ -26,12 +26,18 @@  def update(rev):
         sys.exit(exc.returncode)
 
 def perf(revset):
     """run benchmark for this very revset"""
     try:
-        check_call(['./hg', '--config', 'extensions.perf=contrib/perf.py',
-                    'perfrevset', revset])
+        output = check_output(['./hg',
+                               '--config',
+                               'extensions.perf=contrib/perf.py',
+                               'perfrevset',
+                               revset],
+                               stderr=STDOUT)
+        output = output.lstrip('!') # remove useless ! in this context
+        return output.strip()
     except CalledProcessError, exc:
         print >> sys.stderr, 'abort: cannot run revset benchmark'
         sys.exit(exc.returncode)
 
 def printrevision(rev):
@@ -76,10 +82,9 @@  for r in revs:
     print "----------------------------"
     printrevision(r)
     print "----------------------------"
     update(r)
     for idx, rset in enumerate(revsets):
-        sys.stdout.write("%i) " % idx)
-        sys.stdout.flush()
-        perf(rset)
+
+        print "%i)" % idx, perf(rset)
     print "----------------------------"