##// END OF EJS Templates
profile: drop maybeprofile...
marmoute -
r32788:eede022f default
parent child Browse files
Show More
@@ -764,7 +764,8 b' def _dispatch(req):'
764 for ui_ in uis:
764 for ui_ in uis:
765 ui_.setconfig('profiling', 'enabled', 'true', '--profile')
765 ui_.setconfig('profiling', 'enabled', 'true', '--profile')
766
766
767 with profiling.maybeprofile(lui) as profiler:
767 profile = lui.configbool('profiling', 'enabled')
768 with profiling.profile(lui, enabled=profile) as profiler:
768 # Configure extensions in phases: uisetup, extsetup, cmdtable, and
769 # Configure extensions in phases: uisetup, extsetup, cmdtable, and
769 # reposetup. Programs like TortoiseHg will call _dispatch several
770 # reposetup. Programs like TortoiseHg will call _dispatch several
770 # times so we keep track of configured extensions in _loaded.
771 # times so we keep track of configured extensions in _loaded.
@@ -311,7 +311,8 b' class hgweb(object):'
311 should be using instances of this class as the WSGI application.
311 should be using instances of this class as the WSGI application.
312 """
312 """
313 with self._obtainrepo() as repo:
313 with self._obtainrepo() as repo:
314 with profiling.maybeprofile(repo.ui):
314 profile = repo.ui.configbool('profiling', 'enabled')
315 with profiling.profile(repo.ui, enabled=profile):
315 for r in self._runwsgi(req, repo):
316 for r in self._runwsgi(req, repo):
316 yield r
317 yield r
317
318
@@ -220,7 +220,8 b' class hgwebdir(object):'
220 return False
220 return False
221
221
222 def run_wsgi(self, req):
222 def run_wsgi(self, req):
223 with profiling.maybeprofile(self.ui):
223 profile = self.ui.configbool('profiling', 'enabled')
224 with profiling.profile(self.ui, enabled=profile):
224 for r in self._runwsgi(req):
225 for r in self._runwsgi(req):
225 yield r
226 yield r
226
227
@@ -219,17 +219,3 b' class profile(object):'
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
General Comments 0
You need to be logged in to leave comments. Login now