Skip to content

Commit

Permalink
Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed Jun 1, 2016
1 parent 1304310 commit 0dd5245
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions lib/get_process_mem.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
require 'pathname'
require 'bigdecimal'

if Gem.win_platform?
require 'rubygems'
require 'sys/proctable'
include Sys
end


# Cribbed from Unicorn Worker Killer, thanks!
class GetProcessMem
KB_TO_BYTE = 1024 # 2**10 = 1024
Expand All @@ -17,6 +10,19 @@ class GetProcessMem
ROUND_UP = BigDecimal.new("0.5")
attr_reader :pid

RUNS_ON_WINDOWS = Gem.win_platform?

if RUNS_ON_WINDOWS
begin
require 'sys/proctable'
rescue LoadError => e
message = "Please add `sys-proctable` to your Gemfile for windows machines\n"
message << e.message
raise e, message
end
include Sys
end

def initialize(pid = Process.pid)
@status_file = Pathname.new "/proc/#{pid}/status"
@process_file = Pathname.new "/proc/#{pid}/smaps"
Expand Down Expand Up @@ -80,13 +86,11 @@ def linux_memory(file = @process_file)
# Pull memory from `ps` command, takes more resources and can freeze
# in low memory situations
def ps_memory
case
when /mswin|mingw/ =~ RUBY_PLATFORM
size = ProcTable.ps(pid).working_set_size;
BigDecimal.new(size)
else
KB_TO_BYTE * BigDecimal.new(`ps -o rss= -p #{pid}`)
if RUNS_ON_WINDOWS
size = ProcTable.ps(pid).working_set_size
BigDecimal.new(size)
else
KB_TO_BYTE * BigDecimal.new(`ps -o rss= -p #{pid}`)
end
end

end

0 comments on commit 0dd5245

Please sign in to comment.