Creates a context to profile, placing a timing result onto the queue when it exits.
(self, name, caller=None)
| 309 | |
| 310 | @contextmanager |
| 311 | def profile_ctx(self, name, caller=None): |
| 312 | """Creates a context to profile, placing a timing result onto the queue when it exits.""" |
| 313 | if caller is None: |
| 314 | caller = getframeinfo(stack()[2][0]) # caller of context, not something in contextlib |
| 315 | |
| 316 | start = perf_counter_ns() |
| 317 | try: |
| 318 | yield |
| 319 | finally: |
| 320 | diff = perf_counter_ns() - start |
| 321 | self._put_result(name, diff, caller.filename, caller.lineno) |
| 322 | |
| 323 | def profile_callable(self, name=None): |
| 324 | """ |