Skip to content

Commit

Permalink
Merge pull request #2 from thomrommens/patch-1
Browse files Browse the repository at this point in the history
Remove resources lib from module import - make conditional per OS
  • Loading branch information
dormant-user authored Jul 29, 2023
2 parents ad577d4 + 664e846 commit 1f4ece2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion stressinjector/memory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import math
import resource
import time
from typing import Union

Expand Down Expand Up @@ -106,10 +105,13 @@ def _memory_util_check(cls) -> Union[int, float]:
`memory_info <https://psutil.readthedocs.io/en/latest/#psutil.Process.memory_info>`__
"""
if settings.os == operating_system.macOS:
import resource
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
if settings.os == operating_system.linux:
import resource
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss * 1e+3
if settings.os == operating_system.windows:
import psutil
return psutil.Process(settings.pid).memory_info().peak_wset

def _run(self) -> None:
Expand Down

0 comments on commit 1f4ece2

Please sign in to comment.