Skip to content

Commit

Permalink
Fix value reported by get_maxrss on macos (#344)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
maximecb and k0kubun authored Nov 12, 2024
1 parent 1b298fa commit a892dad
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion harness/harness-common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def get_rss
end
end

def is_macos
RUBY_PLATFORM.match?(/darwin/)
end

def get_maxrss
require 'fiddle'
require 'rbconfig/sizeof'
Expand All @@ -70,7 +74,14 @@ def get_maxrss
result = getrusage.call(rusage_self, buffer)
raise unless result.zero?
maxrss_kb = buffer[offset, Fiddle::SIZEOF_LONG].unpack1('q')
1024 * maxrss_kb

# On macos, this value is already in bytes
# (and the manpage is wrong)
if is_macos
maxrss_kb
else
1024 * maxrss_kb
end
rescue LoadError
warn "Failed to get max RSS: #{$!.message}"
nil
Expand Down

0 comments on commit a892dad

Please sign in to comment.