Methods

Class/Module Index [+]

Quicksearch

Ruote::Mem

Some utilities for mem usage analysis

Public Class Methods

count() click to toggle source

Returns a Hash : classname => [ count, maxsize, totalsize, avgsize ]

The relative size of an object is computed with Marshal.dump(o).size

This uses ObjectSpace.

see www.ruby-forum.com/topic/186339 for better options.

# File lib/ruote/util/look.rb, line 66
def self.count

  uninteresting = [
    Array, String, Hash, Set, Module, Range, Float, Bignum
  ]

  h = {}

  ObjectSpace.each_object do |o|

    next if uninteresting.include?(o.class)

    stats = h[o.class.to_s] ||= [ 0, 0, 0 ]
    size = begin
      Marshal.dump(o).size
    rescue Exception => e
      1
    end

    stats[0] += 1
    stats[1] = size if size > stats[1]
    stats[2] += size
  end

  a = h.to_a
  a.each { |k, v| v << v[2] / v[0] }

  a.sort { |x, y| x.last[1] <=> y.last[1] }.reverse
end
ps() click to toggle source

Very naive : does a "ps aux | grep pid".

Returns a hash like this one :

{
  :user => "jmettraux",
  :pid => "1100",
  :cpu => "73.0",
  :mem => "0.8",
  :vsz => "2472732",
  :rss => "35308",
  :tt => "s001",
  :stat => "S+",
  :started => "8:55PM",
  :time => "0:01.05",
  :command => "ruby start.rb"
}
# File lib/ruote/util/look.rb, line 114
def self.ps

  s = `ps aux | egrep '^.+ +#{$$} '`.split(' ')
  s[10] = s[10..-1].join(' ') # the command

  h = {}

  ]
    user pid cpu mem vsz rss tt stat started time command
  ].each_with_index { |k, i| h[k.to_sym] = s[i] }

  h
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.