Module: TWPipeline::Rusage

Defined in:
lib/twpipeline/rusage.rb,
sig/twpipeline.rbs

Constant Summary collapse

SELF =

Returns:

  • (::Integer)
0
CHILDREN =

Returns:

  • (::Integer)
-1
MAXRSS_OFFSET =

Returns:

  • (::Integer)
Fiddle::SIZEOF_LONG * 4
SCALE =

Returns:

  • (::Integer)
RUBY_PLATFORM.include?("darwin") ? 1 : 1024

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


13
# File 'lib/twpipeline/rusage.rb', line 13

def available? = !getrusage.nil?

.max_rss(who) ⇒ ::Integer

Parameters:

  • who (::Integer)

Returns:

  • (::Integer)


15
16
17
18
19
20
21
22
# File 'lib/twpipeline/rusage.rb', line 15

def max_rss(who)
  return 0 unless available?

  buffer = Fiddle::Pointer.malloc(Fiddle::SIZEOF_LONG * 32, Fiddle::RUBY_FREE)
  return 0 unless getrusage.call(who, buffer).zero?

  buffer[MAXRSS_OFFSET, Fiddle::SIZEOF_LONG].unpack1("l!") * SCALE
end

.peak::Integer

Returns:

  • (::Integer)


24
# File 'lib/twpipeline/rusage.rb', line 24

def peak = max_rss(SELF) + max_rss(CHILDREN)