Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add debug logging when we enter/exit Measure block (#10183)
Browse files Browse the repository at this point in the history
It can be helpful to know when trying to track down slow requests.
  • Loading branch information
erikjohnston authored Jun 16, 2021
1 parent 2c24021 commit 36c426e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/10183.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add debug logging for when we enter and exit `Measure` blocks.
5 changes: 5 additions & 0 deletions synapse/util/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,17 @@ def __enter__(self) -> "Measure":
self.start = self.clock.time()
self._logging_context.__enter__()
in_flight.register((self.name,), self._update_in_flight)

logger.debug("Entering block %s", self.name)

return self

def __exit__(self, exc_type, exc_val, exc_tb):
if self.start is None:
raise RuntimeError("Measure() block exited without being entered")

logger.debug("Exiting block %s", self.name)

duration = self.clock.time() - self.start
usage = self.get_resource_usage()

Expand Down

0 comments on commit 36c426e

Please sign in to comment.