Mercurial > public > mercurial-scm > hg
comparison mercurial/profiling.py @ 32788:eede022fc142
profile: drop maybeprofile
It seems sufficiently simple to use "profile(enabled=X)" to not justify having
a dedicated context manager just to read the config.
(I do not have a too strong opinion about this).
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 09 Jun 2017 12:29:29 +0100 |
parents | 0ead06d54ffe |
children | c0b2c8f25ad9 |
comparison
equal
deleted
inserted
replaced
32787:545f69cd6042 | 32788:eede022fc142 |
---|---|
217 # ui.log treats the input as a format string, | 217 # ui.log treats the input as a format string, |
218 # so we need to escape any % signs. | 218 # so we need to escape any % signs. |
219 val = val.replace('%', '%%') | 219 val = val.replace('%', '%%') |
220 self._ui.log('profile', val) | 220 self._ui.log('profile', val) |
221 self._fp.close() | 221 self._fp.close() |
222 | |
223 @contextlib.contextmanager | |
224 def maybeprofile(ui): | |
225 """Profile if enabled, else do nothing. | |
226 | |
227 This context manager can be used to optionally profile if profiling | |
228 is enabled. Otherwise, it does nothing. | |
229 | |
230 The purpose of this context manager is to make calling code simpler: | |
231 just use a single code path for calling into code you may want to profile | |
232 and this function determines whether to start profiling. | |
233 """ | |
234 with profile(ui, enabled=ui.configbool('profiling', 'enabled')) as p: | |
235 yield p |