contrib/perf.py
branchstable
changeset 49366 288de6f5d724
parent 48946 642e31cb55f0
child 49411 b081a5aab782
equal deleted inserted replaced
49364:e8ea403b1c46 49366:288de6f5d724
    52 #
    52 #
    53 # We don't have to do:
    53 # We don't have to do:
    54 # - make perf command for recent feature work correctly with early
    54 # - make perf command for recent feature work correctly with early
    55 #   Mercurial
    55 #   Mercurial
    56 
    56 
    57 from __future__ import absolute_import
       
    58 import contextlib
    57 import contextlib
    59 import functools
    58 import functools
    60 import gc
    59 import gc
    61 import os
    60 import os
    62 import random
    61 import random
   368     if ui.configbool(b"perf", b"stub", False):
   367     if ui.configbool(b"perf", b"stub", False):
   369         return lambda x: 1
   368         return lambda x: 1
   370     return len
   369     return len
   371 
   370 
   372 
   371 
   373 class noop(object):
   372 class noop:
   374     """dummy context manager"""
   373     """dummy context manager"""
   375 
   374 
   376     def __enter__(self):
   375     def __enter__(self):
   377         pass
   376         pass
   378 
   377 
   412         # for "historical portability":
   411         # for "historical portability":
   413         # define formatter locally, because ui.formatter has been
   412         # define formatter locally, because ui.formatter has been
   414         # available since 2.2 (or ae5f92e154d3)
   413         # available since 2.2 (or ae5f92e154d3)
   415         from mercurial import node
   414         from mercurial import node
   416 
   415 
   417         class defaultformatter(object):
   416         class defaultformatter:
   418             """Minimized composition of baseformatter and plainformatter"""
   417             """Minimized composition of baseformatter and plainformatter"""
   419 
   418 
   420             def __init__(self, ui, topic, opts):
   419             def __init__(self, ui, topic, opts):
   421                 self._ui = ui
   420                 self._ui = ui
   422                 if ui.debugflag:
   421                 if ui.debugflag:
   651             % (name, obj)
   650             % (name, obj)
   652         )
   651         )
   653 
   652 
   654     origvalue = getattr(obj, _sysstr(name))
   653     origvalue = getattr(obj, _sysstr(name))
   655 
   654 
   656     class attrutil(object):
   655     class attrutil:
   657         def set(self, newvalue):
   656         def set(self, newvalue):
   658             setattr(obj, _sysstr(name), newvalue)
   657             setattr(obj, _sysstr(name), newvalue)
   659 
   658 
   660         def restore(self):
   659         def restore(self):
   661             setattr(obj, _sysstr(name), origvalue)
   660             setattr(obj, _sysstr(name), origvalue)
  2941         displayall=displayall,
  2940         displayall=displayall,
  2942     )
  2941     )
  2943     fm.end()
  2942     fm.end()
  2944 
  2943 
  2945 
  2944 
  2946 class _faketr(object):
  2945 class _faketr:
  2947     def add(s, x, y, z=None):
  2946     def add(s, x, y, z=None):
  2948         return None
  2947         return None
  2949 
  2948 
  2950 
  2949 
  2951 def _timeonewrite(
  2950 def _timeonewrite(