Sha256: 409427e315354b6b1df5c6b5ce5690b0c66b545075bd1e1337add6ec8712e0cf

Contents?: true

Size: 785 Bytes

Versions: 20

Compression:

Stored size: 785 Bytes

Contents

# frozen_string_literal: true

module Pitchfork
  class MemInfo
    attr_reader :rss, :pss, :shared_memory

    def initialize(pid)
      @pid = pid
      update
    end

    def cow_efficiency(parent_meminfo)
      shared_memory.to_f / parent_meminfo.rss * 100.0
    end

    def update
      info = parse(File.read("/proc/#{@pid}/smaps_rollup"))
      @pss = info.fetch(:Pss)
      @rss = info.fetch(:Rss)
      @shared_memory = info.fetch(:Shared_Clean) + info.fetch(:Shared_Dirty)
      self
    end

    private

    def parse(rollup)
      fields = {}
      rollup.each_line do |line|
        if (matchdata = line.match(/(?<field>\w+)\:\s+(?<size>\d+) kB$/))
          fields[matchdata[:field].to_sym] = matchdata[:size].to_i
        end
      end
      fields
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
pitchfork-0.16.0 lib/pitchfork/mem_info.rb
pitchfork-0.15.0 lib/pitchfork/mem_info.rb
pitchfork-0.14.0 lib/pitchfork/mem_info.rb
pitchfork-0.13.0 lib/pitchfork/mem_info.rb
pitchfork-0.12.0 lib/pitchfork/mem_info.rb
pitchfork-0.11.1 lib/pitchfork/mem_info.rb
pitchfork-0.11.0 lib/pitchfork/mem_info.rb
pitchfork-0.10.0 lib/pitchfork/mem_info.rb
pitchfork-0.9.0 lib/pitchfork/mem_info.rb
pitchfork-0.8.0 lib/pitchfork/mem_info.rb
pitchfork-0.7.0 lib/pitchfork/mem_info.rb
pitchfork-0.6.0 lib/pitchfork/mem_info.rb
pitchfork-0.5.0 lib/pitchfork/mem_info.rb
pitchfork-0.4.1 lib/pitchfork/mem_info.rb
pitchfork-0.4.0 lib/pitchfork/mem_info.rb
pitchfork-0.3.0 lib/pitchfork/mem_info.rb
pitchfork-0.2.0 lib/pitchfork/mem_info.rb
pitchfork-0.1.2 lib/pitchfork/mem_info.rb
pitchfork-0.1.1 lib/pitchfork/mem_info.rb
pitchfork-0.1.0 lib/pitchfork/mem_info.rb