Class: EasyProfiler::ProfileInstance

Inherits:
ProfileInstanceBase show all
Defined in:
lib/easy_prof/profile_instance.rb

Overview

Class used when profiling is disabled.

Constant Summary collapse

@@groups_stack =
[]

Instance Attribute Summary

Attributes inherited from ProfileInstanceBase

#buffer, #config, #name

Instance Method Summary collapse

Methods inherited from ProfileInstanceBase

#initialize

Constructor Details

This class inherits a constructor from EasyProfiler::ProfileInstanceBase

Instance Method Details

#debug(message) ⇒ Object

Sets a profiling checkpoint without execution time printing.

Parameters:

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



35
36
37
38
# File 'lib/easy_prof/profile_instance.rb', line 35

def debug(message)
  @progress = Time.now.to_f
  buffer_checkpoint("debug: #{message}")
end

#dump_resultsObject

Dumps results to the log.



57
58
59
60
61
62
63
64
65
66
67
# 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_groupObject



51
52
53
54
# File 'lib/easy_prof/profile_instance.rb', line 51

def end_group
  debug "Finished group"
  @@groups_stack.pop
end

#group(name) ⇒ Object

Start a group with a specified name.

Parameters:

  • name – a name of the group.



45
46
47
48
49
# 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) ⇒ Object

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

Parameters:

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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