Patchwork [06,of,10] debugrevlog: display snapshot details per depth

login
register
mail settings
Submitter Boris Feld
Date Aug. 16, 2018, 1:43 p.m.
Message ID <e78ae4e123a35629a1fd.1534426993@FB-lair>
Download mbox | patch
Permalink /patch/33782/
State Accepted
Headers show

Comments

Boris Feld - Aug. 16, 2018, 1:43 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1534329030 -7200
#      Wed Aug 15 12:30:30 2018 +0200
# Node ID e78ae4e123a35629a1fd25bf264c7be812e1c8e3
# Parent  0543f2d7c86af60df21a51b0dc826780400d3a62
# EXP-Topic sparse-snapshot
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r e78ae4e123a3
debugrevlog: display snapshot details per depth

This help in understanding the final structure of build manifest. All data
about snapshot (full and intermediate) are gathered into a sub-list for
clarity.

Since we do not produce such snapshots yet, the only thing changing in test
output is the way the information is presented.

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -2097,6 +2097,8 @@  def debugrevlog(ui, repo, file_=None, **
     numfull = 0
     # intermediate snapshot against a prior snapshot
     numsemi = 0
+    # snapshot count per depth
+    numsnapdepth = collections.defaultdict(lambda: 0)
     # delta against previous revision
     numprev = 0
     # delta against first or second parent (not prev)
@@ -2118,6 +2120,8 @@  def debugrevlog(ui, repo, file_=None, **
     datasize = [None, 0, 0]
     fullsize = [None, 0, 0]
     semisize = [None, 0, 0]
+    # snapshot count per depth
+    snapsizedepth = collections.defaultdict(lambda: [None, 0, 0])
     deltasize = [None, 0, 0]
     chunktypecounts = {}
     chunktypesizes = {}
@@ -2147,7 +2151,9 @@  def debugrevlog(ui, repo, file_=None, **
                 numemptytext += 1
             else:
                 numfull += 1
+                numsnapdepth[0] += 1
                 addsize(size, fullsize)
+                addsize(size, snapsizedepth[0])
         else:
             chainlengths.append(chainlengths[delta] + 1)
             baseaddr = chainbases[delta]
@@ -2160,6 +2166,9 @@  def debugrevlog(ui, repo, file_=None, **
             elif r.issnapshot(rev):
                 addsize(size, semisize)
                 numsemi += 1
+                depth = r.snapshotdepth(rev)
+                numsnapdepth[depth] += 1
+                addsize(size, snapsizedepth[depth])
             else:
                 addsize(size, deltasize)
                 if delta == rev - 1:
@@ -2204,8 +2213,13 @@  def debugrevlog(ui, repo, file_=None, **
     fulltotal = fullsize[2]
     fullsize[2] /= numfull
     semitotal = semisize[2]
+    snaptotal = {}
     if 0 < numsemi:
         semisize[2] /= numsemi
+    for depth in snapsizedepth:
+        snaptotal[depth] = snapsizedepth[depth][2]
+        snapsizedepth[depth][2] /= numsnapdepth[depth]
+
     deltatotal = deltasize[2]
     if numdeltas > 0:
         deltasize[2] /= numdeltas
@@ -2246,12 +2260,17 @@  def debugrevlog(ui, repo, file_=None, **
              + fmt % pcfmt(numemptytext, numemptytext + numemptydelta))
     ui.write(('                   delta : ')
              + fmt % pcfmt(numemptydelta, numemptytext + numemptydelta))
-    ui.write(('    full      : ') + fmt % pcfmt(numfull, numrevs))
-    ui.write(('    inter     : ') + fmt % pcfmt(numsemi, numrevs))
+    ui.write(('    snapshot  : ') + fmt % pcfmt(numfull + numsemi, numrevs))
+    for depth in sorted(numsnapdepth):
+        ui.write(('      lvl-%-3d :       ' % depth)
+                 + fmt % pcfmt(numsnapdepth[depth], numrevs))
     ui.write(('    deltas    : ') + fmt % pcfmt(numdeltas, numrevs))
     ui.write(('revision size : ') + fmt2 % totalsize)
-    ui.write(('    full      : ') + fmt % pcfmt(fulltotal, totalsize))
-    ui.write(('    inter     : ') + fmt % pcfmt(semitotal, totalsize))
+    ui.write(('    snapshot  : ')
+             + fmt % pcfmt(fulltotal + semitotal, totalsize))
+    for depth in sorted(numsnapdepth):
+        ui.write(('      lvl-%-3d :       ' % depth)
+                 + fmt % pcfmt(snaptotal[depth], totalsize))
     ui.write(('    deltas    : ') + fmt % pcfmt(deltatotal, totalsize))
 
     def fmtchunktype(chunktype):
@@ -2285,6 +2304,13 @@  def debugrevlog(ui, repo, file_=None, **
                  % tuple(datasize))
     ui.write(('full revision size (min/max/avg)     : %d / %d / %d\n')
              % tuple(fullsize))
+    ui.write(('inter-snapshot size (min/max/avg)    : %d / %d / %d\n')
+             % tuple(semisize))
+    for depth in sorted(snapsizedepth):
+        if depth == 0:
+            continue
+        ui.write(('    level-%-3d (min/max/avg)          : %d / %d / %d\n')
+                 % ((depth,) + tuple(snapsizedepth[depth])))
     ui.write(('delta size (min/max/avg)             : %d / %d / %d\n')
              % tuple(deltasize))
 
diff --git a/tests/test-debugcommands.t b/tests/test-debugcommands.t
--- a/tests/test-debugcommands.t
+++ b/tests/test-debugcommands.t
@@ -26,12 +26,12 @@ 
       empty     :   0 ( 0.00%)
                      text  :   0 (100.00%)
                      delta :   0 (100.00%)
-      full      :   3 (100.00%)
-      inter     :   0 ( 0.00%)
+      snapshot  :   3 (100.00%)
+        lvl-0   :         3 (100.00%)
       deltas    :   0 ( 0.00%)
   revision size : 191
-      full      : 191 (100.00%)
-      inter     :   0 ( 0.00%)
+      snapshot  : 191 (100.00%)
+        lvl-0   :       191 (100.00%)
       deltas    :   0 ( 0.00%)
   
   chunks        :   3
@@ -46,6 +46,7 @@ 
   
   uncompressed data size (min/max/avg) : 57 / 66 / 62
   full revision size (min/max/avg)     : 58 / 67 / 63
+  inter-snapshot size (min/max/avg)    : 0 / 0 / 0
   delta size (min/max/avg)             : 0 / 0 / 0
   $ hg debugrevlog -m
   format : 1
@@ -58,12 +59,12 @@ 
       empty     :  1 (33.33%)
                      text  :  1 (100.00%)
                      delta :  0 ( 0.00%)
-      full      :  2 (66.67%)
-      inter     :  0 ( 0.00%)
+      snapshot  :  2 (66.67%)
+        lvl-0   :        2 (66.67%)
       deltas    :  0 ( 0.00%)
   revision size : 88
-      full      : 88 (100.00%)
-      inter     :  0 ( 0.00%)
+      snapshot  : 88 (100.00%)
+        lvl-0   :       88 (100.00%)
       deltas    :  0 ( 0.00%)
   
   chunks        :  3
@@ -80,6 +81,7 @@ 
   
   uncompressed data size (min/max/avg) : 0 / 43 / 28
   full revision size (min/max/avg)     : 44 / 44 / 44
+  inter-snapshot size (min/max/avg)    : 0 / 0 / 0
   delta size (min/max/avg)             : 0 / 0 / 0
   $ hg debugrevlog a
   format : 1
@@ -92,12 +94,12 @@ 
       empty     : 0 ( 0.00%)
                      text  : 0 (100.00%)
                      delta : 0 (100.00%)
-      full      : 1 (100.00%)
-      inter     : 0 ( 0.00%)
+      snapshot  : 1 (100.00%)
+        lvl-0   :       1 (100.00%)
       deltas    : 0 ( 0.00%)
   revision size : 3
-      full      : 3 (100.00%)
-      inter     : 0 ( 0.00%)
+      snapshot  : 3 (100.00%)
+        lvl-0   :       3 (100.00%)
       deltas    : 0 ( 0.00%)
   
   chunks        : 1
@@ -112,6 +114,7 @@ 
   
   uncompressed data size (min/max/avg) : 2 / 2 / 2
   full revision size (min/max/avg)     : 3 / 3 / 3
+  inter-snapshot size (min/max/avg)    : 0 / 0 / 0
   delta size (min/max/avg)             : 0 / 0 / 0
 #endif