module MemoryLogr

Constants

VERSION

Public Instance Methods

log_memory() { || ... } click to toggle source
# File lib/memory_logr.rb, line 4
def log_memory(&block)
  begin
    log_start
    thread = create_memory_log_thread
    yield
  ensure
    Thread.kill(thread)
    log_finish
  end
end

Private Instance Methods

create_memory_log_thread() click to toggle source
# File lib/memory_logr.rb, line 25
def create_memory_log_thread
  Thread.new do
    while true
      rss = `ps -eo pid,rss | grep #{$$} | awk '{print $2}'`.to_i
      Rails.logger.info "[MemoryLogr] Resident memory size: #{rss * 0.001}Mb"
      sleep 5
    end
  end
end
log_finish() click to toggle source
# File lib/memory_logr.rb, line 35
def log_finish
  Rails.logger.info "[MemoryLogr] Completed in: #{(Time.now - start_time) / 60} minutes"
end
log_start() click to toggle source
# File lib/memory_logr.rb, line 21
def log_start
  Rails.logger.info "[MemoryLogr] Start time: #{start_time}"
end
start_time() click to toggle source
# File lib/memory_logr.rb, line 17
def start_time
  @start_time ||= Time.now
end