Class: Benchmark::Malloc::AllocationSet
- Inherits:
-
Object
- Object
- Benchmark::Malloc::AllocationSet
- Includes:
- Enumerable
- Defined in:
- lib/benchmark/malloc/allocation_set.rb
Instance Attribute Summary collapse
-
#allocations ⇒ Object
readonly
Returns the value of attribute allocations.
Instance Method Summary collapse
- #count_memory ⇒ Object
- #count_objects ⇒ Object
- #each(&block) ⇒ Object
- #filter(*class_names) ⇒ Object
-
#initialize(allocations) ⇒ AllocationSet
constructor
A new instance of AllocationSet.
- #total_memory ⇒ Object
- #total_objects ⇒ Object
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
#allocations ⇒ Object (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_memory ⇒ Object
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_objects ⇒ Object
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_memory ⇒ Object
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_objects ⇒ Object
20 21 22 |
# File 'lib/benchmark/malloc/allocation_set.rb', line 20 def total_objects @allocations.size end |