perf: add perfprogress command
authorGregory Szorc <gregory.szorc@gmail.com>
Mon, 10 Dec 2018 20:01:07 +0000
changeset 53697 008f3491dc53
parent 53696 08cfa77d7288
child 53699 4e17679c336b
push id1081
push usergszorc@mozilla.com
push dateMon, 10 Dec 2018 21:46:46 +0000
perf: add perfprogress command I've noticed that progress bars can add significant overhead to tight loops. Let's add a perf command that attempts to isolate that overhead. With a default hgrc, iteration over 1M items appears to take ~3.75s on my machine. Profiling reveals ~28% of time is spent in ui.configbool() resolving the value of the progress.debug config option. Even if I set progress.disable=true, execution still takes ~2.60s, with ~59% of the time spent in ui.configbool(). Differential Revision: https://phab.mercurial-scm.org/D5407
contrib/perf.py
tests/test-contrib-perf.t
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -2607,8 +2607,26 @@ def uisetup(ui):
         # openrevlog() should cause failure, because it has been
         # available since 3.5 (or 49c583ca48c4).
         def openrevlog(orig, repo, cmd, file_, opts):
             if opts.get(b'dir') and not util.safehasattr(repo, b'dirlog'):
                 raise error.Abort(b"This version doesn't support --dir option",
                                   hint=b"use 3.5 or later")
             return orig(repo, cmd, file_, opts)
         extensions.wrapfunction(cmdutil, b'openrevlog', openrevlog)
+
+@command(b'perfprogress', formatteropts + [
+    (b'', b'topic', b'topic', b'topic for progress messages'),
+    (b'c', b'total', 1000000, b'total value we are progressing to'),
+], norepo=True)
+def perfprogress(ui, topic=None, total=None, **opts):
+    """printing of progress bars"""
+    opts = _byteskwargs(opts)
+
+    timer, fm = gettimer(ui, opts)
+
+    def doprogress():
+        with ui.makeprogress(topic, total=total) as progress:
+            for i in pycompat.xrange(total):
+                progress.increment()
+
+    timer(doprogress)
+    fm.end()
--- a/tests/test-contrib-perf.t
+++ b/tests/test-contrib-perf.t
@@ -107,16 +107,17 @@ perfstatus
    perfnodelookup
                  (no help text available)
    perfparents   (no help text available)
    perfpathcopies
                  benchmark the copy tracing logic
    perfphases    benchmark phasesets computation
    perfphasesremote
                  benchmark time needed to analyse phases of the remote server
+   perfprogress  printing of progress bars
    perfrawfiles  (no help text available)
    perfrevlogchunks
                  Benchmark operations on revlog chunks.
    perfrevlogindex
                  Benchmark operations against a revlog index.
    perfrevlogrevision
                  Benchmark obtaining a revlog revision.
    perfrevlogrevisions
@@ -183,16 +184,17 @@ perfstatus
   $ hg perfmanifest -m 44fe2c8352bb3a478ffd7d8350bbc721920134d1
   $ hg perfmanifest -m 44fe2c8352bb
   abort: manifest revision must be integer or full node
   [255]
   $ hg perfmergecalculate -r 3
   $ hg perfmoonwalk
   $ hg perfnodelookup 2
   $ hg perfpathcopies 1 2
+  $ hg perfprogress --total 1000
   $ hg perfrawfiles 2
   $ hg perfrevlogindex -c
 #if reporevlogstore
   $ hg perfrevlogrevisions .hg/store/data/a.i
 #endif
   $ hg perfrevlogrevision -m 0
   $ hg perfrevlogchunks -c
   $ hg perfrevrange