Module: MemoryProfiler::Helpers

Defined in:
lib/memory_profiler/helpers.rb

Class Method Summary collapse

Class Method Details

.count_objectsObject



30
31
32
33
34
35
# File 'lib/memory_profiler/helpers.rb', line 30

def self.count_objects
  i = 0
  ObjectSpace.each_object do |obj|
    i += 1
  end
end

.decreased_count(old) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/memory_profiler/helpers.rb', line 21

def self.decreased_count(old)
  count = count_objects
  if !old || count < old
    count
  else
    nil
  end
end

.full_gcObject

helper to work around GC.start not freeing everything



16
17
18
19
# File 'lib/memory_profiler/helpers.rb', line 16

def self.full_gc
  # TODO: discuss with @tmm1 and @ko1 if the while loop is needed
  GC.start(full_mark: true) while new_count = decreased_count(new_count)
end

.guess_gem(path) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/memory_profiler/helpers.rb', line 3

def self.guess_gem(path)
  if /(\/gems\/.*)*\/gems\/(?<gem>[^\/]+)/ =~ path
    gem
  elsif /\/rubygems\// =~ path
    "rubygems"
  elsif /(?<app>[^\/]+\/(bin|app|lib))/ =~ path
    app
  else
    "other"
  end
end