class EasyProfiler::ProfileInstanceBase

Base class for profilers.

Attributes

buffer[R]
config[R]
name[R]

Public Class Methods

new(name, config = nil) click to toggle source

Initializes a new instance of ProfileInstanceBase class.

Parameters:

  • name – session name.

  • options – a Hash of options (see EasyProfiler::Profile.start for details).

# File lib/easy_prof/profile_instance_base.rb, line 13
def initialize(name, config = nil)
  @name = name
  @config = Configuration.parse(config)

  @start = @progress = Time.now.to_f

  # Initial number of ActiveRecord::Base objects
  if @config.count_ar_instances
    @start_ar_instances = @current_ar_instances = active_record_instances_count
  end

  # Initial amount of memory used
  if @config.count_memory_usage
    @start_memory_usage = @current_memory_usage = process_memory_usage
  end

  # A buffer where all log messeges will be stored till the
  # end of the profiling block. We need this because not every
  # profiling log will be printed (see EasyProf::Configuration.print_limit).
  @buffer = []
end

Public Instance Methods

debug(message) click to toggle source

Sets a profiling checkpoint without execution time printing.

Parameters:

  • message – a message to associate with a check point.

# File lib/easy_prof/profile_instance_base.rb, line 48
def debug(message)
end
dump_results() click to toggle source

Dumps results to the log.

# File lib/easy_prof/profile_instance_base.rb, line 64
def dump_results
end
end_group() click to toggle source
# File lib/easy_prof/profile_instance_base.rb, line 60
def end_group
end
group(name, options = {}, &block) click to toggle source

Start a group with a specified name.

Parameters:

  • name – a name of the group.

# File lib/easy_prof/profile_instance_base.rb, line 56
def group(name, options = {}, &block)
  self
end
progress(message) click to toggle source

Sets a profiling checkpoint (block execution time will be printed).

Parameters:

  • message – a message to associate with a check point.

# File lib/easy_prof/profile_instance_base.rb, line 40
def progress(message)
end

Protected Instance Methods

active_record_instances_count() click to toggle source

Returns a number of ActiveRecord instances in the Object Space.

# File lib/easy_prof/profile_instance_base.rb, line 71
def active_record_instances_count
  count = 0
  ObjectSpace.each_object(::ActiveRecord::Base) { count += 1 }
  count
end
format_memory_size(number) click to toggle source

Formats an amount of memory to print.

# File lib/easy_prof/profile_instance_base.rb, line 85
def format_memory_size(number)
  if number > 10 ** 9
    number = number.to_f / (10 ** 9)
    suffix = 'G'
  elsif number > 10 ** 6
    number = number.to_f / (10 ** 6)
    suffix = 'M'
  elsif number > 10 ** 3
    number = number.to_f / (10 ** 3)
    suffix = 'K'
  else
    suffix = 'B'
  end
  "%.2f#{suffix}" % number
end
process_memory_usage() click to toggle source

Returns an amount of memory used by current Ruby process.

# File lib/easy_prof/profile_instance_base.rb, line 79
def process_memory_usage
  `ps -o rss= -p #{$$}`.to_i
end