contrib/perf.py
changeset 30149 d8a2c536dd96
parent 30148 04f2b980df3c
child 30150 c0410814002f
equal deleted inserted replaced
30148:04f2b980df3c 30149:d8a2c536dd96
   129     This function exists to gather the creation of formatter in a single
   129     This function exists to gather the creation of formatter in a single
   130     place instead of duplicating it in all performance commands."""
   130     place instead of duplicating it in all performance commands."""
   131 
   131 
   132     # enforce an idle period before execution to counteract power management
   132     # enforce an idle period before execution to counteract power management
   133     # experimental config: perf.presleep
   133     # experimental config: perf.presleep
   134     time.sleep(ui.configint("perf", "presleep", 1))
   134     time.sleep(getint(ui, "perf", "presleep", 1))
   135 
   135 
   136     if opts is None:
   136     if opts is None:
   137         opts = {}
   137         opts = {}
   138     # redirect all to stderr
   138     # redirect all to stderr
   139     ui = ui.copy()
   139     ui = ui.copy()
   220     fm.write('count',  ' (best of %d)', count)
   220     fm.write('count',  ' (best of %d)', count)
   221     fm.plain('\n')
   221     fm.plain('\n')
   222 
   222 
   223 # utilities for historical portability
   223 # utilities for historical portability
   224 
   224 
       
   225 def getint(ui, section, name, default):
       
   226     # for "historical portability":
       
   227     # ui.configint has been available since 1.9 (or fa2b596db182)
       
   228     v = ui.config(section, name, None)
       
   229     if v is None:
       
   230         return default
       
   231     try:
       
   232         return int(v)
       
   233     except ValueError:
       
   234         raise error.ConfigError(("%s.%s is not an integer ('%s')")
       
   235                                 % (section, name, v))
       
   236 
   225 def safeattrsetter(obj, name, ignoremissing=False):
   237 def safeattrsetter(obj, name, ignoremissing=False):
   226     """Ensure that 'obj' has 'name' attribute before subsequent setattr
   238     """Ensure that 'obj' has 'name' attribute before subsequent setattr
   227 
   239 
   228     This function is aborted, if 'obj' doesn't have 'name' attribute
   240     This function is aborted, if 'obj' doesn't have 'name' attribute
   229     at runtime. This avoids overlooking removal of an attribute, which
   241     at runtime. This avoids overlooking removal of an attribute, which
   567 @command('perfparents', formatteropts)
   579 @command('perfparents', formatteropts)
   568 def perfparents(ui, repo, **opts):
   580 def perfparents(ui, repo, **opts):
   569     timer, fm = gettimer(ui, opts)
   581     timer, fm = gettimer(ui, opts)
   570     # control the number of commits perfparents iterates over
   582     # control the number of commits perfparents iterates over
   571     # experimental config: perf.parentscount
   583     # experimental config: perf.parentscount
   572     count = ui.configint("perf", "parentscount", 1000)
   584     count = getint(ui, "perf", "parentscount", 1000)
   573     if len(repo.changelog) < count:
   585     if len(repo.changelog) < count:
   574         raise error.Abort("repo needs %d commits for this test" % count)
   586         raise error.Abort("repo needs %d commits for this test" % count)
   575     repo = repo.unfiltered()
   587     repo = repo.unfiltered()
   576     nl = [repo.changelog.node(i) for i in xrange(count)]
   588     nl = [repo.changelog.node(i) for i in xrange(count)]
   577     def d():
   589     def d():