Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the max_mem_rss measurement #192

Merged
merged 6 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(resource.RUSAGE_SELF)

# 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
8 changes: 4 additions & 4 deletions pyperf/_process_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
resource = None


def get_max_rss():
def get_max_rss(resource_type):
if resource is not None:
usage = resource.getrusage(resource.RUSAGE_CHILDREN)
usage = resource.getrusage(resource_type)
if sys.platform == 'darwin':
return usage.ru_maxrss
return usage.ru_maxrss * 1024
Expand Down Expand Up @@ -61,7 +61,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(resource.RUSAGE_CHILDREN)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resource.RUSAGE_CHILDREN doesn't work on Windows: resource module is not available there.

You should add an abstraction, like having a children=True parameter for get_max_rss().


proc = subprocess.Popen(args, **kw)
with proc:
Expand All @@ -75,7 +75,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(resource.RUSAGE_CHILDREN) - start_rss
max_rss = max(max_rss, rss)

if profile_filename:
Expand Down
Loading