Sha256: b93f647dad5e358d8b10f835407604aff47efed0848a0d5b6872c3906633a0ef

Contents?: true

Size: 746 Bytes

Versions: 2

Compression:

Stored size: 746 Bytes

Contents

module Whysoslow
  class MemoryProfile

    attr_reader :snapshots, :divider
    attr_accessor :units

    def initialize(units='MB')
      @snapshots = []
      self.units = units
    end

    def units=(value)
      @units, @divider = if value == 'KB'
        ['KB', 1]
      else # MB
        ['MB', 1000]
      end
    end

    def snapshot(label)
      Snapshot.new(label, @divider).tap{ |snap| @snapshots.push(snap) }
    end

    class Snapshot
      attr_reader :label, :memory

      def initialize(label, divider)
        @label = label
        @memory = capture_memory_usage(divider)
      end

      protected

      def capture_memory_usage(divider)
        ((`ps -o rss= -p #{$$}`.to_i) / divider.to_f)
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
whysoslow-1.0.1 lib/whysoslow/memory_profile.rb
whysoslow-1.0.0 lib/whysoslow/memory_profile.rb