Skip to content

Commit c960443

Browse files
authored
Fix mem_max_rss measurement on macOS (#173)
On BSD/darwin, ru_maxrss is defined in "bytes", unlike Linux where it is "kilobytes". Therefore, this code was wrongly multiplying the result by 1024. Rather than just fixing it here, it seems better to reuse the already correct `get_max_rss` function (used for calculating `command_max_rss`) elsewhere.
1 parent 3f54b5d commit c960443

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

pyperf/_collect_metadata.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
get_logical_cpu_count, format_cpu_infos,
2424
set_cpu_affinity)
2525
from pyperf._formatter import format_timedelta, format_datetime
26+
from pyperf._process_time import get_max_rss
2627
from pyperf._utils import (MS_WINDOWS,
2728
open_text, read_first_line, sysfs_path, proc_path)
2829
if MS_WINDOWS:
@@ -199,10 +200,7 @@ def collect_system_metadata(metadata):
199200

200201
def collect_memory_metadata(metadata):
201202
if resource is not None:
202-
usage = resource.getrusage(resource.RUSAGE_SELF)
203-
max_rss = usage.ru_maxrss
204-
if max_rss:
205-
metadata['mem_max_rss'] = max_rss * 1024
203+
metadata["mem_max_rss"] = get_max_rss()
206204

207205
# Note: Don't collect VmPeak of /proc/self/status on Linux because it is
208206
# not accurate. See pyperf._linux_memory for more accurate memory metrics.

0 commit comments

Comments
 (0)