Class: Benchmark::Memory::Measurement

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/benchmark/memory/measurement.rb,
lib/benchmark/memory/measurement/metric.rb

Overview

Encapsulate the combined metrics of an action.

Defined Under Namespace

Classes: Metric

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(memory:, objects:, strings:) ⇒ Measurement

Instantiate a Measurement of memory usage.

Parameters:

  • memory (Metric)

    The memory usage of an action.

  • objects (Metric)

    The object allocations of an action.

  • strings (Metric)

    The string allocations of an action.



30
31
32
33
34
35
# File 'lib/benchmark/memory/measurement.rb', line 30

def initialize(memory:, objects:, strings:)
  @memory = memory
  @objects = objects
  @strings = strings
  @metrics = [@memory, @objects, @strings]
end

Instance Attribute Details

#memoryMetric (readonly)

Returns The memory allocation metric.

Returns:

  • (Metric)

    The memory allocation metric.



38
39
40
# File 'lib/benchmark/memory/measurement.rb', line 38

def memory
  @memory
end

#metricsArray<Metric> (readonly)

Returns The metrics for the measurement.

Returns:

  • (Array<Metric>)

    The metrics for the measurement.



41
42
43
# File 'lib/benchmark/memory/measurement.rb', line 41

def metrics
  @metrics
end

#objectsMetric (readonly)

Returns The object allocation metric.

Returns:

  • (Metric)

    The object allocation metric.



44
45
46
# File 'lib/benchmark/memory/measurement.rb', line 44

def objects
  @objects
end

#stringsMetric (readonly)

Returns The string allocation metric.

Returns:

  • (Metric)

    The string allocation metric.



47
48
49
# File 'lib/benchmark/memory/measurement.rb', line 47

def strings
  @strings
end

Class Method Details

.from_result(result) ⇒ Object

Create a Measurement from a MemoryProfiler::Results object.

Parameters:

  • result (MemoryProfiler::Results)

    The results of a MemoryProfiler report.



17
18
19
20
21
22
23
# File 'lib/benchmark/memory/measurement.rb', line 17

def self.from_result(result)
  memory = MetricExtractor.extract_memory(result)
  objects = MetricExtractor.extract_objects(result)
  strings = MetricExtractor.extract_strings(result)

  new(memory: memory, objects: objects, strings: strings)
end