Skip to content

Commit a892dad

Browse files
maximecbk0kubun
andauthored
Fix value reported by get_maxrss on macos (#344)
* Fix value reported by get_maxrss on macos The value of ru_maxrss is in bytes on macos, which contradicts what the manpage says at: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getrusage.2.html Apparently, the manppage is wrong, but this information has never been corrected. I can't seem to get the Apple bug reporting software to work and so am unable to report this issue to Apple. * Update harness/harness-common.rb Co-authored-by: Takashi Kokubun <[email protected]> --------- Co-authored-by: Takashi Kokubun <[email protected]>
1 parent 1b298fa commit a892dad

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

harness/harness-common.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def get_rss
5151
end
5252
end
5353

54+
def is_macos
55+
RUBY_PLATFORM.match?(/darwin/)
56+
end
57+
5458
def get_maxrss
5559
require 'fiddle'
5660
require 'rbconfig/sizeof'
@@ -70,7 +74,14 @@ def get_maxrss
7074
result = getrusage.call(rusage_self, buffer)
7175
raise unless result.zero?
7276
maxrss_kb = buffer[offset, Fiddle::SIZEOF_LONG].unpack1('q')
73-
1024 * maxrss_kb
77+
78+
# On macos, this value is already in bytes
79+
# (and the manpage is wrong)
80+
if is_macos
81+
maxrss_kb
82+
else
83+
1024 * maxrss_kb
84+
end
7485
rescue LoadError
7586
warn "Failed to get max RSS: #{$!.message}"
7687
nil

0 commit comments

Comments
 (0)