Module: ActiveProfiling::GCStatistics

Extended by:
ActiveSupport::Concern
Included in:
ActiveProfiling
Defined in:
lib/active-profiling/gc_statistics.rb

Instance Method Summary collapse

Instance Method Details

#gc_statistics(*args, &block) ⇒ Object

Profiles a block, capturing information on the garbage collector. The return value is an Array containing the result of the yielded block and a String with a report on the profiling results.

Options:

  • :disable_gc - disables garbage collection for the duration of the block and then renables it immediately afterwards. This allows you to control when GC is run and see the results.

  • :title - a title to use for logging.

More options for this method can be found in the default settings, located in ActiveProfiling::Railtie::DEFAULT_GC_STATISTICS_OPTIONS.

This method only works with versions of Ruby that implement GC::Profiler or that have been patched to implement some additional garbage collection statistics. In older versions, such as version 1.8.7, you can either use Ruby Enterprise Edition or patch your build with the GC statistics patch found here:

blog.pluron.com/2008/02/memory-profilin.html



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/active-profiling/gc_statistics.rb', line 85

def gc_statistics(*args, &block)
  options = Rails.application.config.active_profiling.gc_statistics.merge(args.extract_options!)

  result, gc_report = gc_statistics_report(options, &block)

  ActiveSupport::Notifications.instrument('gc_statistics.active_profiling', {
    report: gc_report,
    title: options[:title] || args.first
  })

  result
end