Skip to content

Commit

Permalink
[wip] Add timing output to --debug for long-running functions
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin committed Jul 7, 2023
1 parent cd000c3 commit ee1a62b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions augur/filter/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from augur.dates import get_numerical_date_from_value
from augur.dates.errors import InvalidDate
from augur.errors import AugurError
from augur.filter.debug import add_debugging
from augur.io.metadata import METADATA_DATE_COLUMN
from augur.io.sqlite3 import Sqlite3Database, sanitize_identifier
from . import constants


@add_debugging
def parse_dates():
"""Validate dates and create a date table."""
# First, determine if there is a date column.
Expand Down
20 changes: 20 additions & 0 deletions augur/filter/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from functools import wraps
import time
from typing import Callable

from . import constants


def add_debugging(func: Callable):
@wraps(func)
def wrapper(*args, **kwargs):
if constants.RUNTIME_DEBUG:
start_time = time.perf_counter()
result = func(*args, **kwargs)
end_time = time.perf_counter()
total_time = end_time - start_time
print(f'Function {func.__name__} took {total_time:.4f} seconds')
return result
else:
return func(*args, **kwargs)
return wrapper
3 changes: 3 additions & 0 deletions augur/filter/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Iterable, Sequence, Set
from tempfile import NamedTemporaryFile
from augur.errors import AugurError
from augur.filter.debug import add_debugging
from augur.index import (
index_sequences,
index_vcf,
Expand Down Expand Up @@ -79,6 +80,7 @@ def _import_tabular_file(file: TabularFile, db: Sqlite3Database, table: str):
db.insert(table, file.columns, file.rows())


@add_debugging
def import_metadata(path: str, id_columns: Sequence[str], delimiters: Iterable[str]):
# Initialize metadata object.
try:
Expand Down Expand Up @@ -246,6 +248,7 @@ def _create_output_table():
""")


@add_debugging
def _read_and_output_sequences(args):
"""Read sequences and output all that passed filtering.
"""
Expand Down
2 changes: 2 additions & 0 deletions augur/filter/subsample.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
from typing import Collection, Iterable, List, Sequence, Set
from augur.errors import AugurError
from augur.filter.debug import add_debugging
from augur.io.metadata import METADATA_DATE_COLUMN
from augur.io.print import print_err
from augur.io.sqlite3 import Sqlite3Database, sanitize_identifier
Expand Down Expand Up @@ -278,6 +279,7 @@ def _calculate_fractional_sequences_per_group(
return (lo + hi) / 2


@add_debugging
def apply_subsampling(args):
"""Apply subsampling to update the filter reason table.
Expand Down

0 comments on commit ee1a62b

Please sign in to comment.