File: metric_extractor.rb

package info (click to toggle)
ruby-benchmark-memory 0.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 300 kB
  • sloc: ruby: 1,121; makefile: 7; sh: 4
file content (46 lines) | stat: -rw-r--r-- 1,316 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

require 'benchmark/memory/measurement/metric'

module Benchmark
  module Memory
    # Extracts metrics from a memory profiler result
    class MetricExtractor
      # Extracts the memory-specific metrics from a profiler result
      #
      # @param result [MemoryProfiler::Results]
      # @return [Benchmark::Memory::Measurement::Metric]
      def self.extract_memory(result)
        Measurement::Metric.new(
          :memsize,
          result.total_allocated_memsize,
          result.total_retained_memsize
        )
      end

      # Extracts the object-specific metrics from a profiler result
      #
      # @param result [MemoryProfiler::Results]
      # @return [Benchmark::Memory::Measurement::Metric]
      def self.extract_objects(result)
        Measurement::Metric.new(
          :objects,
          result.total_allocated,
          result.total_retained
        )
      end

      # Extracts the string-specific metrics from a profiler result
      #
      # @param result [MemoryProfiler::Results]
      # @return [Benchmark::Memory::Measurement::Metric]
      def self.extract_strings(result)
        Measurement::Metric.new(
          :strings,
          result.strings_allocated.size,
          result.strings_retained.size
        )
      end
    end
  end
end