changeset 51073:752e380c5702

debug-delta-chain: add options to control what we compute Currently this mostly controls what we display, but actual computation saving will come soon.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 19 Sep 2023 01:53:03 +0200
parents 810446d2d5ef
children 5b5cb6b833b0
files mercurial/debugcommands.py mercurial/revlogutils/debug.py tests/test-completion.t
diffstat 3 files changed, 125 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Tue Sep 19 01:24:10 2023 +0200
+++ b/mercurial/debugcommands.py	Tue Sep 19 01:53:03 2023 +0200
@@ -753,6 +753,24 @@
             [],
             _('restrict processing to these revlog revisions'),
         ),
+        (
+            b'',
+            b'size-info',
+            True,
+            _('compute information related to deltas size'),
+        ),
+        (
+            b'',
+            b'dist-info',
+            True,
+            _('compute information related to base distance'),
+        ),
+        (
+            b'',
+            b'sparse-info',
+            True,
+            _('compute information related to sparse read'),
+        ),
     ]
     + cmdutil.debugrevlogopts
     + cmdutil.formatteropts,
@@ -767,8 +785,10 @@
     :``rev``:       revision number
     :``p1``:        parent 1 revision number (for reference)
     :``p2``:        parent 2 revision number (for reference)
+
     :``chainid``:   delta chain identifier (numbered by unique base)
     :``chainlen``:  delta chain length to this revision
+
     :``prevrev``:   previous revision in delta chain
     :``deltatype``: role of delta / how it was computed
                     - base:  a full snapshot
