1

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.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
BiswajitP
  • 233
  • 4
  • 15

1 Answers1

0

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.

Community
  • 1
  • 1
Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121