Sha256: 934575b73690974e314a0794dce6fa97d2b206a0fb0da3e68e1e64bea288c6d4

Contents?: true

Size: 1.04 KB

Versions: 11

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module DevSuite
  module Performance
    module Profiler
      class Memory < Base
        attr_reader :stats

        def initialize
          super
          @memory_usage = Data::MemoryUsage.new
          @memory_points = []
        end

        def run(&block)
          before_memory = record_memory
          result = yield
          after_memory = record_memory

          @stats = calculate_stats(before_memory, after_memory)
          result
        end

        private

        def record_memory
          current_mem = @memory_usage.current
          @memory_points << current_mem
          current_mem
        end

        def calculate_stats(before, after)
          memory_used = after - before
          average_memory = @memory_points.sum / @memory_points.size

          {
            before: before,
            after: after,
            used: memory_used,
            max: @memory_points.max,
            min: @memory_points.min,
            avg: average_memory,
          }
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dev_suite-0.2.13 lib/dev_suite/performance/profiler/memory.rb
dev_suite-0.2.12 lib/dev_suite/performance/profiler/memory.rb
dev_suite-0.2.11 lib/dev_suite/performance/profiler/memory.rb
dev_suite-0.2.10 lib/dev_suite/performance/profiler/memory.rb
dev_suite-0.2.9 lib/dev_suite/performance/profiler/memory.rb
dev_suite-0.2.8 lib/dev_suite/performance/profiler/memory.rb
dev_suite-0.2.7 lib/dev_suite/performance/profiler/memory.rb
dev_suite-0.2.6 lib/dev_suite/performance/profiler/memory.rb
dev_suite-0.2.5 lib/dev_suite/performance/profiler/memory.rb
dev_suite-0.2.4 lib/dev_suite/performance/profiler/memory.rb
dev_suite-0.2.3 lib/dev_suite/performance/profiler/memory.rb