-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actually optimise instrument list iteration (#663)
* Actually optimise instrument list iteration * timer
- Loading branch information
1 parent
2b9cf7e
commit 6171102
Showing
3 changed files
with
81 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from time import perf_counter | ||
from contextlib import contextmanager | ||
from cdci_data_analysis.flask_app.sentry import sentry | ||
|
||
@contextmanager | ||
def block_timer(logger=None, | ||
sentry=sentry, | ||
sentry_threshold=30, | ||
message_template="Execution took {:.2f} seconds"): | ||
t1 = t2 = perf_counter() | ||
try: | ||
yield lambda: t2 - t1 | ||
finally: | ||
t2 = perf_counter() | ||
message = message_template.format(t2-t1) | ||
if logger is not None: | ||
logger.info(message) | ||
if sentry is not None and t2-t1 > sentry_threshold: | ||
sentry.capture_message(message) |