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
cloudsmith-api-0.49.94 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.49.21 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.49.15 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.49.13 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.49.9 vendor/bundle/ruby/2.3.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.44.4 vendor/bundle/ruby/2.3.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/ethon-0.11.0/profile/support/os_memory_leak_tracker.rb
approveapi-1.0.8 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
approveapi-1.0.5 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/profile/support/os_memory_leak_tracker.rb
ethon-0.12.0 profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.30.7 vendor/bundle/ruby/2.3.0/gems/ethon-0.11.0/profile/support/os_memory_leak_tracker.rb
color_me_shop-1.0.0 vendor/bundle/ruby/2.5.0/gems/ethon-0.11.0/profile/support/os_memory_leak_tracker.rb
cloudsmith-api-0.21.4 vendor/bundle/ruby/2.3.0/gems/ethon-0.11.0/profile/support/os_memory_leak_tracker.rb
ethon-0.11.0 profile/support/os_memory_leak_tracker.rb
ethon-0.10.1 profile/support/os_memory_leak_tracker.rb
ethon-0.10.0 profile/support/os_memory_leak_tracker.rb
ethon-0.9.1 profile/support/os_memory_leak_tracker.rb
ethon-0.9.0 profile/support/os_memory_leak_tracker.rb
ethon-0.8.1 profile/support/os_memory_leak_tracker.rb
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/ethon-0.8.0/profile/support/os_memory_leak_tracker.rb