[PATCH 1 of 4] perftest: add perfbranchmap command

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Fri Jan 11 12:17:52 CST 2013


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at 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.

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)
+
+ at 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
+
+
+


More information about the Mercurial-devel mailing list