| 37 | |
| 38 | |
| 39 | class TimeRecorder: |
| 40 | def __init__( |
| 41 | self, |
| 42 | conv_res: "ConversionResult", |
| 43 | key: str, |
| 44 | scope: ProfilingScope = ProfilingScope.PAGE, |
| 45 | ): |
| 46 | if settings.debug.profile_pipeline_timings: |
| 47 | if key not in conv_res.timings.keys(): |
| 48 | conv_res.timings[key] = ProfilingItem(scope=scope) |
| 49 | self.conv_res = conv_res |
| 50 | self.key = key |
| 51 | |
| 52 | def __enter__(self): |
| 53 | if settings.debug.profile_pipeline_timings: |
| 54 | self.start = time.monotonic() |
| 55 | self.conv_res.timings[self.key].start_timestamps.append(datetime.utcnow()) |
| 56 | return self |
| 57 | |
| 58 | def __exit__(self, *args): |
| 59 | if settings.debug.profile_pipeline_timings: |
| 60 | elapsed = time.monotonic() - self.start |
| 61 | self.conv_res.timings[self.key].times.append(elapsed) |
| 62 | self.conv_res.timings[self.key].count += 1 |
no outgoing calls
no test coverage detected