stablerange: add a debugstablerangecache command
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 08 Sep 2019 17:50:48 +0200
changeset 4837 b59231359479
parent 4836 e2465969958e
child 4838 bc0ea7666d4d
stablerange: add a debugstablerangecache command The command display get some data about stable range in a repository.
hgext3rd/evolve/stablerangecache.py
--- a/hgext3rd/evolve/stablerangecache.py	Sun Sep 08 17:49:26 2019 +0200
+++ b/hgext3rd/evolve/stablerangecache.py	Sun Sep 08 17:50:48 2019 +0200
@@ -14,6 +14,7 @@
 import time
 
 from mercurial import (
+    commands,
     encoding,
     error,
     localrepo,
@@ -423,6 +424,77 @@
             repo.ui.warn(b'(cache will not be saved)\n')
             super(sqlstablerange, self).warmup(repo, upto)
 
+@eh.command(
+    b'debugstablerangecache',
+    [] + commands.formatteropts,
+    _(b''))
+def debugstablerangecache(ui, repo, **opts):
+    """display data about the stable sort cache of a repository
+    """
+    unfi = repo.unfiltered()
+    revs = unfi.revs('all()')
+    nbrevs = len(revs)
+    ui.write('number of revisions:  %12d\n' % nbrevs)
+    heads = unfi.revs('heads(all())')
+    nbheads = len(heads)
+    ui.write('number of heads:      %12d\n' % nbheads)
+    merge = unfi.revs('merge()')
+    nbmerge = len(merge)
+    ui.write('number of merge:      %12d (%3d%%)\n'
+             % (nbmerge, 100 * nbmerge / nbrevs))
+    cache = unfi.stablerange
+    allsubranges = stablerange.subrangesclosure(unfi, cache, heads)
+    nbsubranges = len(allsubranges) - nbrevs # we remove leafs
+    ui.write('number of range:      %12d\n' % nbsubranges)
+    import collections
+    subsizedistrib = collections.defaultdict(lambda: 0)
+
+    def smallsize(r):
+        # This is computing the size it would take to store a range for a
+        # revision
+        #
+        # one int for the initial/top skip
+        # two int per middle ranges
+        # one int for the revision of the bottom part
+        return 4 * (2 + ((len(r) - 2) * 2))
+
+    totalsize = 0
+
+    allmiddleranges = []
+    for s in allsubranges:
+        sr = cache.subranges(repo, s)
+        srl = len(sr)
+        if srl == 0:
+            # leaf range are not interresting
+            continue
+        subsizedistrib[srl] += 1
+        allmiddleranges.append(s)
+        totalsize += smallsize(sr)
+
+    for ss in sorted(subsizedistrib):
+        ssc = subsizedistrib[ss]
+        ssp = ssc * 100 // nbsubranges
+        ui.write('  with %3d subranges: %12d (%3d%%)\n' % (ss, ssc, ssp))
+
+    depth = repo.depthcache.get
+    stdslice = 0
+    oddslice = 0
+
+    for s in allmiddleranges:
+        head, skip = s
+        d = depth(head)
+        k = d - 1
+        if (skip & k) == skip:
+            stdslice += 1
+        else:
+            oddslice += 1
+
+    ui.write('standard slice point cut: %12d (%3d%%)\n'
+             % (stdslice, stdslice * 100 // nbsubranges))
+    ui.write('other    slice point cut: %12d (%3d%%)\n'
+             % (oddslice, oddslice * 100 // nbsubranges))
+    ui.write('est. naive compact store: %12d bytes\n' % totalsize)
+
 @eh.reposetup
 def setupcache(ui, repo):