Class: Benchmark::Malloc::AllocationSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/benchmark/malloc/allocation_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allocations) ⇒ AllocationSet

Returns a new instance of AllocationSet.



10
11
12
# File 'lib/benchmark/malloc/allocation_set.rb', line 10

def initialize(allocations)
  @allocations = allocations
end

Instance Attribute Details

#allocationsObject (readonly)

Returns the value of attribute allocations.



8
9
10
# File 'lib/benchmark/malloc/allocation_set.rb', line 8

def allocations
  @allocations
end

Instance Method Details

#count_memoryObject



37
38
39
40
41
# File 'lib/benchmark/malloc/allocation_set.rb', line 37

def count_memory
  @allocations.
    map { |alloc| [alloc.object.class, alloc.memsize] }.
    each_with_object(Hash.new(0)) { |(name, mem), h| h[name] += mem }
end

#count_objectsObject



30
31
32
33
34
# File 'lib/benchmark/malloc/allocation_set.rb', line 30

def count_objects
  @allocations.
    map { |alloc| alloc.object.class }.
    each_with_object(Hash.new(0)) { |name, h| h[name] += 1 }
end

#each(&block) ⇒ Object



14
15
16
17
# File 'lib/benchmark/malloc/allocation_set.rb', line 14

def each(&block)
  return to_enum(:each) unless block
  @allocations.each(&block)
end

#filter(*class_names) ⇒ Object



43
44
45
46
# File 'lib/benchmark/malloc/allocation_set.rb', line 43

def filter(*class_names)
  @allocations.
    select { |alloc| class_names.include?(alloc.object.class) }
end

#total_memoryObject



25
26
27
# File 'lib/benchmark/malloc/allocation_set.rb', line 25

def total_memory
  @allocations.reduce(0) { |acc, alloc| acc + alloc.memsize }
end

#total_objectsObject



20
21
22
# File 'lib/benchmark/malloc/allocation_set.rb', line 20

def total_objects
  @allocations.size
end