perf: add a `--timing` argument to `perfhelper-tracecopies`
authorBoris Feld <boris.feld@octobus.net>
Fri, 23 Nov 2018 19:32:51 +0100
changeset 40731 36077a0f6f12
parent 40730 55b053af7196
child 40732 001f27970b60
perf: add a `--timing` argument to `perfhelper-tracecopies` The new argument will help picking better pair for benchmarking. See documentation for details.
contrib/perf.py
--- a/contrib/perf.py	Sun Nov 11 18:08:33 2018 +0900
+++ b/contrib/perf.py	Fri Nov 23 19:32:51 2018 +0100
@@ -1164,19 +1164,39 @@
 @command(b'perfhelper-tracecopies', formatteropts +
          [
           (b'r', b'revs', [], b'restrict search to these revisions'),
+          (b'', b'timing', False, b'provides extra data (costly)'),
          ])
 def perfhelpertracecopies(ui, repo, revs=[], **opts):
     """find statistic about potential parameters for the `perftracecopies`
 
     This command find source-destination pair relevant for copytracing testing.
     It report value for some of the parameters that impact copy tracing time.
+
+    If `--timing` is set, rename detection is run and the associated timing
+    will be reported. The extra details comes at the cost of a slower command
+    execution.
+
+    Since the rename detection is only run once, other factors might easily
+    affect the precision of the timing. However it should give a good
+    approximation of which revision pairs are very costly.
     """
     opts = _byteskwargs(opts)
     fm = ui.formatter(b'perf', opts)
-    header = '%12s %12s %12s %12s\n'
-    output = ("%(source)12s %(destination)12s "
-              "%(nbrevs)12d %(nbmissingfiles)12d\n")
-    fm.plain(header % ("source", "destination", "nb-revs", "nb-files"))
+    dotiming = opts[b'timing']
+
+    if dotiming:
+        header = '%12s %12s %12s %12s %12s %12s\n'
+        output = ("%(source)12s %(destination)12s "
+                  "%(nbrevs)12d %(nbmissingfiles)12d "
+                  "%(nbrenamedfiles)12d %(time)18.5f\n")
+        header_names = ("source", "destination", "nb-revs", "nb-files",
+                        "nb-renames", "time")
+        fm.plain(header % header_names)
+    else:
+        header = '%12s %12s %12s %12s\n'
+        output = ("%(source)12s %(destination)12s "
+                  "%(nbrevs)12d %(nbmissingfiles)12d\n")
+        fm.plain(header % ("source", "destination", "nb-revs", "nb-files"))
 
     if not revs:
         revs = ['all()']
@@ -1195,18 +1215,26 @@
                 missing = copies._computeforwardmissing(base, parent)
                 if not missing:
                     continue
-                fm.startitem()
                 data = {
                     b'source': base.hex(),
                     b'destination': parent.hex(),
                     b'nbrevs': len(repo.revs('%d::%d', b, p)),
                     b'nbmissingfiles': len(missing),
                 }
+                if dotiming:
+                    begin = util.timer()
+                    renames = copies.pathcopies(base, parent)
+                    end = util.timer()
+                    # not very stable timing since we did only one run
+                    data['time'] = end - begin
+                    data['nbrenamedfiles'] = len(renames)
+                fm.startitem()
                 fm.data(**data)
                 out = data.copy()
                 out['source'] = fm.hexfunc(base.node())
                 out['destination'] = fm.hexfunc(parent.node())
                 fm.plain(output % out)
+
     fm.end()
 
 @command(b'perfcca', formatteropts)