Patchwork [1,of,4] perftest: add perfbranchmap command

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 11, 2013, 6:17 p.m.
Message ID <fa58abc613ba57fdbbdb.1357928272@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/543/
State Accepted
Headers show

Comments

Pierre-Yves David - Jan. 11, 2013, 6:17 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1357925983 -3600
# Node ID fa58abc613ba57fdbbdbe265ab00be2fbf82fad7
# Parent  65cec7fa5472ed4c91f246dccd6e05ac49af02ab
perftest: add perfbranchmap command

The commands times the update of a branchmap from it's nearest subset or from
scratch.
Bryan O'Sullivan - Jan. 12, 2013, 4:41 a.m.
On Fri, Jan 11, 2013 at 07:17:52PM +0100, pierre-yves.david@logilab.fr wrote:
> perftest: add perfbranchmap command

Nice work - in crew now, thanks.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -1,10 +1,10 @@ 
 # perf.py - performance test routines
 '''helper extension to measure performance'''
 
 from mercurial import cmdutil, scmutil, util, match, commands, obsolete
-from mercurial import repoview
+from mercurial import repoview, branchmap
 import time, os, sys
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
@@ -307,5 +307,60 @@  def perfvolatilesets(ui, repo, *names):
     if names:
         allfilter = [n for n in allfilter if n in names]
 
     for name in allfilter:
         timer(getfiltered(name), title=name)
+
+@command('perfbranchmap',
+         [('f', 'full', False,
+           'Includes build time of subset'),
+         ])
+def perfbranchmap(ui, repo, full=False):
+    """benchmark the update of a branchmap
+
+    This benchmark the full repo.branchmap() call with read and write disabled
+    """
+    def getbranchmap(filtername):
+        """generate a benchmark function for the filtername"""
+        if filtername is None:
+            view = repo
+        else:
+            view = repo.filtered(filtername)
+        def d():
+            if full:
+                view._branchcaches.clear()
+            else:
+                view._branchcaches.pop(filtername, None)
+            view.branchmap()
+        return d
+    # add filter in smaller subset to bigger subset
+    possiblefilters = set(repoview.filtertable)
+    allfilters = []
+    while possiblefilters:
+        for name in possiblefilters:
+            subset = repoview.subsettable.get(name)
+            if subset not in possiblefilters:
+                break
+        else:
+            assert False, 'subset cycle %s!' % possiblefilters
+        allfilters.append(name)
+        possiblefilters.remove(name)
+
+    # warm the cache
+    if not full:
+        for name in allfilters:
+            repo.filtered(name).branchmap()
+    # add unfiltered
+    allfilters.append(None)
+    oldread = branchmap.read
+    oldwrite = branchmap.branchcache.write
+    try:
+        branchmap.read = lambda repo: None
+        branchmap.write = lambda repo: None
+        for name in allfilters:
+            timer(getbranchmap(name), title=str(name))
+    finally:
+        branchmap.read = oldread
+        branchmap.branchcache.write = oldwrite
+
+
+