Sha256: b77f6bf7b5cf4d143ad8a6159bc69f84dd5cc7e19c6bbf1779957a4e09f5d64b

Contents?: true

Size: 804 Bytes

Versions: 6

Compression:

Stored size: 804 Bytes

Contents

module MemoryProfiler
  module Helpers
    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

    # helper to work around GC.start not freeing everything
    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

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
memory_profiler-0.9.4 lib/memory_profiler/helpers.rb
memory_profiler-0.9.3 lib/memory_profiler/helpers.rb
memory_profiler-0.9.2 lib/memory_profiler/helpers.rb
memory_profiler-0.9.1 lib/memory_profiler/helpers.rb
memory_profiler-0.9.0 lib/memory_profiler/helpers.rb
memory_profiler-0.0.4 lib/memory_profiler/helpers.rb