Mercurial > hg
comparison contrib/perf.py @ 50678:459681233b1f
perf: add a perf::stream-consume
We know how long it take to generate, lets check how long it take to apply now.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 06 Jun 2023 04:56:54 +0200 |
parents | b8de54ac5a21 |
children | 0bba730005df |
comparison
equal
deleted
inserted
replaced
50677:b8de54ac5a21 | 50678:459681233b1f |
---|---|
2022 | 2022 |
2023 timer(runone, title=b"generate") | 2023 timer(runone, title=b"generate") |
2024 fm.end() | 2024 fm.end() |
2025 | 2025 |
2026 | 2026 |
2027 @command( | |
2028 b'perf::stream-consume', | |
2029 formatteropts, | |
2030 ) | |
2031 def perf_stream_clone_consume(ui, repo, filename, **opts): | |
2032 """benchmark the full application of a stream clone | |
2033 | |
2034 This include the creation of the repository | |
2035 """ | |
2036 # try except to appease check code | |
2037 msg = b"mercurial too old, missing necessary module: %s" | |
2038 try: | |
2039 from mercurial import bundle2 | |
2040 except ImportError as exc: | |
2041 msg %= _bytestr(exc) | |
2042 raise error.Abort(msg) | |
2043 try: | |
2044 from mercurial import exchange | |
2045 except ImportError as exc: | |
2046 msg %= _bytestr(exc) | |
2047 raise error.Abort(msg) | |
2048 try: | |
2049 from mercurial import hg | |
2050 except ImportError as exc: | |
2051 msg %= _bytestr(exc) | |
2052 raise error.Abort(msg) | |
2053 try: | |
2054 from mercurial import localrepo | |
2055 except ImportError as exc: | |
2056 msg %= _bytestr(exc) | |
2057 raise error.Abort(msg) | |
2058 | |
2059 opts = _byteskwargs(opts) | |
2060 timer, fm = gettimer(ui, opts) | |
2061 | |
2062 # deletion of the generator may trigger some cleanup that we do not want to | |
2063 # measure | |
2064 if not (os.path.isfile(filename) and os.access(filename, os.R_OK)): | |
2065 raise error.Abort("not a readable file: %s" % filename) | |
2066 | |
2067 run_variables = [None, None] | |
2068 | |
2069 @contextlib.contextmanager | |
2070 def context(): | |
2071 with open(filename, mode='rb') as bundle: | |
2072 with tempfile.TemporaryDirectory() as tmp_dir: | |
2073 tmp_dir = fsencode(tmp_dir) | |
2074 run_variables[0] = bundle | |
2075 run_variables[1] = tmp_dir | |
2076 yield | |
2077 run_variables[0] = None | |
2078 run_variables[1] = None | |
2079 | |
2080 def runone(): | |
2081 bundle = run_variables[0] | |
2082 tmp_dir = run_variables[1] | |
2083 # only pass ui when no srcrepo | |
2084 localrepo.createrepository( | |
2085 repo.ui, tmp_dir, requirements=repo.requirements | |
2086 ) | |
2087 target = hg.repository(repo.ui, tmp_dir) | |
2088 gen = exchange.readbundle(target.ui, bundle, bundle.name) | |
2089 # stream v1 | |
2090 if util.safehasattr(gen, 'apply'): | |
2091 gen.apply(target) | |
2092 else: | |
2093 with target.transaction(b"perf::stream-consume") as tr: | |
2094 bundle2.applybundle( | |
2095 target, | |
2096 gen, | |
2097 tr, | |
2098 source=b'unbundle', | |
2099 url=filename, | |
2100 ) | |
2101 | |
2102 timer(runone, context=context, title=b"consume") | |
2103 fm.end() | |
2104 | |
2105 | |
2027 @command(b'perf::parents|perfparents', formatteropts) | 2106 @command(b'perf::parents|perfparents', formatteropts) |
2028 def perfparents(ui, repo, **opts): | 2107 def perfparents(ui, repo, **opts): |
2029 """benchmark the time necessary to fetch one changeset's parents. | 2108 """benchmark the time necessary to fetch one changeset's parents. |
2030 | 2109 |
2031 The fetch is done using the `node identifier`, traversing all object layers | 2110 The fetch is done using the `node identifier`, traversing all object layers |