Mercurial > hg
comparison contrib/perf.py @ 34749:acdc574cb8d7
contrib-perf: update the config registration
There are various issue with the previous code, all hidden by the try-except
clause. These are fixed now.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Fri, 13 Oct 2017 21:31:24 +0200 |
parents | e8a89ed7ce96 |
children | caf6c446cbe3 |
comparison
equal
deleted
inserted
replaced
34748:8c1d0fe1f431 | 34749:acdc574cb8d7 |
---|---|
138 commands.norepo += ' %s' % ' '.join(parsealiases(name)) | 138 commands.norepo += ' %s' % ' '.join(parsealiases(name)) |
139 return func | 139 return func |
140 return decorator | 140 return decorator |
141 | 141 |
142 try: | 142 try: |
143 import registrar | 143 import mercurial.registrar |
144 import mercurial.configitems | |
144 configtable = {} | 145 configtable = {} |
145 configitem = registrar.configitem(configtable) | 146 configitem = mercurial.registrar.configitem(configtable) |
147 configitem('perf', 'presleep', | |
148 default=mercurial.configitems.dynamicdefault, | |
149 ) | |
146 configitem('perf', 'stub', | 150 configitem('perf', 'stub', |
147 default=False, | 151 default=mercurial.configitems.dynamicdefault, |
148 ) | 152 ) |
149 except (ImportError, AttributeError): | 153 except (ImportError, AttributeError): |
150 pass | 154 pass |
151 | 155 |
152 def getlen(ui): | 156 def getlen(ui): |
153 if ui.configbool("perf", "stub"): | 157 if ui.configbool("perf", "stub", False): |
154 return lambda x: 1 | 158 return lambda x: 1 |
155 return len | 159 return len |
156 | 160 |
157 def gettimer(ui, opts=None): | 161 def gettimer(ui, opts=None): |
158 """return a timer function and formatter: (timer, formatter) | 162 """return a timer function and formatter: (timer, formatter) |
211 pass | 215 pass |
212 fm = defaultformatter(ui, 'perf', opts) | 216 fm = defaultformatter(ui, 'perf', opts) |
213 | 217 |
214 # stub function, runs code only once instead of in a loop | 218 # stub function, runs code only once instead of in a loop |
215 # experimental config: perf.stub | 219 # experimental config: perf.stub |
216 if ui.configbool("perf", "stub"): | 220 if ui.configbool("perf", "stub", False): |
217 return functools.partial(stub_timer, fm), fm | 221 return functools.partial(stub_timer, fm), fm |
218 return functools.partial(_timer, fm), fm | 222 return functools.partial(_timer, fm), fm |
219 | 223 |
220 def stub_timer(fm, func, title=None): | 224 def stub_timer(fm, func, title=None): |
221 func() | 225 func() |