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


def get_max_rss():
def get_max_rss(resource_type=None):
if resource is not None:
usage = resource.getrusage(resource.RUSAGE_CHILDREN)
if resource_type is None:
resource_type = 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.

We should not use RUSAGE_SELF on Linux, FreeBSD and other platforms?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This function is called in two contexts -- one when the benchmark runs entirely in a separate subprocess, in which case we want CHILDREN, and one when in which it runs in the same process, where we want SELF. Saying that, it would probably clearer to not have a default value for resource_type here.

usage = resource.getrusage(resource_type)
if sys.platform == 'darwin':
return usage.ru_maxrss
return usage.ru_maxrss * 1024
Expand Down