class EasyProfiler::ProfileInstance

Class used when profiling is disabled.

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.rb, line 35
def debug(message)
  @progress = Time.now.to_f
  buffer_checkpoint("debug: #{message}")
end
dump_results() click to toggle source

Dumps results to the log.

# File lib/easy_prof/profile_instance.rb, line 57
def dump_results
  self.end_group while @@groups_stack.any?

  progress('END')

  t = total
  log_footer(t)
  if false === config.print_limit || t > config.print_limit.to_f
    @buffer.each { |message| log_line(*message) }
  end
end
end_group() click to toggle source
# File lib/easy_prof/profile_instance.rb, line 51
def end_group
  debug "Finished group"
  @@groups_stack.pop
end
group(name) click to toggle source

Start a group with a specified name.

Parameters:

  • name – a name of the group.

# File lib/easy_prof/profile_instance.rb, line 45
def group(name)
  progress "Before group '#{name}'"
  debug 'Started group'
  @@groups_stack << name
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.rb, line 10
def progress(message)
  progress = (now = Time.now.to_f) - @progress
  @progress = now

  ar_instances_count = if config.count_ar_instances
    ar_instances_delta = (ar_instances = active_record_instances_count) - @current_ar_instances
    @current_ar_instances = ar_instances
    ", #{ar_instances_delta} AR objects"
  end

  memory_usage_value = if config.count_memory_usage
    memory_usage_delta = (memory_usage = process_memory_usage) - @current_memory_usage
    @current_memory_usage = memory_usage
    ", #{format_memory_size(total_memory_usage)}"
  end

  buffer_checkpoint("progress: %0.4f s#{ar_instances_count}#{memory_usage_value} [#{message}]" % progress)

  return progress
end

Private Instance Methods

buffer_checkpoint(message) click to toggle source

Buffers a profiling checkpoint.

# File lib/easy_prof/profile_instance.rb, line 87
def buffer_checkpoint(message)
  log_header unless @header_printed

  group_name = @@groups_stack.last
  name = group_name ? "#{@name}: #{group_name}" : @name

  if config.live_logging
    log_line(message, name)
  else
    @buffer << [message, name]
  end
end
log_header() click to toggle source

Write a header to the log.

# File lib/easy_prof/profile_instance.rb, line 101
def log_header
  @header_printed = true
  buffer_checkpoint("Benchmark results:")
end
log_line(line, name = nil) click to toggle source

Write a log line.

# File lib/easy_prof/profile_instance.rb, line 120
def log_line(line, name = nil)
  name ||= @name

  if config.colorize_logging
    @@row_even, message_color = if @@row_even
      [false, '4;32;1']
    else
      [true, '4;33;1']
    end

    config.logger.info("[\e[#{message_color}m%s\e[0m] %s" % [name, line])
  else
    config.logger.info("[%s] %s" % [name, line])
  end
end
total() click to toggle source

Gets a total profiling time.

# File lib/easy_prof/profile_instance.rb, line 72
def total
  Time.now.to_f - @start
end
total_ar_instances() click to toggle source

Gets a number of total AR objects instantiated number.

# File lib/easy_prof/profile_instance.rb, line 77
def total_ar_instances
  active_record_instances_count - @start_ar_instances
end
total_memory_usage() click to toggle source

Gets a total amount of memory used.

# File lib/easy_prof/profile_instance.rb, line 82
def total_memory_usage
  process_memory_usage - @start_memory_usage
end