class EasyProfiler::Profile

Contains global profiling parameters and methods to start and stop profiling.

Public Class Methods

reset!() click to toggle source
# File lib/easy_prof/profile.rb, line 57
def self.reset!
  @@profile_results = {}
end
start(name, config = nil) click to toggle source

Starts a profiling session.

Parameters:

  • name – session name.

  • options – a Hash of options.

Possible options:

  • :enabled – value indicating whether profiling is enabled.

  • :limit – minimum time period which should be reached to print profiling log.

  • :count_ar_instances —- indicating whether profiler should log an approximate number of instantiated ActiveRecord objects.

  • :count_memory_usage —- indicating whether profiler should log an approximate amount of memory used.

  • :logger – a Logger instance.

  • :colorize_logging – indicating whether profiling log lines should be colorized.

  • :live_logging – indicating whether profiler should flush logs on every checkpoint.

Returns:

  • an instance of profiler (descendant of the EasyProfiler::ProfileInstanceBase class).

# File lib/easy_prof/profile.rb, line 24
def self.start(name, config = nil)
  if @@profile_results[name]
    raise ArgumentError.new("EasyProfiler::Profile.start() collision! '#{name}' is already started.")
  end

  config = Configuration.parse(config)

  klass = config.enabled? ? ProfileInstance : NoProfileInstance
  instance = klass.new(name, config)

  @@profile_results[name] = instance

  # Disable garbage collector to get more precise results
  GC.disable if instance.config.disable_gc?

  instance
end
stop(name) click to toggle source

Finishes a profiling session and dumps results to the log.

Parameters:

  • name – session name, used in start method.

# File lib/easy_prof/profile.rb, line 46
def self.stop(name)
  unless instance = @@profile_results.delete(name)
    raise ArgumentError.new("EasyProfiler::Profile.stop() error! '#{name}' is not started yet.")
  end

  instance.dump_results

  # Enable garbage collector which has been disabled before
  GC.enable if instance.config.disable_gc?
end