evolve: add a debugobsstorestat command
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 20 Feb 2014 13:59:49 -0800
changeset 807 4dd1cda16fd0
parent 806 895fadf6ba3e
child 808 81a3d9a24e6b
evolve: add a debugobsstorestat command This commands print multiple some data about the content of the obsstore. This will be usefull to provide some metric and insight for obsolescence marker exchange.
hgext/evolve.py
tests/test-evolve.t
--- a/hgext/evolve.py	Wed Feb 19 17:27:45 2014 -0800
+++ b/hgext/evolve.py	Thu Feb 20 13:59:49 2014 -0800
@@ -860,6 +860,41 @@
      _('record the specified user in metadata'), _('USER')),
 ]
 
+@command('debugobsstorestat', [], '')
+def cmddebugobsstorestat(ui, repo):
+    """print statistic about obsolescence markers in the repo"""
+    store = repo.obsstore
+    unfi = repo.unfiltered()
+    nm = unfi.changelog.nodemap
+    ui.write('markers total:              %9i\n' % len(store._all))
+    sucscount = [0, 0 , 0, 0]
+    known = 0
+    metatotallenght = 0
+    metakeys = {}
+    for mark in store:
+        if mark[0] in nm:
+            known += 1
+        nbsucs = len(mark[1])
+        sucscount[min(nbsucs, 3)] += 1
+        metatotallenght += len(mark[3])
+        meta = obsolete.decodemeta(mark[3])
+        for key in meta:
+            metakeys.setdefault(key, 0)
+            metakeys[key] += 1
+
+    ui.write('    for known precursors:   %9i\n' % known)
+    # successors data
+    ui.write('markers with no successors: %9i\n' % sucscount[0])
+    ui.write('              1 successors: %9i\n' % sucscount[1])
+    ui.write('              2 successors: %9i\n' % sucscount[2])
+    ui.write('    more than 2 successors: %9i\n' % sucscount[3])
+    # meta data info
+    ui.write('average meta length:        %9i\n'
+             % (metatotallenght/len(store._all)))
+    ui.write('    available  keys:\n')
+    for key in sorted(metakeys):
+        ui.write('    %15s:        %9i\n' % (key, metakeys[key]))
+
 
 @command('^evolve|stabilize|solve',
     [('n', 'dry-run', False, 'do not perform actions, print what to be done'),
--- a/tests/test-evolve.t	Wed Feb 19 17:27:45 2014 -0800
+++ b/tests/test-evolve.t	Thu Feb 20 13:59:49 2014 -0800
@@ -645,3 +645,17 @@
   4	: add 4 - test
   5	: add 3 - test
   11	: add 1 - test
+
+Test obsstore stat
+
+  $ hg debugobsstorestat
+  markers total:                     10
+      for known precursors:          10
+  markers with no successors:         0
+                1 successors:        10
+                2 successors:         0
+      more than 2 successors:         0
+  average meta length:               27
+      available  keys:
+                 date:               10
+                 user:               10