##// END OF EJS Templates
contrib: byteify perf.py file...
Pulkit Goyal -
r39398:438f3932 default
parent child Browse files
Show More
This diff has been collapsed as it changes many lines, (671 lines changed) Show them Hide them
@@ -103,7 +103,7 b" setattr(util, 'safehasattr', safehasattr"
103 # since ae5d60bb70c9
103 # since ae5d60bb70c9
104 if safehasattr(time, 'perf_counter'):
104 if safehasattr(time, 'perf_counter'):
105 util.timer = time.perf_counter
105 util.timer = time.perf_counter
106 elif os.name == 'nt':
106 elif os.name == b'nt':
107 util.timer = time.clock
107 util.timer = time.clock
108 else:
108 else:
109 util.timer = time.time
109 util.timer = time.time
@@ -123,9 +123,9 b' formatteropts = getattr(cmdutil, "format'
123 # since 1.9 (or a79fea6b3e77).
123 # since 1.9 (or a79fea6b3e77).
124 revlogopts = getattr(cmdutil, "debugrevlogopts",
124 revlogopts = getattr(cmdutil, "debugrevlogopts",
125 getattr(commands, "debugrevlogopts", [
125 getattr(commands, "debugrevlogopts", [
126 ('c', 'changelog', False, ('open changelog')),
126 (b'c', b'changelog', False, (b'open changelog')),
127 ('m', 'manifest', False, ('open manifest')),
127 (b'm', b'manifest', False, (b'open manifest')),
128 ('', 'dir', False, ('open directory manifest')),
128 (b'', b'dir', False, (b'open directory manifest')),
129 ]))
129 ]))
130
130
131 cmdtable = {}
131 cmdtable = {}
@@ -134,20 +134,20 b' cmdtable = {}'
134 # define parsealiases locally, because cmdutil.parsealiases has been
134 # define parsealiases locally, because cmdutil.parsealiases has been
135 # available since 1.5 (or 6252852b4332)
135 # available since 1.5 (or 6252852b4332)
136 def parsealiases(cmd):
136 def parsealiases(cmd):
137 return cmd.lstrip("^").split("|")
137 return cmd.lstrip(b"^").split(b"|")
138
138
139 if safehasattr(registrar, 'command'):
139 if safehasattr(registrar, 'command'):
140 command = registrar.command(cmdtable)
140 command = registrar.command(cmdtable)
141 elif safehasattr(cmdutil, 'command'):
141 elif safehasattr(cmdutil, 'command'):
142 command = cmdutil.command(cmdtable)
142 command = cmdutil.command(cmdtable)
143 if 'norepo' not in getargspec(command).args:
143 if b'norepo' not in getargspec(command).args:
144 # for "historical portability":
144 # for "historical portability":
145 # wrap original cmdutil.command, because "norepo" option has
145 # wrap original cmdutil.command, because "norepo" option has
146 # been available since 3.1 (or 75a96326cecb)
146 # been available since 3.1 (or 75a96326cecb)
147 _command = command
147 _command = command
148 def command(name, options=(), synopsis=None, norepo=False):
148 def command(name, options=(), synopsis=None, norepo=False):
149 if norepo:
149 if norepo:
150 commands.norepo += ' %s' % ' '.join(parsealiases(name))
150 commands.norepo += b' %s' % b' '.join(parsealiases(name))
151 return _command(name, list(options), synopsis)
151 return _command(name, list(options), synopsis)
152 else:
152 else:
153 # for "historical portability":
153 # for "historical portability":
@@ -160,7 +160,7 b' else:'
160 else:
160 else:
161 cmdtable[name] = func, list(options)
161 cmdtable[name] = func, list(options)
162 if norepo:
162 if norepo:
163 commands.norepo += ' %s' % ' '.join(parsealiases(name))
163 commands.norepo += b' %s' % b' '.join(parsealiases(name))
164 return func
164 return func
165 return decorator
165 return decorator
166
166
@@ -169,23 +169,23 b' try:'
169 import mercurial.configitems
169 import mercurial.configitems
170 configtable = {}
170 configtable = {}
171 configitem = mercurial.registrar.configitem(configtable)
171 configitem = mercurial.registrar.configitem(configtable)
172 configitem('perf', 'presleep',
172 configitem(b'perf', b'presleep',
173 default=mercurial.configitems.dynamicdefault,
173 default=mercurial.configitems.dynamicdefault,
174 )
174 )
175 configitem('perf', 'stub',
175 configitem(b'perf', b'stub',
176 default=mercurial.configitems.dynamicdefault,
176 default=mercurial.configitems.dynamicdefault,
177 )
177 )
178 configitem('perf', 'parentscount',
178 configitem(b'perf', b'parentscount',
179 default=mercurial.configitems.dynamicdefault,
179 default=mercurial.configitems.dynamicdefault,
180 )
180 )
181 configitem('perf', 'all-timing',
181 configitem(b'perf', b'all-timing',
182 default=mercurial.configitems.dynamicdefault,
182 default=mercurial.configitems.dynamicdefault,
183 )
183 )
184 except (ImportError, AttributeError):
184 except (ImportError, AttributeError):
185 pass
185 pass
186
186
187 def getlen(ui):
187 def getlen(ui):
188 if ui.configbool("perf", "stub", False):
188 if ui.configbool(b"perf", b"stub", False):
189 return lambda x: 1
189 return lambda x: 1
190 return len
190 return len
191
191
@@ -197,14 +197,14 b' def gettimer(ui, opts=None):'
197
197
198 # enforce an idle period before execution to counteract power management
198 # enforce an idle period before execution to counteract power management
199 # experimental config: perf.presleep
199 # experimental config: perf.presleep
200 time.sleep(getint(ui, "perf", "presleep", 1))
200 time.sleep(getint(ui, b"perf", b"presleep", 1))
201
201
202 if opts is None:
202 if opts is None:
203 opts = {}
203 opts = {}
204 # redirect all to stderr unless buffer api is in use
204 # redirect all to stderr unless buffer api is in use
205 if not ui._buffers:
205 if not ui._buffers:
206 ui = ui.copy()
206 ui = ui.copy()
207 uifout = safeattrsetter(ui, 'fout', ignoremissing=True)
207 uifout = safeattrsetter(ui, b'fout', ignoremissing=True)
208 if uifout:
208 if uifout:
209 # for "historical portability":
209 # for "historical portability":
210 # ui.fout/ferr have been available since 1.9 (or 4e1ccd4c2b6d)
210 # ui.fout/ferr have been available since 1.9 (or 4e1ccd4c2b6d)
@@ -213,7 +213,7 b' def gettimer(ui, opts=None):'
213 # get a formatter
213 # get a formatter
214 uiformatter = getattr(ui, 'formatter', None)
214 uiformatter = getattr(ui, 'formatter', None)
215 if uiformatter:
215 if uiformatter:
216 fm = uiformatter('perf', opts)
216 fm = uiformatter(b'perf', opts)
217 else:
217 else:
218 # for "historical portability":
218 # for "historical portability":
219 # define formatter locally, because ui.formatter has been
219 # define formatter locally, because ui.formatter has been
@@ -244,15 +244,15 b' def gettimer(ui, opts=None):'
244 self._ui.write(text, **opts)
244 self._ui.write(text, **opts)
245 def end(self):
245 def end(self):
246 pass
246 pass
247 fm = defaultformatter(ui, 'perf', opts)
247 fm = defaultformatter(ui, b'perf', opts)
248
248
249 # stub function, runs code only once instead of in a loop
249 # stub function, runs code only once instead of in a loop
250 # experimental config: perf.stub
250 # experimental config: perf.stub
251 if ui.configbool("perf", "stub", False):
251 if ui.configbool(b"perf", b"stub", False):
252 return functools.partial(stub_timer, fm), fm
252 return functools.partial(stub_timer, fm), fm
253
253
254 # experimental config: perf.all-timing
254 # experimental config: perf.all-timing
255 displayall = ui.configbool("perf", "all-timing", False)
255 displayall = ui.configbool(b"perf", b"all-timing", False)
256 return functools.partial(_timer, fm, displayall=displayall), fm
256 return functools.partial(_timer, fm, displayall=displayall), fm
257
257
258 def stub_timer(fm, func, title=None):
258 def stub_timer(fm, func, title=None):
@@ -280,30 +280,30 b' def _timer(fm, func, title=None, display'
280 fm.startitem()
280 fm.startitem()
281
281
282 if title:
282 if title:
283 fm.write('title', '! %s\n', title)
283 fm.write(b'title', b'! %s\n', title)
284 if r:
284 if r:
285 fm.write('result', '! result: %s\n', r)
285 fm.write(b'result', b'! result: %s\n', r)
286 def display(role, entry):
286 def display(role, entry):
287 prefix = ''
287 prefix = b''
288 if role != 'best':
288 if role != b'best':
289 prefix = '%s.' % role
289 prefix = b'%s.' % role
290 fm.plain('!')
290 fm.plain(b'!')
291 fm.write(prefix + 'wall', ' wall %f', entry[0])
291 fm.write(prefix + b'wall', b' wall %f', entry[0])
292 fm.write(prefix + 'comb', ' comb %f', entry[1] + entry[2])
292 fm.write(prefix + b'comb', b' comb %f', entry[1] + entry[2])
293 fm.write(prefix + 'user', ' user %f', entry[1])
293 fm.write(prefix + b'user', b' user %f', entry[1])
294 fm.write(prefix + 'sys', ' sys %f', entry[2])
294 fm.write(prefix + b'sys', b' sys %f', entry[2])
295 fm.write(prefix + 'count', ' (%s of %d)', role, count)
295 fm.write(prefix + b'count', b' (%s of %d)', role, count)
296 fm.plain('\n')
296 fm.plain(b'\n')
297 results.sort()
297 results.sort()
298 min_val = results[0]
298 min_val = results[0]
299 display('best', min_val)
299 display(b'best', min_val)
300 if displayall:
300 if displayall:
301 max_val = results[-1]
301 max_val = results[-1]
302 display('max', max_val)
302 display(b'max', max_val)
303 avg = tuple([sum(x) / count for x in zip(*results)])
303 avg = tuple([sum(x) / count for x in zip(*results)])
304 display('avg', avg)
304 display(b'avg', avg)
305 median = results[len(results) // 2]
305 median = results[len(results) // 2]
306 display('median', median)
306 display(b'median', median)
307
307
308 # utilities for historical portability
308 # utilities for historical portability
309
309
@@ -316,7 +316,7 b' def getint(ui, section, name, default):'
316 try:
316 try:
317 return int(v)
317 return int(v)
318 except ValueError:
318 except ValueError:
319 raise error.ConfigError(("%s.%s is not an integer ('%s')")
319 raise error.ConfigError((b"%s.%s is not an integer ('%s')")
320 % (section, name, v))
320 % (section, name, v))
321
321
322 def safeattrsetter(obj, name, ignoremissing=False):
322 def safeattrsetter(obj, name, ignoremissing=False):
@@ -337,8 +337,8 b' def safeattrsetter(obj, name, ignoremiss'
337 if not util.safehasattr(obj, name):
337 if not util.safehasattr(obj, name):
338 if ignoremissing:
338 if ignoremissing:
339 return None
339 return None
340 raise error.Abort(("missing attribute %s of %s might break assumption"
340 raise error.Abort((b"missing attribute %s of %s might break assumption"
341 " of performance measurement") % (name, obj))
341 b" of performance measurement") % (name, obj))
342
342
343 origvalue = getattr(obj, name)
343 origvalue = getattr(obj, name)
344 class attrutil(object):
344 class attrutil(object):
@@ -364,8 +364,8 b' def getbranchmapsubsettable():'
364 # bisecting in bcee63733aad::59a9f18d4587 can reach here (both
364 # bisecting in bcee63733aad::59a9f18d4587 can reach here (both
365 # branchmap and repoview modules exist, but subsettable attribute
365 # branchmap and repoview modules exist, but subsettable attribute
366 # doesn't)
366 # doesn't)
367 raise error.Abort(("perfbranchmap not available with this Mercurial"),
367 raise error.Abort((b"perfbranchmap not available with this Mercurial"),
368 hint="use 2.5 or later")
368 hint=b"use 2.5 or later")
369
369
370 def getsvfs(repo):
370 def getsvfs(repo):
371 """Return appropriate object to access files under .hg/store
371 """Return appropriate object to access files under .hg/store
@@ -392,22 +392,22 b' def getvfs(repo):'
392 def repocleartagscachefunc(repo):
392 def repocleartagscachefunc(repo):
393 """Return the function to clear tags cache according to repo internal API
393 """Return the function to clear tags cache according to repo internal API
394 """
394 """
395 if util.safehasattr(repo, '_tagscache'): # since 2.0 (or 9dca7653b525)
395 if util.safehasattr(repo, b'_tagscache'): # since 2.0 (or 9dca7653b525)
396 # in this case, setattr(repo, '_tagscache', None) or so isn't
396 # in this case, setattr(repo, '_tagscache', None) or so isn't
397 # correct way to clear tags cache, because existing code paths
397 # correct way to clear tags cache, because existing code paths
398 # expect _tagscache to be a structured object.
398 # expect _tagscache to be a structured object.
399 def clearcache():
399 def clearcache():
400 # _tagscache has been filteredpropertycache since 2.5 (or
400 # _tagscache has been filteredpropertycache since 2.5 (or
401 # 98c867ac1330), and delattr() can't work in such case
401 # 98c867ac1330), and delattr() can't work in such case
402 if '_tagscache' in vars(repo):
402 if b'_tagscache' in vars(repo):
403 del repo.__dict__['_tagscache']
403 del repo.__dict__[b'_tagscache']
404 return clearcache
404 return clearcache
405
405
406 repotags = safeattrsetter(repo, '_tags', ignoremissing=True)
406 repotags = safeattrsetter(repo, b'_tags', ignoremissing=True)
407 if repotags: # since 1.4 (or 5614a628d173)
407 if repotags: # since 1.4 (or 5614a628d173)
408 return lambda : repotags.set(None)
408 return lambda : repotags.set(None)
409
409
410 repotagscache = safeattrsetter(repo, 'tagscache', ignoremissing=True)
410 repotagscache = safeattrsetter(repo, b'tagscache', ignoremissing=True)
411 if repotagscache: # since 0.6 (or d7df759d0e97)
411 if repotagscache: # since 0.6 (or d7df759d0e97)
412 return lambda : repotagscache.set(None)
412 return lambda : repotagscache.set(None)
413
413
@@ -416,7 +416,7 b' def repocleartagscachefunc(repo):'
416 # - repo.tags of such Mercurial isn't "callable", and repo.tags()
416 # - repo.tags of such Mercurial isn't "callable", and repo.tags()
417 # in perftags() causes failure soon
417 # in perftags() causes failure soon
418 # - perf.py itself has been available since 1.1 (or eb240755386d)
418 # - perf.py itself has been available since 1.1 (or eb240755386d)
419 raise error.Abort(("tags API of this hg command is unknown"))
419 raise error.Abort((b"tags API of this hg command is unknown"))
420
420
421 # utilities to clear cache
421 # utilities to clear cache
422
422
@@ -428,7 +428,7 b' def clearfilecache(repo, attrname):'
428
428
429 # perf commands
429 # perf commands
430
430
431 @command('perfwalk', formatteropts)
431 @command(b'perfwalk', formatteropts)
432 def perfwalk(ui, repo, *pats, **opts):
432 def perfwalk(ui, repo, *pats, **opts):
433 timer, fm = gettimer(ui, opts)
433 timer, fm = gettimer(ui, opts)
434 m = scmutil.match(repo[None], pats, {})
434 m = scmutil.match(repo[None], pats, {})
@@ -436,47 +436,47 b' def perfwalk(ui, repo, *pats, **opts):'
436 ignored=False))))
436 ignored=False))))
437 fm.end()
437 fm.end()
438
438
439 @command('perfannotate', formatteropts)
439 @command(b'perfannotate', formatteropts)
440 def perfannotate(ui, repo, f, **opts):
440 def perfannotate(ui, repo, f, **opts):
441 timer, fm = gettimer(ui, opts)
441 timer, fm = gettimer(ui, opts)
442 fc = repo['.'][f]
442 fc = repo[b'.'][f]
443 timer(lambda: len(fc.annotate(True)))
443 timer(lambda: len(fc.annotate(True)))
444 fm.end()
444 fm.end()
445
445
446 @command('perfstatus',
446 @command(b'perfstatus',
447 [('u', 'unknown', False,
447 [(b'u', b'unknown', False,
448 'ask status to look for unknown files')] + formatteropts)
448 b'ask status to look for unknown files')] + formatteropts)
449 def perfstatus(ui, repo, **opts):
449 def perfstatus(ui, repo, **opts):
450 #m = match.always(repo.root, repo.getcwd())
450 #m = match.always(repo.root, repo.getcwd())
451 #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False,
451 #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False,
452 # False))))
452 # False))))
453 timer, fm = gettimer(ui, opts)
453 timer, fm = gettimer(ui, opts)
454 timer(lambda: sum(map(len, repo.status(unknown=opts['unknown']))))
454 timer(lambda: sum(map(len, repo.status(unknown=opts[b'unknown']))))
455 fm.end()
455 fm.end()
456
456
457 @command('perfaddremove', formatteropts)
457 @command(b'perfaddremove', formatteropts)
458 def perfaddremove(ui, repo, **opts):
458 def perfaddremove(ui, repo, **opts):
459 timer, fm = gettimer(ui, opts)
459 timer, fm = gettimer(ui, opts)
460 try:
460 try:
461 oldquiet = repo.ui.quiet
461 oldquiet = repo.ui.quiet
462 repo.ui.quiet = True
462 repo.ui.quiet = True
463 matcher = scmutil.match(repo[None])
463 matcher = scmutil.match(repo[None])
464 opts['dry_run'] = True
464 opts[b'dry_run'] = True
465 timer(lambda: scmutil.addremove(repo, matcher, "", opts))
465 timer(lambda: scmutil.addremove(repo, matcher, b"", opts))
466 finally:
466 finally:
467 repo.ui.quiet = oldquiet
467 repo.ui.quiet = oldquiet
468 fm.end()
468 fm.end()
469
469
470 def clearcaches(cl):
470 def clearcaches(cl):
471 # behave somewhat consistently across internal API changes
471 # behave somewhat consistently across internal API changes
472 if util.safehasattr(cl, 'clearcaches'):
472 if util.safehasattr(cl, b'clearcaches'):
473 cl.clearcaches()
473 cl.clearcaches()
474 elif util.safehasattr(cl, '_nodecache'):
474 elif util.safehasattr(cl, b'_nodecache'):
475 from mercurial.node import nullid, nullrev
475 from mercurial.node import nullid, nullrev
476 cl._nodecache = {nullid: nullrev}
476 cl._nodecache = {nullid: nullrev}
477 cl._nodepos = None
477 cl._nodepos = None
478
478
479 @command('perfheads', formatteropts)
479 @command(b'perfheads', formatteropts)
480 def perfheads(ui, repo, **opts):
480 def perfheads(ui, repo, **opts):
481 timer, fm = gettimer(ui, opts)
481 timer, fm = gettimer(ui, opts)
482 cl = repo.changelog
482 cl = repo.changelog
@@ -486,7 +486,7 b' def perfheads(ui, repo, **opts):'
486 timer(d)
486 timer(d)
487 fm.end()
487 fm.end()
488
488
489 @command('perftags', formatteropts)
489 @command(b'perftags', formatteropts)
490 def perftags(ui, repo, **opts):
490 def perftags(ui, repo, **opts):
491 import mercurial.changelog
491 import mercurial.changelog
492 import mercurial.manifest
492 import mercurial.manifest
@@ -501,7 +501,7 b' def perftags(ui, repo, **opts):'
501 timer(t)
501 timer(t)
502 fm.end()
502 fm.end()
503
503
504 @command('perfancestors', formatteropts)
504 @command(b'perfancestors', formatteropts)
505 def perfancestors(ui, repo, **opts):
505 def perfancestors(ui, repo, **opts):
506 timer, fm = gettimer(ui, opts)
506 timer, fm = gettimer(ui, opts)
507 heads = repo.changelog.headrevs()
507 heads = repo.changelog.headrevs()
@@ -511,7 +511,7 b' def perfancestors(ui, repo, **opts):'
511 timer(d)
511 timer(d)
512 fm.end()
512 fm.end()
513
513
514 @command('perfancestorset', formatteropts)
514 @command(b'perfancestorset', formatteropts)
515 def perfancestorset(ui, repo, revset, **opts):
515 def perfancestorset(ui, repo, revset, **opts):
516 timer, fm = gettimer(ui, opts)
516 timer, fm = gettimer(ui, opts)
517 revs = repo.revs(revset)
517 revs = repo.revs(revset)
@@ -523,17 +523,17 b' def perfancestorset(ui, repo, revset, **'
523 timer(d)
523 timer(d)
524 fm.end()
524 fm.end()
525
525
526 @command('perfbookmarks', formatteropts)
526 @command(b'perfbookmarks', formatteropts)
527 def perfbookmarks(ui, repo, **opts):
527 def perfbookmarks(ui, repo, **opts):
528 """benchmark parsing bookmarks from disk to memory"""
528 """benchmark parsing bookmarks from disk to memory"""
529 timer, fm = gettimer(ui, opts)
529 timer, fm = gettimer(ui, opts)
530 def d():
530 def d():
531 clearfilecache(repo, '_bookmarks')
531 clearfilecache(repo, b'_bookmarks')
532 repo._bookmarks
532 repo._bookmarks
533 timer(d)
533 timer(d)
534 fm.end()
534 fm.end()
535
535
536 @command('perfbundleread', formatteropts, 'BUNDLE')
536 @command(b'perfbundleread', formatteropts, b'BUNDLE')
537 def perfbundleread(ui, repo, bundlepath, **opts):
537 def perfbundleread(ui, repo, bundlepath, **opts):
538 """Benchmark reading of bundle files.
538 """Benchmark reading of bundle files.
539
539
@@ -548,7 +548,7 b' def perfbundleread(ui, repo, bundlepath,'
548
548
549 def makebench(fn):
549 def makebench(fn):
550 def run():
550 def run():
551 with open(bundlepath, 'rb') as fh:
551 with open(bundlepath, b'rb') as fh:
552 bundle = exchange.readbundle(ui, fh, bundlepath)
552 bundle = exchange.readbundle(ui, fh, bundlepath)
553 fn(bundle)
553 fn(bundle)
554
554
@@ -556,7 +556,7 b' def perfbundleread(ui, repo, bundlepath,'
556
556
557 def makereadnbytes(size):
557 def makereadnbytes(size):
558 def run():
558 def run():
559 with open(bundlepath, 'rb') as fh:
559 with open(bundlepath, b'rb') as fh:
560 bundle = exchange.readbundle(ui, fh, bundlepath)
560 bundle = exchange.readbundle(ui, fh, bundlepath)
561 while bundle.read(size):
561 while bundle.read(size):
562 pass
562 pass
@@ -565,7 +565,7 b' def perfbundleread(ui, repo, bundlepath,'
565
565
566 def makestdioread(size):
566 def makestdioread(size):
567 def run():
567 def run():
568 with open(bundlepath, 'rb') as fh:
568 with open(bundlepath, b'rb') as fh:
569 while fh.read(size):
569 while fh.read(size):
570 pass
570 pass
571
571
@@ -601,7 +601,7 b' def perfbundleread(ui, repo, bundlepath,'
601
601
602 def makepartreadnbytes(size):
602 def makepartreadnbytes(size):
603 def run():
603 def run():
604 with open(bundlepath, 'rb') as fh:
604 with open(bundlepath, b'rb') as fh:
605 bundle = exchange.readbundle(ui, fh, bundlepath)
605 bundle = exchange.readbundle(ui, fh, bundlepath)
606 for part in bundle.iterparts():
606 for part in bundle.iterparts():
607 while part.read(size):
607 while part.read(size):
@@ -610,49 +610,49 b' def perfbundleread(ui, repo, bundlepath,'
610 return run
610 return run
611
611
612 benches = [
612 benches = [
613 (makestdioread(8192), 'read(8k)'),
613 (makestdioread(8192), b'read(8k)'),
614 (makestdioread(16384), 'read(16k)'),
614 (makestdioread(16384), b'read(16k)'),
615 (makestdioread(32768), 'read(32k)'),
615 (makestdioread(32768), b'read(32k)'),
616 (makestdioread(131072), 'read(128k)'),
616 (makestdioread(131072), b'read(128k)'),
617 ]
617 ]
618
618
619 with open(bundlepath, 'rb') as fh:
619 with open(bundlepath, b'rb') as fh:
620 bundle = exchange.readbundle(ui, fh, bundlepath)
620 bundle = exchange.readbundle(ui, fh, bundlepath)
621
621
622 if isinstance(bundle, changegroup.cg1unpacker):
622 if isinstance(bundle, changegroup.cg1unpacker):
623 benches.extend([
623 benches.extend([
624 (makebench(deltaiter), 'cg1 deltaiter()'),
624 (makebench(deltaiter), b'cg1 deltaiter()'),
625 (makebench(iterchunks), 'cg1 getchunks()'),
625 (makebench(iterchunks), b'cg1 getchunks()'),
626 (makereadnbytes(8192), 'cg1 read(8k)'),
626 (makereadnbytes(8192), b'cg1 read(8k)'),
627 (makereadnbytes(16384), 'cg1 read(16k)'),
627 (makereadnbytes(16384), b'cg1 read(16k)'),
628 (makereadnbytes(32768), 'cg1 read(32k)'),
628 (makereadnbytes(32768), b'cg1 read(32k)'),
629 (makereadnbytes(131072), 'cg1 read(128k)'),
629 (makereadnbytes(131072), b'cg1 read(128k)'),
630 ])
630 ])
631 elif isinstance(bundle, bundle2.unbundle20):
631 elif isinstance(bundle, bundle2.unbundle20):
632 benches.extend([
632 benches.extend([
633 (makebench(forwardchunks), 'bundle2 forwardchunks()'),
633 (makebench(forwardchunks), b'bundle2 forwardchunks()'),
634 (makebench(iterparts), 'bundle2 iterparts()'),
634 (makebench(iterparts), b'bundle2 iterparts()'),
635 (makebench(iterpartsseekable), 'bundle2 iterparts() seekable'),
635 (makebench(iterpartsseekable), b'bundle2 iterparts() seekable'),
636 (makebench(seek), 'bundle2 part seek()'),
636 (makebench(seek), b'bundle2 part seek()'),
637 (makepartreadnbytes(8192), 'bundle2 part read(8k)'),
637 (makepartreadnbytes(8192), b'bundle2 part read(8k)'),
638 (makepartreadnbytes(16384), 'bundle2 part read(16k)'),
638 (makepartreadnbytes(16384), b'bundle2 part read(16k)'),
639 (makepartreadnbytes(32768), 'bundle2 part read(32k)'),
639 (makepartreadnbytes(32768), b'bundle2 part read(32k)'),
640 (makepartreadnbytes(131072), 'bundle2 part read(128k)'),
640 (makepartreadnbytes(131072), b'bundle2 part read(128k)'),
641 ])
641 ])
642 elif isinstance(bundle, streamclone.streamcloneapplier):
642 elif isinstance(bundle, streamclone.streamcloneapplier):
643 raise error.Abort('stream clone bundles not supported')
643 raise error.Abort(b'stream clone bundles not supported')
644 else:
644 else:
645 raise error.Abort('unhandled bundle type: %s' % type(bundle))
645 raise error.Abort(b'unhandled bundle type: %s' % type(bundle))
646
646
647 for fn, title in benches:
647 for fn, title in benches:
648 timer, fm = gettimer(ui, opts)
648 timer, fm = gettimer(ui, opts)
649 timer(fn, title=title)
649 timer(fn, title=title)
650 fm.end()
650 fm.end()
651
651
652 @command('perfchangegroupchangelog', formatteropts +
652 @command(b'perfchangegroupchangelog', formatteropts +
653 [('', 'version', '02', 'changegroup version'),
653 [(b'', b'version', b'02', b'changegroup version'),
654 ('r', 'rev', '', 'revisions to add to changegroup')])
654 (b'r', b'rev', b'', b'revisions to add to changegroup')])
655 def perfchangegroupchangelog(ui, repo, version='02', rev=None, **opts):
655 def perfchangegroupchangelog(ui, repo, version=b'02', rev=None, **opts):
656 """Benchmark producing a changelog group for a changegroup.
656 """Benchmark producing a changelog group for a changegroup.
657
657
658 This measures the time spent processing the changelog during a
658 This measures the time spent processing the changelog during a
@@ -663,7 +663,7 b' def perfchangegroupchangelog(ui, repo, v'
663 By default, all revisions are added to the changegroup.
663 By default, all revisions are added to the changegroup.
664 """
664 """
665 cl = repo.changelog
665 cl = repo.changelog
666 nodes = [cl.lookup(r) for r in repo.revs(rev or 'all()')]
666 nodes = [cl.lookup(r) for r in repo.revs(rev or b'all()')]
667 bundler = changegroup.getbundler(version, repo)
667 bundler = changegroup.getbundler(version, repo)
668
668
669 def d():
669 def d():
@@ -674,78 +674,78 b' def perfchangegroupchangelog(ui, repo, v'
674 timer, fm = gettimer(ui, opts)
674 timer, fm = gettimer(ui, opts)
675
675
676 # Terminal printing can interfere with timing. So disable it.
676 # Terminal printing can interfere with timing. So disable it.
677 with ui.configoverride({('progress', 'disable'): True}):
677 with ui.configoverride({(b'progress', b'disable'): True}):
678 timer(d)
678 timer(d)
679
679
680 fm.end()
680 fm.end()
681
681
682 @command('perfdirs', formatteropts)
682 @command(b'perfdirs', formatteropts)
683 def perfdirs(ui, repo, **opts):
683 def perfdirs(ui, repo, **opts):
684 timer, fm = gettimer(ui, opts)
684 timer, fm = gettimer(ui, opts)
685 dirstate = repo.dirstate
685 dirstate = repo.dirstate
686 'a' in dirstate
686 b'a' in dirstate
687 def d():
687 def d():
688 dirstate.hasdir('a')
688 dirstate.hasdir(b'a')
689 del dirstate._map._dirs
689 del dirstate._map._dirs
690 timer(d)
690 timer(d)
691 fm.end()
691 fm.end()
692
692
693 @command('perfdirstate', formatteropts)
693 @command(b'perfdirstate', formatteropts)
694 def perfdirstate(ui, repo, **opts):
694 def perfdirstate(ui, repo, **opts):
695 timer, fm = gettimer(ui, opts)
695 timer, fm = gettimer(ui, opts)
696 "a" in repo.dirstate
696 b"a" in repo.dirstate
697 def d():
697 def d():
698 repo.dirstate.invalidate()
698 repo.dirstate.invalidate()
699 "a" in repo.dirstate
699 b"a" in repo.dirstate
700 timer(d)
700 timer(d)
701 fm.end()
701 fm.end()
702
702
703 @command('perfdirstatedirs', formatteropts)
703 @command(b'perfdirstatedirs', formatteropts)
704 def perfdirstatedirs(ui, repo, **opts):
704 def perfdirstatedirs(ui, repo, **opts):
705 timer, fm = gettimer(ui, opts)
705 timer, fm = gettimer(ui, opts)
706 "a" in repo.dirstate
706 b"a" in repo.dirstate
707 def d():
707 def d():
708 repo.dirstate.hasdir("a")
708 repo.dirstate.hasdir(b"a")
709 del repo.dirstate._map._dirs
709 del repo.dirstate._map._dirs
710 timer(d)
710 timer(d)
711 fm.end()
711 fm.end()
712
712
713 @command('perfdirstatefoldmap', formatteropts)
713 @command(b'perfdirstatefoldmap', formatteropts)
714 def perfdirstatefoldmap(ui, repo, **opts):
714 def perfdirstatefoldmap(ui, repo, **opts):
715 timer, fm = gettimer(ui, opts)
715 timer, fm = gettimer(ui, opts)
716 dirstate = repo.dirstate
716 dirstate = repo.dirstate
717 'a' in dirstate
717 b'a' in dirstate
718 def d():
718 def d():
719 dirstate._map.filefoldmap.get('a')
719 dirstate._map.filefoldmap.get(b'a')
720 del dirstate._map.filefoldmap
720 del dirstate._map.filefoldmap
721 timer(d)
721 timer(d)
722 fm.end()
722 fm.end()
723
723
724 @command('perfdirfoldmap', formatteropts)
724 @command(b'perfdirfoldmap', formatteropts)
725 def perfdirfoldmap(ui, repo, **opts):
725 def perfdirfoldmap(ui, repo, **opts):
726 timer, fm = gettimer(ui, opts)
726 timer, fm = gettimer(ui, opts)
727 dirstate = repo.dirstate
727 dirstate = repo.dirstate
728 'a' in dirstate
728 b'a' in dirstate
729 def d():
729 def d():
730 dirstate._map.dirfoldmap.get('a')
730 dirstate._map.dirfoldmap.get(b'a')
731 del dirstate._map.dirfoldmap
731 del dirstate._map.dirfoldmap
732 del dirstate._map._dirs
732 del dirstate._map._dirs
733 timer(d)
733 timer(d)
734 fm.end()
734 fm.end()
735
735
736 @command('perfdirstatewrite', formatteropts)
736 @command(b'perfdirstatewrite', formatteropts)
737 def perfdirstatewrite(ui, repo, **opts):
737 def perfdirstatewrite(ui, repo, **opts):
738 timer, fm = gettimer(ui, opts)
738 timer, fm = gettimer(ui, opts)
739 ds = repo.dirstate
739 ds = repo.dirstate
740 "a" in ds
740 b"a" in ds
741 def d():
741 def d():
742 ds._dirty = True
742 ds._dirty = True
743 ds.write(repo.currenttransaction())
743 ds.write(repo.currenttransaction())
744 timer(d)
744 timer(d)
745 fm.end()
745 fm.end()
746
746
747 @command('perfmergecalculate',
747 @command(b'perfmergecalculate',
748 [('r', 'rev', '.', 'rev to merge against')] + formatteropts)
748 [(b'r', b'rev', b'.', b'rev to merge against')] + formatteropts)
749 def perfmergecalculate(ui, repo, rev, **opts):
749 def perfmergecalculate(ui, repo, rev, **opts):
750 timer, fm = gettimer(ui, opts)
750 timer, fm = gettimer(ui, opts)
751 wctx = repo[None]
751 wctx = repo[None]
@@ -762,7 +762,7 b' def perfmergecalculate(ui, repo, rev, **'
762 timer(d)
762 timer(d)
763 fm.end()
763 fm.end()
764
764
765 @command('perfpathcopies', [], "REV REV")
765 @command(b'perfpathcopies', [], b"REV REV")
766 def perfpathcopies(ui, repo, rev1, rev2, **opts):
766 def perfpathcopies(ui, repo, rev1, rev2, **opts):
767 timer, fm = gettimer(ui, opts)
767 timer, fm = gettimer(ui, opts)
768 ctx1 = scmutil.revsingle(repo, rev1, rev1)
768 ctx1 = scmutil.revsingle(repo, rev1, rev1)
@@ -772,26 +772,26 b' def perfpathcopies(ui, repo, rev1, rev2,'
772 timer(d)
772 timer(d)
773 fm.end()
773 fm.end()
774
774
775 @command('perfphases',
775 @command(b'perfphases',
776 [('', 'full', False, 'include file reading time too'),
776 [(b'', b'full', False, b'include file reading time too'),
777 ], "")
777 ], b"")
778 def perfphases(ui, repo, **opts):
778 def perfphases(ui, repo, **opts):
779 """benchmark phasesets computation"""
779 """benchmark phasesets computation"""
780 timer, fm = gettimer(ui, opts)
780 timer, fm = gettimer(ui, opts)
781 _phases = repo._phasecache
781 _phases = repo._phasecache
782 full = opts.get('full')
782 full = opts.get(b'full')
783 def d():
783 def d():
784 phases = _phases
784 phases = _phases
785 if full:
785 if full:
786 clearfilecache(repo, '_phasecache')
786 clearfilecache(repo, b'_phasecache')
787 phases = repo._phasecache
787 phases = repo._phasecache
788 phases.invalidate()
788 phases.invalidate()
789 phases.loadphaserevs(repo)
789 phases.loadphaserevs(repo)
790 timer(d)
790 timer(d)
791 fm.end()
791 fm.end()
792
792
793 @command('perfphasesremote',
793 @command(b'perfphasesremote',
794 [], "[DEST]")
794 [], b"[DEST]")
795 def perfphasesremote(ui, repo, dest=None, **opts):
795 def perfphasesremote(ui, repo, dest=None, **opts):
796 """benchmark time needed to analyse phases of the remote server"""
796 """benchmark time needed to analyse phases of the remote server"""
797 from mercurial.node import (
797 from mercurial.node import (
@@ -804,14 +804,14 b' def perfphasesremote(ui, repo, dest=None'
804 )
804 )
805 timer, fm = gettimer(ui, opts)
805 timer, fm = gettimer(ui, opts)
806
806
807 path = ui.paths.getpath(dest, default=('default-push', 'default'))
807 path = ui.paths.getpath(dest, default=(b'default-push', b'default'))
808 if not path:
808 if not path:
809 raise error.Abort(('default repository not configured!'),
809 raise error.Abort((b'default repository not configured!'),
810 hint=("see 'hg help config.paths'"))
810 hint=(b"see 'hg help config.paths'"))
811 dest = path.pushloc or path.loc
811 dest = path.pushloc or path.loc
812 branches = (path.branch, opts.get('branch') or [])
812 branches = (path.branch, opts.get(b'branch') or [])
813 ui.status(('analysing phase of %s\n') % util.hidepassword(dest))
813 ui.status((b'analysing phase of %s\n') % util.hidepassword(dest))
814 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
814 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get(b'rev'))
815 other = hg.peer(repo, opts, dest)
815 other = hg.peer(repo, opts, dest)
816
816
817 # easier to perform discovery through the operation
817 # easier to perform discovery through the operation
@@ -821,25 +821,25 b' def perfphasesremote(ui, repo, dest=None'
821 remotesubset = op.fallbackheads
821 remotesubset = op.fallbackheads
822
822
823 with other.commandexecutor() as e:
823 with other.commandexecutor() as e:
824 remotephases = e.callcommand('listkeys',
824 remotephases = e.callcommand(b'listkeys',
825 {'namespace': 'phases'}).result()
825 {b'namespace': b'phases'}).result()
826 del other
826 del other
827 publishing = remotephases.get('publishing', False)
827 publishing = remotephases.get(b'publishing', False)
828 if publishing:
828 if publishing:
829 ui.status(('publishing: yes\n'))
829 ui.status((b'publishing: yes\n'))
830 else:
830 else:
831 ui.status(('publishing: no\n'))
831 ui.status((b'publishing: no\n'))
832
832
833 nodemap = repo.changelog.nodemap
833 nodemap = repo.changelog.nodemap
834 nonpublishroots = 0
834 nonpublishroots = 0
835 for nhex, phase in remotephases.iteritems():
835 for nhex, phase in remotephases.iteritems():
836 if nhex == 'publishing': # ignore data related to publish option
836 if nhex == b'publishing': # ignore data related to publish option
837 continue
837 continue
838 node = bin(nhex)
838 node = bin(nhex)
839 if node in nodemap and int(phase):
839 if node in nodemap and int(phase):
840 nonpublishroots += 1
840 nonpublishroots += 1
841 ui.status(('number of roots: %d\n') % len(remotephases))
841 ui.status((b'number of roots: %d\n') % len(remotephases))
842 ui.status(('number of known non public roots: %d\n') % nonpublishroots)
842 ui.status((b'number of known non public roots: %d\n') % nonpublishroots)
843 def d():
843 def d():
844 phases.remotephasessummary(repo,
844 phases.remotephasessummary(repo,
845 remotesubset,
845 remotesubset,
@@ -847,10 +847,10 b' def perfphasesremote(ui, repo, dest=None'
847 timer(d)
847 timer(d)
848 fm.end()
848 fm.end()
849
849
850 @command('perfmanifest',[
850 @command(b'perfmanifest',[
851 ('m', 'manifest-rev', False, 'Look up a manifest node revision'),
851 (b'm', b'manifest-rev', False, b'Look up a manifest node revision'),
852 ('', 'clear-disk', False, 'clear on-disk caches too'),
852 (b'', b'clear-disk', False, b'clear on-disk caches too'),
853 ], 'REV|NODE')
853 ], b'REV|NODE')
854 def perfmanifest(ui, repo, rev, manifest_rev=False, clear_disk=False, **opts):
854 def perfmanifest(ui, repo, rev, manifest_rev=False, clear_disk=False, **opts):
855 """benchmark the time to read a manifest from disk and return a usable
855 """benchmark the time to read a manifest from disk and return a usable
856 dict-like object
856 dict-like object
@@ -869,20 +869,20 b' def perfmanifest(ui, repo, rev, manifest'
869 try:
869 try:
870 rev = int(rev)
870 rev = int(rev)
871
871
872 if util.safehasattr(repo.manifestlog, 'getstorage'):
872 if util.safehasattr(repo.manifestlog, b'getstorage'):
873 t = repo.manifestlog.getstorage(b'').node(rev)
873 t = repo.manifestlog.getstorage(b'').node(rev)
874 else:
874 else:
875 t = repo.manifestlog._revlog.lookup(rev)
875 t = repo.manifestlog._revlog.lookup(rev)
876 except ValueError:
876 except ValueError:
877 raise error.Abort('manifest revision must be integer or full '
877 raise error.Abort(b'manifest revision must be integer or full '
878 'node')
878 b'node')
879 def d():
879 def d():
880 repo.manifestlog.clearcaches(clear_persisted_data=clear_disk)
880 repo.manifestlog.clearcaches(clear_persisted_data=clear_disk)
881 repo.manifestlog[t].read()
881 repo.manifestlog[t].read()
882 timer(d)
882 timer(d)
883 fm.end()
883 fm.end()
884
884
885 @command('perfchangeset', formatteropts)
885 @command(b'perfchangeset', formatteropts)
886 def perfchangeset(ui, repo, rev, **opts):
886 def perfchangeset(ui, repo, rev, **opts):
887 timer, fm = gettimer(ui, opts)
887 timer, fm = gettimer(ui, opts)
888 n = scmutil.revsingle(repo, rev).node()
888 n = scmutil.revsingle(repo, rev).node()
@@ -892,40 +892,40 b' def perfchangeset(ui, repo, rev, **opts)'
892 timer(d)
892 timer(d)
893 fm.end()
893 fm.end()
894
894
895 @command('perfindex', formatteropts)
895 @command(b'perfindex', formatteropts)
896 def perfindex(ui, repo, **opts):
896 def perfindex(ui, repo, **opts):
897 import mercurial.revlog
897 import mercurial.revlog
898 timer, fm = gettimer(ui, opts)
898 timer, fm = gettimer(ui, opts)
899 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
899 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
900 n = repo["tip"].node()
900 n = repo[b"tip"].node()
901 svfs = getsvfs(repo)
901 svfs = getsvfs(repo)
902 def d():
902 def d():
903 cl = mercurial.revlog.revlog(svfs, "00changelog.i")
903 cl = mercurial.revlog.revlog(svfs, b"00changelog.i")
904 cl.rev(n)
904 cl.rev(n)
905 timer(d)
905 timer(d)
906 fm.end()
906 fm.end()
907
907
908 @command('perfstartup', formatteropts)
908 @command(b'perfstartup', formatteropts)
909 def perfstartup(ui, repo, **opts):
909 def perfstartup(ui, repo, **opts):
910 timer, fm = gettimer(ui, opts)
910 timer, fm = gettimer(ui, opts)
911 cmd = sys.argv[0]
911 cmd = sys.argv[0]
912 def d():
912 def d():
913 if os.name != 'nt':
913 if os.name != b'nt':
914 os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
914 os.system(b"HGRCPATH= %s version -q > /dev/null" % cmd)
915 else:
915 else:
916 os.environ['HGRCPATH'] = ' '
916 os.environ[b'HGRCPATH'] = b' '
917 os.system("%s version -q > NUL" % cmd)
917 os.system(b"%s version -q > NUL" % cmd)
918 timer(d)
918 timer(d)
919 fm.end()
919 fm.end()
920
920
921 @command('perfparents', formatteropts)
921 @command(b'perfparents', formatteropts)
922 def perfparents(ui, repo, **opts):
922 def perfparents(ui, repo, **opts):
923 timer, fm = gettimer(ui, opts)
923 timer, fm = gettimer(ui, opts)
924 # control the number of commits perfparents iterates over
924 # control the number of commits perfparents iterates over
925 # experimental config: perf.parentscount
925 # experimental config: perf.parentscount
926 count = getint(ui, "perf", "parentscount", 1000)
926 count = getint(ui, b"perf", b"parentscount", 1000)
927 if len(repo.changelog) < count:
927 if len(repo.changelog) < count:
928 raise error.Abort("repo needs %d commits for this test" % count)
928 raise error.Abort(b"repo needs %d commits for this test" % count)
929 repo = repo.unfiltered()
929 repo = repo.unfiltered()
930 nl = [repo.changelog.node(i) for i in xrange(count)]
930 nl = [repo.changelog.node(i) for i in xrange(count)]
931 def d():
931 def d():
@@ -934,7 +934,7 b' def perfparents(ui, repo, **opts):'
934 timer(d)
934 timer(d)
935 fm.end()
935 fm.end()
936
936
937 @command('perfctxfiles', formatteropts)
937 @command(b'perfctxfiles', formatteropts)
938 def perfctxfiles(ui, repo, x, **opts):
938 def perfctxfiles(ui, repo, x, **opts):
939 x = int(x)
939 x = int(x)
940 timer, fm = gettimer(ui, opts)
940 timer, fm = gettimer(ui, opts)
@@ -943,7 +943,7 b' def perfctxfiles(ui, repo, x, **opts):'
943 timer(d)
943 timer(d)
944 fm.end()
944 fm.end()
945
945
946 @command('perfrawfiles', formatteropts)
946 @command(b'perfrawfiles', formatteropts)
947 def perfrawfiles(ui, repo, x, **opts):
947 def perfrawfiles(ui, repo, x, **opts):
948 x = int(x)
948 x = int(x)
949 timer, fm = gettimer(ui, opts)
949 timer, fm = gettimer(ui, opts)
@@ -953,21 +953,21 b' def perfrawfiles(ui, repo, x, **opts):'
953 timer(d)
953 timer(d)
954 fm.end()
954 fm.end()
955
955
956 @command('perflookup', formatteropts)
956 @command(b'perflookup', formatteropts)
957 def perflookup(ui, repo, rev, **opts):
957 def perflookup(ui, repo, rev, **opts):
958 timer, fm = gettimer(ui, opts)
958 timer, fm = gettimer(ui, opts)
959 timer(lambda: len(repo.lookup(rev)))
959 timer(lambda: len(repo.lookup(rev)))
960 fm.end()
960 fm.end()
961
961
962 @command('perflinelogedits',
962 @command(b'perflinelogedits',
963 [('n', 'edits', 10000, 'number of edits'),
963 [(b'n', b'edits', 10000, b'number of edits'),
964 ('', 'max-hunk-lines', 10, 'max lines in a hunk'),
964 (b'', b'max-hunk-lines', 10, b'max lines in a hunk'),
965 ], norepo=True)
965 ], norepo=True)
966 def perflinelogedits(ui, **opts):
966 def perflinelogedits(ui, **opts):
967 from mercurial import linelog
967 from mercurial import linelog
968
968
969 edits = opts['edits']
969 edits = opts[b'edits']
970 maxhunklines = opts['max_hunk_lines']
970 maxhunklines = opts[b'max_hunk_lines']
971
971
972 maxb1 = 100000
972 maxb1 = 100000
973 random.seed(0)
973 random.seed(0)
@@ -991,39 +991,40 b' def perflinelogedits(ui, **opts):'
991 timer(d)
991 timer(d)
992 fm.end()
992 fm.end()
993
993
994 @command('perfrevrange', formatteropts)
994 @command(b'perfrevrange', formatteropts)
995 def perfrevrange(ui, repo, *specs, **opts):
995 def perfrevrange(ui, repo, *specs, **opts):
996 timer, fm = gettimer(ui, opts)
996 timer, fm = gettimer(ui, opts)
997 revrange = scmutil.revrange
997 revrange = scmutil.revrange
998 timer(lambda: len(revrange(repo, specs)))
998 timer(lambda: len(revrange(repo, specs)))
999 fm.end()
999 fm.end()
1000
1000
1001 @command('perfnodelookup', formatteropts)
1001 @command(b'perfnodelookup', formatteropts)
1002 def perfnodelookup(ui, repo, rev, **opts):
1002 def perfnodelookup(ui, repo, rev, **opts):
1003 timer, fm = gettimer(ui, opts)
1003 timer, fm = gettimer(ui, opts)
1004 import mercurial.revlog
1004 import mercurial.revlog
1005 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
1005 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
1006 n = scmutil.revsingle(repo, rev).node()
1006 n = scmutil.revsingle(repo, rev).node()
1007 cl = mercurial.revlog.revlog(getsvfs(repo), "00changelog.i")
1007 cl = mercurial.revlog.revlog(getsvfs(repo), b"00changelog.i")
1008 def d():
1008 def d():
1009 cl.rev(n)
1009 cl.rev(n)
1010 clearcaches(cl)
1010 clearcaches(cl)
1011 timer(d)
1011 timer(d)
1012 fm.end()
1012 fm.end()
1013
1013
1014 @command('perflog',
1014 @command(b'perflog',
1015 [('', 'rename', False, 'ask log to follow renames')] + formatteropts)
1015 [(b'', b'rename', False, b'ask log to follow renames')
1016 ] + formatteropts)
1016 def perflog(ui, repo, rev=None, **opts):
1017 def perflog(ui, repo, rev=None, **opts):
1017 if rev is None:
1018 if rev is None:
1018 rev=[]
1019 rev=[]
1019 timer, fm = gettimer(ui, opts)
1020 timer, fm = gettimer(ui, opts)
1020 ui.pushbuffer()
1021 ui.pushbuffer()
1021 timer(lambda: commands.log(ui, repo, rev=rev, date='', user='',
1022 timer(lambda: commands.log(ui, repo, rev=rev, date=b'', user=b'',
1022 copies=opts.get('rename')))
1023 copies=opts.get(b'rename')))
1023 ui.popbuffer()
1024 ui.popbuffer()
1024 fm.end()
1025 fm.end()
1025
1026
1026 @command('perfmoonwalk', formatteropts)
1027 @command(b'perfmoonwalk', formatteropts)
1027 def perfmoonwalk(ui, repo, **opts):
1028 def perfmoonwalk(ui, repo, **opts):
1028 """benchmark walking the changelog backwards
1029 """benchmark walking the changelog backwards
1029
1030
@@ -1037,25 +1038,25 b' def perfmoonwalk(ui, repo, **opts):'
1037 timer(moonwalk)
1038 timer(moonwalk)
1038 fm.end()
1039 fm.end()
1039
1040
1040 @command('perftemplating',
1041 @command(b'perftemplating',
1041 [('r', 'rev', [], 'revisions to run the template on'),
1042 [(b'r', b'rev', [], b'revisions to run the template on'),
1042 ] + formatteropts)
1043 ] + formatteropts)
1043 def perftemplating(ui, repo, testedtemplate=None, **opts):
1044 def perftemplating(ui, repo, testedtemplate=None, **opts):
1044 """test the rendering time of a given template"""
1045 """test the rendering time of a given template"""
1045 if makelogtemplater is None:
1046 if makelogtemplater is None:
1046 raise error.Abort(("perftemplating not available with this Mercurial"),
1047 raise error.Abort((b"perftemplating not available with this Mercurial"),
1047 hint="use 4.3 or later")
1048 hint=b"use 4.3 or later")
1048
1049
1049 nullui = ui.copy()
1050 nullui = ui.copy()
1050 nullui.fout = open(os.devnull, 'wb')
1051 nullui.fout = open(os.devnull, b'wb')
1051 nullui.disablepager()
1052 nullui.disablepager()
1052 revs = opts.get('rev')
1053 revs = opts.get(b'rev')
1053 if not revs:
1054 if not revs:
1054 revs = ['all()']
1055 revs = [b'all()']
1055 revs = list(scmutil.revrange(repo, revs))
1056 revs = list(scmutil.revrange(repo, revs))
1056
1057
1057 defaulttemplate = ('{date|shortdate} [{rev}:{node|short}]'
1058 defaulttemplate = (b'{date|shortdate} [{rev}:{node|short}]'
1058 ' {author|person}: {desc|firstline}\n')
1059 b' {author|person}: {desc|firstline}\n')
1059 if testedtemplate is None:
1060 if testedtemplate is None:
1060 testedtemplate = defaulttemplate
1061 testedtemplate = defaulttemplate
1061 displayer = makelogtemplater(nullui, repo, testedtemplate)
1062 displayer = makelogtemplater(nullui, repo, testedtemplate)
@@ -1069,13 +1070,13 b' def perftemplating(ui, repo, testedtempl'
1069 timer(format)
1070 timer(format)
1070 fm.end()
1071 fm.end()
1071
1072
1072 @command('perfcca', formatteropts)
1073 @command(b'perfcca', formatteropts)
1073 def perfcca(ui, repo, **opts):
1074 def perfcca(ui, repo, **opts):
1074 timer, fm = gettimer(ui, opts)
1075 timer, fm = gettimer(ui, opts)
1075 timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
1076 timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
1076 fm.end()
1077 fm.end()
1077
1078
1078 @command('perffncacheload', formatteropts)
1079 @command(b'perffncacheload', formatteropts)
1079 def perffncacheload(ui, repo, **opts):
1080 def perffncacheload(ui, repo, **opts):
1080 timer, fm = gettimer(ui, opts)
1081 timer, fm = gettimer(ui, opts)
1081 s = repo.store
1082 s = repo.store
@@ -1084,14 +1085,14 b' def perffncacheload(ui, repo, **opts):'
1084 timer(d)
1085 timer(d)
1085 fm.end()
1086 fm.end()
1086
1087
1087 @command('perffncachewrite', formatteropts)
1088 @command(b'perffncachewrite', formatteropts)
1088 def perffncachewrite(ui, repo, **opts):
1089 def perffncachewrite(ui, repo, **opts):
1089 timer, fm = gettimer(ui, opts)
1090 timer, fm = gettimer(ui, opts)
1090 s = repo.store
1091 s = repo.store
1091 lock = repo.lock()
1092 lock = repo.lock()
1092 s.fncache._load()
1093 s.fncache._load()
1093 tr = repo.transaction('perffncachewrite')
1094 tr = repo.transaction(b'perffncachewrite')
1094 tr.addbackup('fncache')
1095 tr.addbackup(b'fncache')
1095 def d():
1096 def d():
1096 s.fncache._dirty = True
1097 s.fncache._dirty = True
1097 s.fncache.write(tr)
1098 s.fncache.write(tr)
@@ -1100,7 +1101,7 b' def perffncachewrite(ui, repo, **opts):'
1100 lock.release()
1101 lock.release()
1101 fm.end()
1102 fm.end()
1102
1103
1103 @command('perffncacheencode', formatteropts)
1104 @command(b'perffncacheencode', formatteropts)
1104 def perffncacheencode(ui, repo, **opts):
1105 def perffncacheencode(ui, repo, **opts):
1105 timer, fm = gettimer(ui, opts)
1106 timer, fm = gettimer(ui, opts)
1106 s = repo.store
1107 s = repo.store
@@ -1130,22 +1131,22 b' def _bdiffworker(q, blocks, xdiff, ready'
1130 def _manifestrevision(repo, mnode):
1131 def _manifestrevision(repo, mnode):
1131 ml = repo.manifestlog
1132 ml = repo.manifestlog
1132
1133
1133 if util.safehasattr(ml, 'getstorage'):
1134 if util.safehasattr(ml, b'getstorage'):
1134 store = ml.getstorage(b'')
1135 store = ml.getstorage(b'')
1135 else:
1136 else:
1136 store = ml._revlog
1137 store = ml._revlog
1137
1138
1138 return store.revision(mnode)
1139 return store.revision(mnode)
1139
1140
1140 @command('perfbdiff', revlogopts + formatteropts + [
1141 @command(b'perfbdiff', revlogopts + formatteropts + [
1141 ('', 'count', 1, 'number of revisions to test (when using --startrev)'),
1142 (b'', b'count', 1, b'number of revisions to test (when using --startrev)'),
1142 ('', 'alldata', False, 'test bdiffs for all associated revisions'),
1143 (b'', b'alldata', False, b'test bdiffs for all associated revisions'),
1143 ('', 'threads', 0, 'number of thread to use (disable with 0)'),
1144 (b'', b'threads', 0, b'number of thread to use (disable with 0)'),
1144 ('', 'blocks', False, 'test computing diffs into blocks'),
1145 (b'', b'blocks', False, b'test computing diffs into blocks'),
1145 ('', 'xdiff', False, 'use xdiff algorithm'),
1146 (b'', b'xdiff', False, b'use xdiff algorithm'),
1146 ],
1147 ],
1147
1148
1148 '-c|-m|FILE REV')
1149 b'-c|-m|FILE REV')
1149 def perfbdiff(ui, repo, file_, rev=None, count=None, threads=0, **opts):
1150 def perfbdiff(ui, repo, file_, rev=None, count=None, threads=0, **opts):
1150 """benchmark a bdiff between revisions
1151 """benchmark a bdiff between revisions
1151
1152
@@ -1160,26 +1161,26 b' def perfbdiff(ui, repo, file_, rev=None,'
1160 """
1161 """
1161 opts = pycompat.byteskwargs(opts)
1162 opts = pycompat.byteskwargs(opts)
1162
1163
1163 if opts['xdiff'] and not opts['blocks']:
1164 if opts[b'xdiff'] and not opts[b'blocks']:
1164 raise error.CommandError('perfbdiff', '--xdiff requires --blocks')
1165 raise error.CommandError(b'perfbdiff', b'--xdiff requires --blocks')
1165
1166
1166 if opts['alldata']:
1167 if opts[b'alldata']:
1167 opts['changelog'] = True
1168 opts[b'changelog'] = True
1168
1169
1169 if opts.get('changelog') or opts.get('manifest'):
1170 if opts.get(b'changelog') or opts.get(b'manifest'):
1170 file_, rev = None, file_
1171 file_, rev = None, file_
1171 elif rev is None:
1172 elif rev is None:
1172 raise error.CommandError('perfbdiff', 'invalid arguments')
1173 raise error.CommandError(b'perfbdiff', b'invalid arguments')
1173
1174
1174 blocks = opts['blocks']
1175 blocks = opts[b'blocks']
1175 xdiff = opts['xdiff']
1176 xdiff = opts[b'xdiff']
1176 textpairs = []
1177 textpairs = []
1177
1178
1178 r = cmdutil.openrevlog(repo, 'perfbdiff', file_, opts)
1179 r = cmdutil.openrevlog(repo, b'perfbdiff', file_, opts)
1179
1180
1180 startrev = r.rev(r.lookup(rev))
1181 startrev = r.rev(r.lookup(rev))
1181 for rev in range(startrev, min(startrev + count, len(r) - 1)):
1182 for rev in range(startrev, min(startrev + count, len(r) - 1)):
1182 if opts['alldata']:
1183 if opts[b'alldata']:
1183 # Load revisions associated with changeset.
1184 # Load revisions associated with changeset.
1184 ctx = repo[rev]
1185 ctx = repo[rev]
1185 mtext = _manifestrevision(repo, ctx.manifestnode())
1186 mtext = _manifestrevision(repo, ctx.manifestnode())
@@ -1238,10 +1239,10 b' def perfbdiff(ui, repo, file_, rev=None,'
1238 with ready:
1239 with ready:
1239 ready.notify_all()
1240 ready.notify_all()
1240
1241
1241 @command('perfunidiff', revlogopts + formatteropts + [
1242 @command(b'perfunidiff', revlogopts + formatteropts + [
1242 ('', 'count', 1, 'number of revisions to test (when using --startrev)'),
1243 (b'', b'count', 1, b'number of revisions to test (when using --startrev)'),
1243 ('', 'alldata', False, 'test unidiffs for all associated revisions'),
1244 (b'', b'alldata', False, b'test unidiffs for all associated revisions'),
1244 ], '-c|-m|FILE REV')
1245 ], b'-c|-m|FILE REV')
1245 def perfunidiff(ui, repo, file_, rev=None, count=None, **opts):
1246 def perfunidiff(ui, repo, file_, rev=None, count=None, **opts):
1246 """benchmark a unified diff between revisions
1247 """benchmark a unified diff between revisions
1247
1248
@@ -1257,21 +1258,21 b' def perfunidiff(ui, repo, file_, rev=Non'
1257 measure diffs for all changes related to that changeset (manifest
1258 measure diffs for all changes related to that changeset (manifest
1258 and filelogs).
1259 and filelogs).
1259 """
1260 """
1260 if opts['alldata']:
1261 if opts[b'alldata']:
1261 opts['changelog'] = True
1262 opts[b'changelog'] = True
1262
1263
1263 if opts.get('changelog') or opts.get('manifest'):
1264 if opts.get(b'changelog') or opts.get(b'manifest'):
1264 file_, rev = None, file_
1265 file_, rev = None, file_
1265 elif rev is None:
1266 elif rev is None:
1266 raise error.CommandError('perfunidiff', 'invalid arguments')
1267 raise error.CommandError(b'perfunidiff', b'invalid arguments')
1267
1268
1268 textpairs = []
1269 textpairs = []
1269
1270
1270 r = cmdutil.openrevlog(repo, 'perfunidiff', file_, opts)
1271 r = cmdutil.openrevlog(repo, b'perfunidiff', file_, opts)
1271
1272
1272 startrev = r.rev(r.lookup(rev))
1273 startrev = r.rev(r.lookup(rev))
1273 for rev in range(startrev, min(startrev + count, len(r) - 1)):
1274 for rev in range(startrev, min(startrev + count, len(r) - 1)):
1274 if opts['alldata']:
1275 if opts[b'alldata']:
1275 # Load revisions associated with changeset.
1276 # Load revisions associated with changeset.
1276 ctx = repo[rev]
1277 ctx = repo[rev]
1277 mtext = _manifestrevision(repo, ctx.manifestnode())
1278 mtext = _manifestrevision(repo, ctx.manifestnode())
@@ -1295,7 +1296,7 b' def perfunidiff(ui, repo, file_, rev=Non'
1295 for left, right in textpairs:
1296 for left, right in textpairs:
1296 # The date strings don't matter, so we pass empty strings.
1297 # The date strings don't matter, so we pass empty strings.
1297 headerlines, hunks = mdiff.unidiff(
1298 headerlines, hunks = mdiff.unidiff(
1298 left, '', right, '', 'left', 'right', binary=False)
1299 left, b'', right, b'', b'left', b'right', binary=False)
1299 # consume iterators in roughly the way patch.py does
1300 # consume iterators in roughly the way patch.py does
1300 b'\n'.join(headerlines)
1301 b'\n'.join(headerlines)
1301 b''.join(sum((list(hlines) for hrange, hlines in hunks), []))
1302 b''.join(sum((list(hlines) for hrange, hlines in hunks), []))
@@ -1303,28 +1304,28 b' def perfunidiff(ui, repo, file_, rev=Non'
1303 timer(d)
1304 timer(d)
1304 fm.end()
1305 fm.end()
1305
1306
1306 @command('perfdiffwd', formatteropts)
1307 @command(b'perfdiffwd', formatteropts)
1307 def perfdiffwd(ui, repo, **opts):
1308 def perfdiffwd(ui, repo, **opts):
1308 """Profile diff of working directory changes"""
1309 """Profile diff of working directory changes"""
1309 timer, fm = gettimer(ui, opts)
1310 timer, fm = gettimer(ui, opts)
1310 options = {
1311 options = {
1311 'w': 'ignore_all_space',
1312 b'w': b'ignore_all_space',
1312 'b': 'ignore_space_change',
1313 b'b': b'ignore_space_change',
1313 'B': 'ignore_blank_lines',
1314 b'B': b'ignore_blank_lines',
1314 }
1315 }
1315
1316
1316 for diffopt in ('', 'w', 'b', 'B', 'wB'):
1317 for diffopt in (b'', b'w', b'b', b'B', b'wB'):
1317 opts = dict((options[c], '1') for c in diffopt)
1318 opts = dict((options[c], b'1') for c in diffopt)
1318 def d():
1319 def d():
1319 ui.pushbuffer()
1320 ui.pushbuffer()
1320 commands.diff(ui, repo, **opts)
1321 commands.diff(ui, repo, **opts)
1321 ui.popbuffer()
1322 ui.popbuffer()
1322 title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
1323 title = b'diffopts: %s' % (diffopt and (b'-' + diffopt) or b'none')
1323 timer(d, title)
1324 timer(d, title)
1324 fm.end()
1325 fm.end()
1325
1326
1326 @command('perfrevlogindex', revlogopts + formatteropts,
1327 @command(b'perfrevlogindex', revlogopts + formatteropts,
1327 '-c|-m|FILE')
1328 b'-c|-m|FILE')
1328 def perfrevlogindex(ui, repo, file_=None, **opts):
1329 def perfrevlogindex(ui, repo, file_=None, **opts):
1329 """Benchmark operations against a revlog index.
1330 """Benchmark operations against a revlog index.
1330
1331
@@ -1333,19 +1334,19 b' def perfrevlogindex(ui, repo, file_=None'
1333 index data.
1334 index data.
1334 """
1335 """
1335
1336
1336 rl = cmdutil.openrevlog(repo, 'perfrevlogindex', file_, opts)
1337 rl = cmdutil.openrevlog(repo, b'perfrevlogindex', file_, opts)
1337
1338
1338 opener = getattr(rl, 'opener') # trick linter
1339 opener = getattr(rl, 'opener') # trick linter
1339 indexfile = rl.indexfile
1340 indexfile = rl.indexfile
1340 data = opener.read(indexfile)
1341 data = opener.read(indexfile)
1341
1342
1342 header = struct.unpack('>I', data[0:4])[0]
1343 header = struct.unpack(b'>I', data[0:4])[0]
1343 version = header & 0xFFFF
1344 version = header & 0xFFFF
1344 if version == 1:
1345 if version == 1:
1345 revlogio = revlog.revlogio()
1346 revlogio = revlog.revlogio()
1346 inline = header & (1 << 16)
1347 inline = header & (1 << 16)
1347 else:
1348 else:
1348 raise error.Abort(('unsupported revlog version: %d') % version)
1349 raise error.Abort((b'unsupported revlog version: %d') % version)
1349
1350
1350 rllen = len(rl)
1351 rllen = len(rl)
1351
1352
@@ -1405,33 +1406,33 b' def perfrevlogindex(ui, repo, file_=None'
1405 pass
1406 pass
1406
1407
1407 benches = [
1408 benches = [
1408 (constructor, 'revlog constructor'),
1409 (constructor, b'revlog constructor'),
1409 (read, 'read'),
1410 (read, b'read'),
1410 (parseindex, 'create index object'),
1411 (parseindex, b'create index object'),
1411 (lambda: getentry(0), 'retrieve index entry for rev 0'),
1412 (lambda: getentry(0), b'retrieve index entry for rev 0'),
1412 (lambda: resolvenode('a' * 20), 'look up missing node'),
1413 (lambda: resolvenode(b'a' * 20), b'look up missing node'),
1413 (lambda: resolvenode(node0), 'look up node at rev 0'),
1414 (lambda: resolvenode(node0), b'look up node at rev 0'),
1414 (lambda: resolvenode(node25), 'look up node at 1/4 len'),
1415 (lambda: resolvenode(node25), b'look up node at 1/4 len'),
1415 (lambda: resolvenode(node50), 'look up node at 1/2 len'),
1416 (lambda: resolvenode(node50), b'look up node at 1/2 len'),
1416 (lambda: resolvenode(node75), 'look up node at 3/4 len'),
1417 (lambda: resolvenode(node75), b'look up node at 3/4 len'),
1417 (lambda: resolvenode(node100), 'look up node at tip'),
1418 (lambda: resolvenode(node100), b'look up node at tip'),
1418 # 2x variation is to measure caching impact.
1419 # 2x variation is to measure caching impact.
1419 (lambda: resolvenodes(allnodes),
1420 (lambda: resolvenodes(allnodes),
1420 'look up all nodes (forward)'),
1421 b'look up all nodes (forward)'),
1421 (lambda: resolvenodes(allnodes, 2),
1422 (lambda: resolvenodes(allnodes, 2),
1422 'look up all nodes 2x (forward)'),
1423 b'look up all nodes 2x (forward)'),
1423 (lambda: resolvenodes(allnodesrev),
1424 (lambda: resolvenodes(allnodesrev),
1424 'look up all nodes (reverse)'),
1425 b'look up all nodes (reverse)'),
1425 (lambda: resolvenodes(allnodesrev, 2),
1426 (lambda: resolvenodes(allnodesrev, 2),
1426 'look up all nodes 2x (reverse)'),
1427 b'look up all nodes 2x (reverse)'),
1427 (lambda: getentries(allrevs),
1428 (lambda: getentries(allrevs),
1428 'retrieve all index entries (forward)'),
1429 b'retrieve all index entries (forward)'),
1429 (lambda: getentries(allrevs, 2),
1430 (lambda: getentries(allrevs, 2),
1430 'retrieve all index entries 2x (forward)'),
1431 b'retrieve all index entries 2x (forward)'),
1431 (lambda: getentries(allrevsrev),
1432 (lambda: getentries(allrevsrev),
1432 'retrieve all index entries (reverse)'),
1433 b'retrieve all index entries (reverse)'),
1433 (lambda: getentries(allrevsrev, 2),
1434 (lambda: getentries(allrevsrev, 2),
1434 'retrieve all index entries 2x (reverse)'),
1435 b'retrieve all index entries 2x (reverse)'),
1435 ]
1436 ]
1436
1437
1437 for fn, title in benches:
1438 for fn, title in benches:
@@ -1439,11 +1440,11 b' def perfrevlogindex(ui, repo, file_=None'
1439 timer(fn, title=title)
1440 timer(fn, title=title)
1440 fm.end()
1441 fm.end()
1441
1442
1442 @command('perfrevlogrevisions', revlogopts + formatteropts +
1443 @command(b'perfrevlogrevisions', revlogopts + formatteropts +
1443 [('d', 'dist', 100, 'distance between the revisions'),
1444 [(b'd', b'dist', 100, b'distance between the revisions'),
1444 ('s', 'startrev', 0, 'revision to start reading at'),
1445 (b's', b'startrev', 0, b'revision to start reading at'),
1445 ('', 'reverse', False, 'read in reverse')],
1446 (b'', b'reverse', False, b'read in reverse')],
1446 '-c|-m|FILE')
1447 b'-c|-m|FILE')
1447 def perfrevlogrevisions(ui, repo, file_=None, startrev=0, reverse=False,
1448 def perfrevlogrevisions(ui, repo, file_=None, startrev=0, reverse=False,
1448 **opts):
1449 **opts):
1449 """Benchmark reading a series of revisions from a revlog.
1450 """Benchmark reading a series of revisions from a revlog.
@@ -1453,7 +1454,7 b' def perfrevlogrevisions(ui, repo, file_='
1453
1454
1454 The start revision can be defined via ``-s/--startrev``.
1455 The start revision can be defined via ``-s/--startrev``.
1455 """
1456 """
1456 rl = cmdutil.openrevlog(repo, 'perfrevlogrevisions', file_, opts)
1457 rl = cmdutil.openrevlog(repo, b'perfrevlogrevisions', file_, opts)
1457 rllen = getlen(ui)(rl)
1458 rllen = getlen(ui)(rl)
1458
1459
1459 def d():
1460 def d():
@@ -1461,7 +1462,7 b' def perfrevlogrevisions(ui, repo, file_='
1461
1462
1462 beginrev = startrev
1463 beginrev = startrev
1463 endrev = rllen
1464 endrev = rllen
1464 dist = opts['dist']
1465 dist = opts[b'dist']
1465
1466
1466 if reverse:
1467 if reverse:
1467 beginrev, endrev = endrev, beginrev
1468 beginrev, endrev = endrev, beginrev
@@ -1476,10 +1477,10 b' def perfrevlogrevisions(ui, repo, file_='
1476 timer(d)
1477 timer(d)
1477 fm.end()
1478 fm.end()
1478
1479
1479 @command('perfrevlogchunks', revlogopts + formatteropts +
1480 @command(b'perfrevlogchunks', revlogopts + formatteropts +
1480 [('e', 'engines', '', 'compression engines to use'),
1481 [(b'e', b'engines', b'', b'compression engines to use'),
1481 ('s', 'startrev', 0, 'revision to start at')],
1482 (b's', b'startrev', 0, b'revision to start at')],
1482 '-c|-m|FILE')
1483 b'-c|-m|FILE')
1483 def perfrevlogchunks(ui, repo, file_=None, engines=None, startrev=0, **opts):
1484 def perfrevlogchunks(ui, repo, file_=None, engines=None, startrev=0, **opts):
1484 """Benchmark operations on revlog chunks.
1485 """Benchmark operations on revlog chunks.
1485
1486
@@ -1492,7 +1493,7 b' def perfrevlogchunks(ui, repo, file_=Non'
1492 For measurements of higher-level operations like resolving revisions,
1493 For measurements of higher-level operations like resolving revisions,
1493 see ``perfrevlogrevisions`` and ``perfrevlogrevision``.
1494 see ``perfrevlogrevisions`` and ``perfrevlogrevision``.
1494 """
1495 """
1495 rl = cmdutil.openrevlog(repo, 'perfrevlogchunks', file_, opts)
1496 rl = cmdutil.openrevlog(repo, b'perfrevlogchunks', file_, opts)
1496
1497
1497 # _chunkraw was renamed to _getsegmentforrevs.
1498 # _chunkraw was renamed to _getsegmentforrevs.
1498 try:
1499 try:
@@ -1502,19 +1503,19 b' def perfrevlogchunks(ui, repo, file_=Non'
1502
1503
1503 # Verify engines argument.
1504 # Verify engines argument.
1504 if engines:
1505 if engines:
1505 engines = set(e.strip() for e in engines.split(','))
1506 engines = set(e.strip() for e in engines.split(b','))
1506 for engine in engines:
1507 for engine in engines:
1507 try:
1508 try:
1508 util.compressionengines[engine]
1509 util.compressionengines[engine]
1509 except KeyError:
1510 except KeyError:
1510 raise error.Abort('unknown compression engine: %s' % engine)
1511 raise error.Abort(b'unknown compression engine: %s' % engine)
1511 else:
1512 else:
1512 engines = []
1513 engines = []
1513 for e in util.compengines:
1514 for e in util.compengines:
1514 engine = util.compengines[e]
1515 engine = util.compengines[e]
1515 try:
1516 try:
1516 if engine.available():
1517 if engine.available():
1517 engine.revlogcompressor().compress('dummy')
1518 engine.revlogcompressor().compress(b'dummy')
1518 engines.append(e)
1519 engines.append(e)
1519 except NotImplementedError:
1520 except NotImplementedError:
1520 pass
1521 pass
@@ -1574,27 +1575,27 b' def perfrevlogchunks(ui, repo, file_=Non'
1574 rl._compressor = oldcompressor
1575 rl._compressor = oldcompressor
1575
1576
1576 benches = [
1577 benches = [
1577 (lambda: doread(), 'read'),
1578 (lambda: doread(), b'read'),
1578 (lambda: doreadcachedfh(), 'read w/ reused fd'),
1579 (lambda: doreadcachedfh(), b'read w/ reused fd'),
1579 (lambda: doreadbatch(), 'read batch'),
1580 (lambda: doreadbatch(), b'read batch'),
1580 (lambda: doreadbatchcachedfh(), 'read batch w/ reused fd'),
1581 (lambda: doreadbatchcachedfh(), b'read batch w/ reused fd'),
1581 (lambda: dochunk(), 'chunk'),
1582 (lambda: dochunk(), b'chunk'),
1582 (lambda: dochunkbatch(), 'chunk batch'),
1583 (lambda: dochunkbatch(), b'chunk batch'),
1583 ]
1584 ]
1584
1585
1585 for engine in sorted(engines):
1586 for engine in sorted(engines):
1586 compressor = util.compengines[engine].revlogcompressor()
1587 compressor = util.compengines[engine].revlogcompressor()
1587 benches.append((functools.partial(docompress, compressor),
1588 benches.append((functools.partial(docompress, compressor),
1588 'compress w/ %s' % engine))
1589 b'compress w/ %s' % engine))
1589
1590
1590 for fn, title in benches:
1591 for fn, title in benches:
1591 timer, fm = gettimer(ui, opts)
1592 timer, fm = gettimer(ui, opts)
1592 timer(fn, title=title)
1593 timer(fn, title=title)
1593 fm.end()
1594 fm.end()
1594
1595
1595 @command('perfrevlogrevision', revlogopts + formatteropts +
1596 @command(b'perfrevlogrevision', revlogopts + formatteropts +
1596 [('', 'cache', False, 'use caches instead of clearing')],
1597 [(b'', b'cache', False, b'use caches instead of clearing')],
1597 '-c|-m|FILE REV')
1598 b'-c|-m|FILE REV')
1598 def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts):
1599 def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts):
1599 """Benchmark obtaining a revlog revision.
1600 """Benchmark obtaining a revlog revision.
1600
1601
@@ -1608,12 +1609,12 b' def perfrevlogrevision(ui, repo, file_, '
1608
1609
1609 This command measures the time spent in each of these phases.
1610 This command measures the time spent in each of these phases.
1610 """
1611 """
1611 if opts.get('changelog') or opts.get('manifest'):
1612 if opts.get(b'changelog') or opts.get(b'manifest'):
1612 file_, rev = None, file_
1613 file_, rev = None, file_
1613 elif rev is None:
1614 elif rev is None:
1614 raise error.CommandError('perfrevlogrevision', 'invalid arguments')
1615 raise error.CommandError(b'perfrevlogrevision', b'invalid arguments')
1615
1616
1616 r = cmdutil.openrevlog(repo, 'perfrevlogrevision', file_, opts)
1617 r = cmdutil.openrevlog(repo, b'perfrevlogrevision', file_, opts)
1617
1618
1618 # _chunkraw was renamed to _getsegmentforrevs.
1619 # _chunkraw was renamed to _getsegmentforrevs.
1619 try:
1620 try:
@@ -1688,13 +1689,13 b' def perfrevlogrevision(ui, repo, file_, '
1688 text = mdiff.patches(text, bins)
1689 text = mdiff.patches(text, bins)
1689
1690
1690 benches = [
1691 benches = [
1691 (lambda: dorevision(), 'full'),
1692 (lambda: dorevision(), b'full'),
1692 (lambda: dodeltachain(rev), 'deltachain'),
1693 (lambda: dodeltachain(rev), b'deltachain'),
1693 (lambda: doread(chain), 'read'),
1694 (lambda: doread(chain), b'read'),
1694 (lambda: dorawchunks(data, chain), 'rawchunks'),
1695 (lambda: dorawchunks(data, chain), b'rawchunks'),
1695 (lambda: dodecompress(rawchunks), 'decompress'),
1696 (lambda: dodecompress(rawchunks), b'decompress'),
1696 (lambda: dopatch(text, bins), 'patch'),
1697 (lambda: dopatch(text, bins), b'patch'),
1697 (lambda: dohash(text), 'hash'),
1698 (lambda: dohash(text), b'hash'),
1698 ]
1699 ]
1699
1700
1700 for fn, title in benches:
1701 for fn, title in benches:
@@ -1702,10 +1703,10 b' def perfrevlogrevision(ui, repo, file_, '
1702 timer(fn, title=title)
1703 timer(fn, title=title)
1703 fm.end()
1704 fm.end()
1704
1705
1705 @command('perfrevset',
1706 @command(b'perfrevset',
1706 [('C', 'clear', False, 'clear volatile cache between each call.'),
1707 [(b'C', b'clear', False, b'clear volatile cache between each call.'),
1707 ('', 'contexts', False, 'obtain changectx for each revision')]
1708 (b'', b'contexts', False, b'obtain changectx for each revision')]
1708 + formatteropts, "REVSET")
1709 + formatteropts, b"REVSET")
1709 def perfrevset(ui, repo, expr, clear=False, contexts=False, **opts):
1710 def perfrevset(ui, repo, expr, clear=False, contexts=False, **opts):
1710 """benchmark the execution time of a revset
1711 """benchmark the execution time of a revset
1711
1712
@@ -1723,9 +1724,9 b' def perfrevset(ui, repo, expr, clear=Fal'
1723 timer(d)
1724 timer(d)
1724 fm.end()
1725 fm.end()
1725
1726
1726 @command('perfvolatilesets',
1727 @command(b'perfvolatilesets',
1727 [('', 'clear-obsstore', False, 'drop obsstore between each call.'),
1728 [(b'', b'clear-obsstore', False, b'drop obsstore between each call.'),
1728 ] + formatteropts)
1729 ] + formatteropts)
1729 def perfvolatilesets(ui, repo, *names, **opts):
1730 def perfvolatilesets(ui, repo, *names, **opts):
1730 """benchmark the computation of various volatile set
1731 """benchmark the computation of various volatile set
1731
1732
@@ -1736,8 +1737,8 b' def perfvolatilesets(ui, repo, *names, *'
1736 def getobs(name):
1737 def getobs(name):
1737 def d():
1738 def d():
1738 repo.invalidatevolatilesets()
1739 repo.invalidatevolatilesets()
1739 if opts['clear_obsstore']:
1740 if opts[b'clear_obsstore']:
1740 clearfilecache(repo, 'obsstore')
1741 clearfilecache(repo, b'obsstore')
1741 obsolete.getrevs(repo, name)
1742 obsolete.getrevs(repo, name)
1742 return d
1743 return d
1743
1744
@@ -1751,8 +1752,8 b' def perfvolatilesets(ui, repo, *names, *'
1751 def getfiltered(name):
1752 def getfiltered(name):
1752 def d():
1753 def d():
1753 repo.invalidatevolatilesets()
1754 repo.invalidatevolatilesets()
1754 if opts['clear_obsstore']:
1755 if opts[b'clear_obsstore']:
1755 clearfilecache(repo, 'obsstore')
1756 clearfilecache(repo, b'obsstore')
1756 repoview.filterrevs(repo, name)
1757 repoview.filterrevs(repo, name)
1757 return d
1758 return d
1758
1759
@@ -1764,19 +1765,19 b' def perfvolatilesets(ui, repo, *names, *'
1764 timer(getfiltered(name), title=name)
1765 timer(getfiltered(name), title=name)
1765 fm.end()
1766 fm.end()
1766
1767
1767 @command('perfbranchmap',
1768 @command(b'perfbranchmap',
1768 [('f', 'full', False,
1769 [(b'f', b'full', False,
1769 'Includes build time of subset'),
1770 b'Includes build time of subset'),
1770 ('', 'clear-revbranch', False,
1771 (b'', b'clear-revbranch', False,
1771 'purge the revbranch cache between computation'),
1772 b'purge the revbranch cache between computation'),
1772 ] + formatteropts)
1773 ] + formatteropts)
1773 def perfbranchmap(ui, repo, *filternames, **opts):
1774 def perfbranchmap(ui, repo, *filternames, **opts):
1774 """benchmark the update of a branchmap
1775 """benchmark the update of a branchmap
1775
1776
1776 This benchmarks the full repo.branchmap() call with read and write disabled
1777 This benchmarks the full repo.branchmap() call with read and write disabled
1777 """
1778 """
1778 full = opts.get("full", False)
1779 full = opts.get(b"full", False)
1779 clear_revbranch = opts.get("clear_revbranch", False)
1780 clear_revbranch = opts.get(b"clear_revbranch", False)
1780 timer, fm = gettimer(ui, opts)
1781 timer, fm = gettimer(ui, opts)
1781 def getbranchmap(filtername):
1782 def getbranchmap(filtername):
1782 """generate a benchmark function for the filtername"""
1783 """generate a benchmark function for the filtername"""
@@ -1805,7 +1806,7 b' def perfbranchmap(ui, repo, *filternames'
1805 if subset not in possiblefilters:
1806 if subset not in possiblefilters:
1806 break
1807 break
1807 else:
1808 else:
1808 assert False, 'subset cycle %s!' % possiblefilters
1809 assert False, b'subset cycle %s!' % possiblefilters
1809 allfilters.append(name)
1810 allfilters.append(name)
1810 possiblefilters.remove(name)
1811 possiblefilters.remove(name)
1811
1812
@@ -1813,36 +1814,36 b' def perfbranchmap(ui, repo, *filternames'
1813 if not full:
1814 if not full:
1814 for name in allfilters:
1815 for name in allfilters:
1815 repo.filtered(name).branchmap()
1816 repo.filtered(name).branchmap()
1816 if not filternames or 'unfiltered' in filternames:
1817 if not filternames or b'unfiltered' in filternames:
1817 # add unfiltered
1818 # add unfiltered
1818 allfilters.append(None)
1819 allfilters.append(None)
1819
1820
1820 branchcacheread = safeattrsetter(branchmap, 'read')
1821 branchcacheread = safeattrsetter(branchmap, b'read')
1821 branchcachewrite = safeattrsetter(branchmap.branchcache, 'write')
1822 branchcachewrite = safeattrsetter(branchmap.branchcache, b'write')
1822 branchcacheread.set(lambda repo: None)
1823 branchcacheread.set(lambda repo: None)
1823 branchcachewrite.set(lambda bc, repo: None)
1824 branchcachewrite.set(lambda bc, repo: None)
1824 try:
1825 try:
1825 for name in allfilters:
1826 for name in allfilters:
1826 printname = name
1827 printname = name
1827 if name is None:
1828 if name is None:
1828 printname = 'unfiltered'
1829 printname = b'unfiltered'
1829 timer(getbranchmap(name), title=str(printname))
1830 timer(getbranchmap(name), title=str(printname))
1830 finally:
1831 finally:
1831 branchcacheread.restore()
1832 branchcacheread.restore()
1832 branchcachewrite.restore()
1833 branchcachewrite.restore()
1833 fm.end()
1834 fm.end()
1834
1835
1835 @command('perfbranchmapload', [
1836 @command(b'perfbranchmapload', [
1836 ('f', 'filter', '', 'Specify repoview filter'),
1837 (b'f', b'filter', b'', b'Specify repoview filter'),
1837 ('', 'list', False, 'List brachmap filter caches'),
1838 (b'', b'list', False, b'List brachmap filter caches'),
1838 ] + formatteropts)
1839 ] + formatteropts)
1839 def perfbranchmapread(ui, repo, filter='', list=False, **opts):
1840 def perfbranchmapread(ui, repo, filter=b'', list=False, **opts):
1840 """benchmark reading the branchmap"""
1841 """benchmark reading the branchmap"""
1841 if list:
1842 if list:
1842 for name, kind, st in repo.cachevfs.readdir(stat=True):
1843 for name, kind, st in repo.cachevfs.readdir(stat=True):
1843 if name.startswith('branch2'):
1844 if name.startswith(b'branch2'):
1844 filtername = name.partition('-')[2] or 'unfiltered'
1845 filtername = name.partition(b'-')[2] or b'unfiltered'
1845 ui.status('%s - %s\n'
1846 ui.status(b'%s - %s\n'
1846 % (filtername, util.bytecount(st.st_size)))
1847 % (filtername, util.bytecount(st.st_size)))
1847 return
1848 return
1848 if filter:
1849 if filter:
@@ -1851,13 +1852,13 b" def perfbranchmapread(ui, repo, filter='"
1851 repo = repo.unfiltered()
1852 repo = repo.unfiltered()
1852 # try once without timer, the filter may not be cached
1853 # try once without timer, the filter may not be cached
1853 if branchmap.read(repo) is None:
1854 if branchmap.read(repo) is None:
1854 raise error.Abort('No brachmap cached for %s repo'
1855 raise error.Abort(b'No brachmap cached for %s repo'
1855 % (filter or 'unfiltered'))
1856 % (filter or b'unfiltered'))
1856 timer, fm = gettimer(ui, opts)
1857 timer, fm = gettimer(ui, opts)
1857 timer(lambda: branchmap.read(repo) and None)
1858 timer(lambda: branchmap.read(repo) and None)
1858 fm.end()
1859 fm.end()
1859
1860
1860 @command('perfloadmarkers')
1861 @command(b'perfloadmarkers')
1861 def perfloadmarkers(ui, repo):
1862 def perfloadmarkers(ui, repo):
1862 """benchmark the time to parse the on-disk markers for a repo
1863 """benchmark the time to parse the on-disk markers for a repo
1863
1864
@@ -1867,12 +1868,12 b' def perfloadmarkers(ui, repo):'
1867 timer(lambda: len(obsolete.obsstore(svfs)))
1868 timer(lambda: len(obsolete.obsstore(svfs)))
1868 fm.end()
1869 fm.end()
1869
1870
1870 @command('perflrucachedict', formatteropts +
1871 @command(b'perflrucachedict', formatteropts +
1871 [('', 'size', 4, 'size of cache'),
1872 [(b'', b'size', 4, b'size of cache'),
1872 ('', 'gets', 10000, 'number of key lookups'),
1873 (b'', b'gets', 10000, b'number of key lookups'),
1873 ('', 'sets', 10000, 'number of key sets'),
1874 (b'', b'sets', 10000, b'number of key sets'),
1874 ('', 'mixed', 10000, 'number of mixed mode operations'),
1875 (b'', b'mixed', 10000, b'number of mixed mode operations'),
1875 ('', 'mixedgetfreq', 50, 'frequency of get vs set ops in mixed mode')],
1876 (b'', b'mixedgetfreq', 50, b'frequency of get vs set ops in mixed mode')],
1876 norepo=True)
1877 norepo=True)
1877 def perflrucache(ui, size=4, gets=10000, sets=10000, mixed=10000,
1878 def perflrucache(ui, size=4, gets=10000, sets=10000, mixed=10000,
1878 mixedgetfreq=50, **opts):
1879 mixedgetfreq=50, **opts):
@@ -1932,10 +1933,10 b' def perflrucache(ui, size=4, gets=10000,'
1932 d[v] = v
1933 d[v] = v
1933
1934
1934 benches = [
1935 benches = [
1935 (doinit, 'init'),
1936 (doinit, b'init'),
1936 (dogets, 'gets'),
1937 (dogets, b'gets'),
1937 (dosets, 'sets'),
1938 (dosets, b'sets'),
1938 (domixed, 'mixed')
1939 (domixed, b'mixed')
1939 ]
1940 ]
1940
1941
1941 for fn, title in benches:
1942 for fn, title in benches:
@@ -1943,28 +1944,28 b' def perflrucache(ui, size=4, gets=10000,'
1943 timer(fn, title=title)
1944 timer(fn, title=title)
1944 fm.end()
1945 fm.end()
1945
1946
1946 @command('perfwrite', formatteropts)
1947 @command(b'perfwrite', formatteropts)
1947 def perfwrite(ui, repo, **opts):
1948 def perfwrite(ui, repo, **opts):
1948 """microbenchmark ui.write
1949 """microbenchmark ui.write
1949 """
1950 """
1950 timer, fm = gettimer(ui, opts)
1951 timer, fm = gettimer(ui, opts)
1951 def write():
1952 def write():
1952 for i in range(100000):
1953 for i in range(100000):
1953 ui.write(('Testing write performance\n'))
1954 ui.write((b'Testing write performance\n'))
1954 timer(write)
1955 timer(write)
1955 fm.end()
1956 fm.end()
1956
1957
1957 def uisetup(ui):
1958 def uisetup(ui):
1958 if (util.safehasattr(cmdutil, 'openrevlog') and
1959 if (util.safehasattr(cmdutil, b'openrevlog') and
1959 not util.safehasattr(commands, 'debugrevlogopts')):
1960 not util.safehasattr(commands, b'debugrevlogopts')):
1960 # for "historical portability":
1961 # for "historical portability":
1961 # In this case, Mercurial should be 1.9 (or a79fea6b3e77) -
1962 # In this case, Mercurial should be 1.9 (or a79fea6b3e77) -
1962 # 3.7 (or 5606f7d0d063). Therefore, '--dir' option for
1963 # 3.7 (or 5606f7d0d063). Therefore, '--dir' option for
1963 # openrevlog() should cause failure, because it has been
1964 # openrevlog() should cause failure, because it has been
1964 # available since 3.5 (or 49c583ca48c4).
1965 # available since 3.5 (or 49c583ca48c4).
1965 def openrevlog(orig, repo, cmd, file_, opts):
1966 def openrevlog(orig, repo, cmd, file_, opts):
1966 if opts.get('dir') and not util.safehasattr(repo, 'dirlog'):
1967 if opts.get(b'dir') and not util.safehasattr(repo, b'dirlog'):
1967 raise error.Abort("This version doesn't support --dir option",
1968 raise error.Abort(b"This version doesn't support --dir option",
1968 hint="use 3.5 or later")
1969 hint=b"use 3.5 or later")
1969 return orig(repo, cmd, file_, opts)
1970 return orig(repo, cmd, file_, opts)
1970 extensions.wrapfunction(cmdutil, 'openrevlog', openrevlog)
1971 extensions.wrapfunction(cmdutil, b'openrevlog', openrevlog)
General Comments 0
You need to be logged in to leave comments. Login now