Skip to content

Instantly share code, notes, and snippets.

@michaeldwan
Forked from ryandotsmith/memstat.rb
Created November 6, 2011 19:26
Show Gist options
  • Select an option

  • Save michaeldwan/1343347 to your computer and use it in GitHub Desktop.

Select an option

Save michaeldwan/1343347 to your computer and use it in GitHub Desktop.

Revisions

  1. michaeldwan revised this gist Nov 6, 2011. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions memstat.rb
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,19 @@
    module Memstat
    extend self

    MAC = RUBY_PLATFORM =~ /darwin/

    def puts
    def log
    "memory=#{real_mem_size} ruby_objects=#{num_objects}"
    end

    def real_mem_size
    mb = `ps -o rsz #{$$}`.split("\n")[1].to_f / 1024.0
    mb = mb.round(-2) # nearest 100 (i.e. 60.round(-2) == 100)
    mb = (MAC ? `ps -o rss -p #{$$}` : `ps -o rsz #{$$}`).split("\n")[1].to_f / 1024.0
    mb = mb.round(1)
    "#{mb}MB"
    end

    def num_objects
    ObjectSpace.count_objects[:TOTAL]
    end

    end
    end
  2. Ryan Smith (ace hacker) created this gist Jul 29, 2011.
    18 changes: 18 additions & 0 deletions memstat.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    module Memstat
    extend self

    def puts
    "memory=#{real_mem_size} ruby_objects=#{num_objects}"
    end

    def real_mem_size
    mb = `ps -o rsz #{$$}`.split("\n")[1].to_f / 1024.0
    mb = mb.round(-2) # nearest 100 (i.e. 60.round(-2) == 100)
    "#{mb}MB"
    end

    def num_objects
    ObjectSpace.count_objects[:TOTAL]
    end

    end