Skip to content

Instantly share code, notes, and snippets.

@cbliard
Last active August 29, 2015 14:01
Show Gist options
  • Save cbliard/3b79e91c610b6f3e8bd0 to your computer and use it in GitHub Desktop.
Save cbliard/3b79e91c610b6f3e8bd0 to your computer and use it in GitHub Desktop.
Diff two GC.stat values
# quick'n'dirty
def diff_gc(first_gc, second_gc)
  # add custom field
  [first_gc, second_gc].each { |gc| gc[:allocated] = gc[:total_allocated_object] - gc[:total_freed_object] }
  # get data
  first_gc.keys.map do |key|
    before = first_gc[key]
    after = second_gc[key]
    diff = after - before
    [sprintf("%35s", key), sprintf("%+10i", diff), sprintf("%15i", before), sprintf("%15i", after)].join(" ")
  end.each do |line|
    puts line
  end
  nil
end

usage:

a = {}
b = {}
GC.stat(a)
# coding stuff
GC.stat(b)

diff_gc(a, b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment