Skip to content

Commit

Permalink
use pretty_bytest to print memory info
Browse files Browse the repository at this point in the history
  • Loading branch information
ungarj committed Jul 23, 2024
1 parent cce6fef commit 4fd72c3
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions mapchete/processing/profilers/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from mapchete.io import copy
from mapchete.path import MPath
from mapchete.pretty import pretty_bytes
from mapchete.types import MPathLike

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -47,9 +48,9 @@ def wrapped_f(*args, **kwargs) -> Union[Any, Tuple[Any, MeasuredMemory]]:
return (retval, result)

logger.info(
"function %s consumed a maximum of %sMB",
"function %s consumed a maximum of %s",
func,
round(tracker.max_allocated / 1024 / 1024, 2),
pretty_bytes(tracker.max_allocated),
)
return retval

Expand Down Expand Up @@ -92,9 +93,7 @@ def __init__(
logger.exception(exc)

def __str__(self): # pragma: no cover
max_allocated = f"{self.max_allocated / 1024 / 1024:.2f}MB"
total_allocated = f"{self.total_allocated / 1024 / 1024:.2f}MB"
return f"<MemoryTracker max_allocated={max_allocated}, total_allocated={total_allocated}, allocations={self.allocations}>"
return f"<MemoryTracker max_allocated={pretty_bytes(self.max_allocated)}, total_allocated={pretty_bytes(self.total_allocated)}, allocations={self.allocations}>"

def __repr__(self): # pragma: no cover
return repr(str(self))
Expand Down

0 comments on commit 4fd72c3

Please sign in to comment.