Skip to content

Commit

Permalink
adding execution time logging
Browse files Browse the repository at this point in the history
  • Loading branch information
miili committed Dec 6, 2024
1 parent fbe1ef5 commit d7b36f2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/qseek/distance_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pydantic import BaseModel, ByteSize, Field, PositiveFloat, PrivateAttr

from qseek.octree import get_node_coordinates
from qseek.utils import alog_call

if TYPE_CHECKING:
from qseek.models.station import Station, Stations
Expand Down Expand Up @@ -114,6 +115,7 @@ def lut_fill_level(self) -> float:
"""Return the fill level of the LUT as a float between 0.0 and 1.0."""
return len(self._node_lut) / self._node_lut.get_size()

@alog_call
async def get_weights(
self, nodes: Sequence[Node], stations: Stations
) -> np.ndarray:
Expand Down
2 changes: 2 additions & 0 deletions src/qseek/tracers/cake.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from qseek.utils import (
CACHE_DIR,
PhaseDescription,
alog_call,
datetime_now,
human_readable_bytes,
)
Expand Down Expand Up @@ -658,6 +659,7 @@ def get_travel_time_location(
raise ValueError(f"Phase {phase} is not defined.") from exc
return tree.get_travel_time(source, receiver)

@alog_call
async def get_travel_times(
self,
phase: str,
Expand Down
14 changes: 10 additions & 4 deletions src/qseek/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,11 @@ def log_call(func: Callable[P, T]) -> Callable[P, T]:
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
start = time.time()
ret = func(*args, **kwargs)
duration = timedelta(seconds=time.time() - start)
logger.debug("executed %s in %s", func.__qualname__, duration)
logger.debug(
"executed %s in %s",
func.__qualname__,
timedelta(seconds=time.time() - start),
)
return ret

return wrapper
Expand All @@ -397,8 +400,11 @@ def alog_call(func: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]]:
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
start = time.time()
ret = await func(*args, **kwargs)
duration = timedelta(seconds=time.time() - start)
logger.debug("executed %s in %s", func.__qualname__, duration)
logger.debug(
"executed %s in %s",
func.__qualname__,
timedelta(seconds=time.time() - start),
)
return ret

return wrapper
Expand Down

0 comments on commit d7b36f2

Please sign in to comment.