Class: RequireProf::MemorySampler

Inherits:
Object
  • Object
show all
Defined in:
lib/require_prof/memory_sampler.rb

Defined Under Namespace

Classes: JavaHeapSampler, ProcStatus, ShellPS

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
# File 'lib/require_prof/memory_sampler.rb', line 4

def self.available?
  return @available if defined?(@available)
  @available = defined?(JRuby) || platform =~ /linux|darwin|freebsd|solaris/
  unless @available
    STDERR.puts "WARNING: Unsupported platform for getting memory '#{platform}'"
  end
  @available
end

.memory_usageObject



40
41
42
# File 'lib/require_prof/memory_sampler.rb', line 40

def self.memory_usage
  sampler.memory_usage
end

.platformObject



32
33
34
35
36
37
38
# File 'lib/require_prof/memory_sampler.rb', line 32

def self.platform
  if RUBY_PLATFORM =~ /java/
    %x[uname -s].downcase
  else
    RUBY_PLATFORM.downcase
  end
end

.samplerObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/require_prof/memory_sampler.rb', line 13

def self.sampler
  return @sampler if defined?(@sampler)

  @sampler = if defined? JRuby
               JavaHeapSampler.new
             elsif platform =~ /linux/
               ProcStatus.new
               # ShellPS.new('ps -o rsz')
             elsif platform =~ /darwin9/ # 10.5
               ShellPS.new('ps -o rsz')
             elsif platform =~ /darwin1\d+/ # >= 10.6
               ShellPS.new('ps -o rss')
             elsif platform =~ /freebsd/
               ShellPS.new('ps -o rss')
             elsif platform =~ /solaris/
               ShellPS.new('/usr/bin/ps -o rss -p')
             end
end