equal
deleted
inserted
replaced
145 """Start profiling. |
145 """Start profiling. |
146 |
146 |
147 Profiling is active when the context manager is active. When the context |
147 Profiling is active when the context manager is active. When the context |
148 manager exits, profiling results will be written to the configured output. |
148 manager exits, profiling results will be written to the configured output. |
149 """ |
149 """ |
150 def __init__(self, ui): |
150 def __init__(self, ui, enabled=True): |
151 self._ui = ui |
151 self._ui = ui |
152 self._output = None |
152 self._output = None |
153 self._fp = None |
153 self._fp = None |
154 self._profiler = None |
154 self._profiler = None |
|
155 self._enabled = enabled |
155 self._entered = False |
156 self._entered = False |
156 self._started = False |
157 self._started = False |
157 |
158 |
158 def __enter__(self): |
159 def __enter__(self): |
159 self._entered = True |
160 self._entered = True |
160 self.start() |
161 if self._enabled: |
|
162 self.start() |
161 |
163 |
162 def start(self): |
164 def start(self): |
163 """Start profiling. |
165 """Start profiling. |
164 |
166 |
165 The profiling will stop at the context exit. |
167 The profiling will stop at the context exit. |
226 |
228 |
227 The purpose of this context manager is to make calling code simpler: |
229 The purpose of this context manager is to make calling code simpler: |
228 just use a single code path for calling into code you may want to profile |
230 just use a single code path for calling into code you may want to profile |
229 and this function determines whether to start profiling. |
231 and this function determines whether to start profiling. |
230 """ |
232 """ |
231 if ui.configbool('profiling', 'enabled'): |
233 with profile(ui, enabled=ui.configbool('profiling', 'enabled')): |
232 with profile(ui): |
234 yield |
233 yield |
|
234 else: |
|
235 yield |
|