Show More
@@ -764,7 +764,8 b' def _dispatch(req):' | |||
|
764 | 764 | for ui_ in uis: |
|
765 | 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 | 769 | # Configure extensions in phases: uisetup, extsetup, cmdtable, and |
|
769 | 770 | # reposetup. Programs like TortoiseHg will call _dispatch several |
|
770 | 771 | # times so we keep track of configured extensions in _loaded. |
@@ -311,7 +311,8 b' class hgweb(object):' | |||
|
311 | 311 | should be using instances of this class as the WSGI application. |
|
312 | 312 | """ |
|
313 | 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 | 316 | for r in self._runwsgi(req, repo): |
|
316 | 317 | yield r |
|
317 | 318 |
@@ -220,7 +220,8 b' class hgwebdir(object):' | |||
|
220 | 220 | return False |
|
221 | 221 | |
|
222 | 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 | 225 | for r in self._runwsgi(req): |
|
225 | 226 | yield r |
|
226 | 227 |
@@ -219,17 +219,3 b' class profile(object):' | |||
|
219 | 219 | val = val.replace('%', '%%') |
|
220 | 220 | self._ui.log('profile', val) |
|
221 | 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