I was trying to get verbose GC information for Ruby Cucumber like I can for the JVM.
But I am not sure how to proceed.
I have seen GC.collections
, GC.dump
but I am not sure how to use them.
If any one has faced the same issue then please inform me how to get GC dump or GC statistics or verbose GC for Cucumber tests.

- 36,475
- 10
- 98
- 121

- 233
- 4
- 15
-
I've never seen `GC.collections` or `GC.dump`. Where did you see those? – Dave Schweisguth Jun 28 '14 at 13:50
1 Answers
The easiest way to watch Ruby's GC work is to use GC::Profiler
. You can use it with cucumber by putting something like this in features/support/gc.rb:
Before do
GC::Profiler.enable
GC.start
end
After do
puts GC::Profiler.report
end
If you want more detailed information, assuming you're using MRI (C Ruby), you can get garbage collection statistics from GC.stat
. You can print information from GC.stat
after every Cucumber scenario by putting something like this in features/support/gc.rb:
After do
puts "GC: total #{GC.stat[:count]}, major #{GC.stat[:minor_gc_count]}, minor #{GC.stat[:minor_gc_count]}"
end
Different versions of Ruby have different garbage collection, so GC.stat
returns different information. The GC.stat
rdoc doesn't document what each hash key means. A blog post by Sam Saffron documents GC.stat
's hash keys for Ruby 2.0 (and says that this SO answer is inaccurate). A blog post by Thorsten Ball documents GC.stat
's hash keys for Ruby 2.1.

- 1
- 1

- 36,475
- 10
- 98
- 121
-
Thanks,It is resulting data in a tabular form,but still I could not see specific documentation for different field. – BiswajitP Jun 30 '14 at 16:02
-
AFAIK Ruby doesn't document GC stats. That's why I linked to the blog posts. – Dave Schweisguth Jun 30 '14 at 16:13