Sha256: 1082d413a1b12cfa2b1809bc384f5946f6f3590e39a495217b524fb3d4953821

Contents?: true

Size: 1.1 KB

Versions: 50

Compression:

Stored size: 1.1 KB

Contents

class OSMemoryLeakTracker
  attr_reader :current_run

  def initialize
    @previous_run = @current_run = 0
  end

  def difference_between_runs(basis=@previous_run)
    @current_run - basis
  end

  def total_difference_between_runs
    difference_between_runs(@initial_count_run)
  end

  def capture_initial_memory_usage
    capture_memory_usage
    @initial_count_run = @current_run
  end

  def capture_memory_usage
    @previous_run = @current_run
    @current_run = rss_bytes
  end

  def dump_status(logger)
    delta = difference_between_runs
    logger.add(log_level(delta), sprintf("\tTotal memory usage (kb): %d (%+d)", current_run, delta))
  end

  private
  # amount of memory the current process "is using", in RAM
  # (doesn't include any swap memory that it may be using, just that in actual RAM)
  # Code loosely based on https://github.com/rdp/os/blob/master/lib/os.rb
  # returns 0 on windows
  def rss_bytes
    if ENV['OS'] == 'Windows_NT'
      0
    else
      `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
    end
  end

  def log_level(delta)
    delta > 0 ? Logger::WARN : Logger::DEBUG
  end
end

Version data entries

50 entries across 49 versions & 8 rubygems

Version Path
mfk_openapi_ruby_client-1.0.0 vendor/bundle/ruby/2.7.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.54.15 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.53.79 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.53.17 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.53.3 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.53.1 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.52.121 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.52.92 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.52.79 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.52.5 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.52.0 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.51.93 vendor/bundle/ruby/2.3.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.51.38 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.51.37 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.51.34 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.51.22 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
talon_one-2.0.0 vendor/bundle/ruby/2.7.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.49.118 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.49.98 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb