Skip to content

Commit

Permalink
Merge pull request #192 from mdboom/fix-max-rss
Browse files Browse the repository at this point in the history
Fix the max_mem_rss measurement
  • Loading branch information
mdboom authored Jun 12, 2024
2 parents 2b9591d + 54077f9 commit 7b9a23a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyperf/_collect_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def collect_system_metadata(metadata):

def collect_memory_metadata(metadata):
if resource is not None:
metadata["mem_max_rss"] = get_max_rss()
metadata["mem_max_rss"] = get_max_rss(children=False)

# Note: Don't collect VmPeak of /proc/self/status on Linux because it is
# not accurate. See pyperf._linux_memory for more accurate memory metrics.
Expand Down
12 changes: 8 additions & 4 deletions pyperf/_process_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@
resource = None


def get_max_rss():
def get_max_rss(*, children):
if resource is not None:
usage = resource.getrusage(resource.RUSAGE_CHILDREN)
if children:
resource_type = resource.RUSAGE_CHILDREN
else:
resource_type = resource.RUSAGE_SELF
usage = resource.getrusage(resource_type)
if sys.platform == 'darwin':
return usage.ru_maxrss
return usage.ru_maxrss * 1024
Expand Down Expand Up @@ -61,7 +65,7 @@ def bench_process(loops, args, kw, profile_filename=None):
args = [args[0], "-m", "cProfile", "-o", temp_profile_filename] + args[1:]

for _ in range_it:
start_rss = get_max_rss()
start_rss = get_max_rss(children=True)

proc = subprocess.Popen(args, **kw)
with proc:
Expand All @@ -75,7 +79,7 @@ def bench_process(loops, args, kw, profile_filename=None):
os.unlink(temp_profile_filename)
sys.exit(exitcode)

rss = get_max_rss() - start_rss
rss = get_max_rss(children=True) - start_rss
max_rss = max(max_rss, rss)

if profile_filename:
Expand Down

0 comments on commit 7b9a23a

Please sign in to comment.