@@ -781,11 +801,13 @@
                               (when p2 has empty delta
                     - prev:  a delta against the previous revision
                     - other: a delta against an arbitrary revision
+
     :``compsize``:  compressed size of revision
     :``uncompsize``: uncompressed size of revision
     :``chainsize``: total size of compressed revisions in chain
     :``chainratio``: total chain size divided by uncompressed revision size
                     (new delta chains typically start at ratio 2.00)
+
     :``lindist``:   linear distance from base revision in delta chain to end
                     of this revision
     :``extradist``: total size of revisions not part of this delta chain from
@@ -804,18 +826,64 @@
     :``readdensity``:  density of useful bytes in the data read from the disk
     :``srchunks``:  in how many data hunks the whole revision would be read
 
+    It is possible to select the information to be computed, this can provide a
+    noticeable speedup to the command in some cases.
+
+    Always computed:
+
+    - ``rev``
+    - ``p1``
+    - ``p2``
+    - ``chainid``
+    - ``chainlen``
+    - ``prevrev``
+    - ``deltatype``
+
+    Computed with --no-size-info
+
+    - ``compsize``
+    - ``uncompsize``
+    - ``chainsize``
+    - ``chainratio``
+
+    Computed with --no-dist-info
+
+    - ``lindist``
+    - ``extradist``
+    - ``extraratio``
+
+    Skipped with --no-sparse-info
+
+    - ``readsize``
+    - ``largestblock``
+    - ``readdensity``
+    - ``srchunks``
+
+    --
+
     The sparse read can be enabled with experimental.sparse-read = True
     """
     revs = None
     revs_opt = opts.pop('rev', [])
     if revs_opt:
         revs = [int(r) for r in revs_opt]
+
+    size_info = opts.pop('size_info', True)
+    dist_info = opts.pop('dist_info', True)
+    sparse_info = opts.pop('sparse_info', True)
+
     revlog = cmdutil.openrevlog(
         repo, b'debugdeltachain', file_, pycompat.byteskwargs(opts)
     )
     fm = ui.formatter(b'debugdeltachain', pycompat.byteskwargs(opts))
 
-    lines = revlog_debug.debug_delta_chain(revlog, revs=revs)
+    lines = revlog_debug.debug_delta_chain(
+        revlog,
+        revs=revs,
+        size_info=size_info,
+        dist_info=dist_info,
+        sparse_info=sparse_info,
+    )
     # first entry is the header
     header = next(lines)
     fm.plain(header)
--- a/mercurial/revlogutils/debug.py	Tue Sep 19 01:24:10 2023 +0200
+++ b/mercurial/revlogutils/debug.py	Tue Sep 19 01:53:03 2023 +0200
@@ -798,10 +798,24 @@
             chain_size += e[constants.ENTRY_DATA_COMPRESSED_LENGTH]
         self._chain_size_cache[rev] = chain_size
 
-        return p1, p2, compsize, uncompsize, deltatype, chain, chain_size
+        return {
+            'p1': p1,
+            'p2': p2,
+            'compressed_size': compsize,
+            'uncompressed_size': uncompsize,
+            'deltatype': deltatype,
+            'chain': chain,
+            'chain_size': chain_size,
+        }
 
 
-def debug_delta_chain(revlog, revs=None):
+def debug_delta_chain(
+    revlog,
+    revs=None,
+    size_info=True,
+    dist_info=True,
+    sparse_info=True,
+):
     auditor = DeltaChainAuditor(revlog)
     r = revlog
     start = r.start
@@ -809,12 +823,20 @@
     withsparseread = revlog.data_config.with_sparse_read
 
     header = (
-        b'    rev      p1      p2  chain# chainlen     prev   delta       '
-        b'size    rawsize  chainsize     ratio   lindist extradist '
-        b'extraratio'
+        b'    rev'
+        b'      p1'
+        b'      p2'
+        b'  chain#'
+        b' chainlen'
+        b'     prev'
+        b'   delta'
     )
-    if withsparseread:
-        header += b'   readsize largestblk rddensity srchunks'
+    if size_info:
+        header += b'       size' b'    rawsize' b'  chainsize' b'     ratio'
+    if dist_info:
+        header += b'   lindist' b' extradist' b' extraratio'
+    if withsparseread and sparse_info:
+        header += b'   readsize' b' largestblk' b' rddensity' b' srchunks'
     header += b'\n'
     yield header
 
@@ -826,12 +848,16 @@
 
     chainbases = {}
     for rev in all_revs:
-        p1, p2, comp, uncomp, deltatype, chain, chainsize = auditor.revinfo(rev)
+        info = auditor.revinfo(rev)
+        comp = info['compressed_size']
+        uncomp = info['uncompressed_size']
+        chain = info['chain']
         chainbase = chain[0]
         chainid = chainbases.setdefault(chainbase, len(chainbases) + 1)
         basestart = start(chainbase)
         revstart = start(rev)
         lineardist = revstart + comp - basestart
+        chainsize = info['chain_size']
         extradist = lineardist - chainsize
         try:
             prevrev = chain[-2]
@@ -851,21 +877,31 @@
         # label, display-format, data-key, value
         entry = [
             (b'rev', b'%7d', 'rev', rev),
-            (b'p1', b'%7d', 'p1', p1),
-            (b'p2', b'%7d', 'p2', p2),
+            (b'p1', b'%7d', 'p1', info['p1']),
+            (b'p2', b'%7d', 'p2', info['p2']),
             (b'chainid', b'%7d', 'chainid', chainid),
             (b'chainlen', b'%8d', 'chainlen', len(chain)),
             (b'prevrev', b'%8d', 'prevrev', prevrev),
-            (b'deltatype', b'%7s', 'deltatype', deltatype),
-            (b'compsize', b'%10d', 'compsize', comp),
-            (b'uncompsize', b'%10d', 'uncompsize', uncomp),
-            (b'chainsize', b'%10d', 'chainsize', chainsize),
-            (b'chainratio', b'%9.5f', 'chainratio', chainratio),
-            (b'lindist', b'%9d', 'lindist', lineardist),
-            (b'extradist', b'%9d', 'extradist', extradist),
-            (b'extraratio', b'%10.5f', 'extraratio', extraratio),
+            (b'deltatype', b'%7s', 'deltatype', info['deltatype']),
         ]
-        if withsparseread:
+        if size_info:
+            entry.extend(
+                [
+                    (b'compsize', b'%10d', 'compsize', comp),
+                    (b'uncompsize', b'%10d', 'uncompsize', uncomp),
+                    (b'chainsize', b'%10d', 'chainsize', chainsize),
+                    (b'chainratio', b'%9.5f', 'chainratio', chainratio),
+                ]
+            )
+        if dist_info:
+            entry.extend(
+                [
+                    (b'lindist', b'%9d', 'lindist', lineardist),
+                    (b'extradist', b'%9d', 'extradist', extradist),
+                    (b'extraratio', b'%10.5f', 'extraratio', extraratio),
+                ]
+            )
+        if withsparseread and sparse_info:
             readsize = 0
             largestblock = 0
             srchunks = 0
--- a/tests/test-completion.t	Tue Sep 19 01:24:10 2023 +0200
+++ b/tests/test-completion.t	Tue Sep 19 01:53:03 2023 +0200
@@ -296,7 +296,7 @@
   debugdag: tags, branches, dots, spaces
   debugdata: changelog, manifest, dir
   debugdate: extended
-  debugdeltachain: rev, changelog, manifest, dir, template
+  debugdeltachain: rev, size-info, dist-info, sparse-info, changelog, manifest, dir, template
   debugdirstateignorepatternshash: 
   debugdirstate: nodates, dates, datesort, docket, all
   debugdiscovery: old, nonheads, rev, seed, local-as-revs, remote-as-revs, ssh, remotecmd, insecure, template