Mercurial > hg
changeset 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 | 545f69cd6042 |
children | 443e8543a125 |
files | mercurial/dispatch.py mercurial/hgweb/hgweb_mod.py mercurial/hgweb/hgwebdir_mod.py mercurial/profiling.py |
diffstat | 4 files changed, 6 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dispatch.py Fri Jun 09 12:36:07 2017 +0100 +++ b/mercurial/dispatch.py Fri Jun 09 12:29:29 2017 +0100 @@ -764,7 +764,8 @@ for ui_ in uis: ui_.setconfig('profiling', 'enabled', 'true', '--profile') - with profiling.maybeprofile(lui) as profiler: + profile = lui.configbool('profiling', 'enabled') + with profiling.profile(lui, enabled=profile) as profiler: # Configure extensions in phases: uisetup, extsetup, cmdtable, and # reposetup. Programs like TortoiseHg will call _dispatch several # times so we keep track of configured extensions in _loaded.
--- a/mercurial/hgweb/hgweb_mod.py Fri Jun 09 12:36:07 2017 +0100 +++ b/mercurial/hgweb/hgweb_mod.py Fri Jun 09 12:29:29 2017 +0100 @@ -311,7 +311,8 @@ should be using instances of this class as the WSGI application. """ with self._obtainrepo() as repo: - with profiling.maybeprofile(repo.ui): + profile = repo.ui.configbool('profiling', 'enabled') + with profiling.profile(repo.ui, enabled=profile): for r in self._runwsgi(req, repo): yield r
--- a/mercurial/hgweb/hgwebdir_mod.py Fri Jun 09 12:36:07 2017 +0100 +++ b/mercurial/hgweb/hgwebdir_mod.py Fri Jun 09 12:29:29 2017 +0100 @@ -220,7 +220,8 @@ return False def run_wsgi(self, req): - with profiling.maybeprofile(self.ui): + profile = self.ui.configbool('profiling', 'enabled') + with profiling.profile(self.ui, enabled=profile): for r in self._runwsgi(req): yield r
--- a/mercurial/profiling.py Fri Jun 09 12:36:07 2017 +0100 +++ b/mercurial/profiling.py Fri Jun 09 12:29:29 2017 +0100 @@ -219,17 +219,3 @@ val = val.replace('%', '%%') self._ui.log('profile', val) self._fp.close() - -@contextlib.contextmanager -def maybeprofile(ui): - """Profile if enabled, else do nothing. - - This context manager can be used to optionally profile if profiling - is enabled. Otherwise, it does nothing. - - The purpose of this context manager is to make calling code simpler: - just use a single code path for calling into code you may want to profile - and this function determines whether to start profiling. - """ - with profile(ui, enabled=ui.configbool('profiling', 'enabled')) as p: - yield p