Class: MethodProfiler::Profiler

Inherits:
Object
  • Object
show all
Defined in:
lib/method_profiler/profiler.rb

Overview

Observes an object, keeping track of all its method calls and the wall clock time spent executing them.

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ Profiler

Initializes a new MethodProfiler::Profiler. Wraps all methods in the object and its singleton class with profiling code.

Parameters:

  • obj (Object)

    The object to observe.



15
16
17
18
19
20
# File 'lib/method_profiler/profiler.rb', line 15

def initialize(obj)
  @obj = obj
  @data = Hash.new { |h, k| h[k] = [] }

  wrap_methods_with_profiling
end

Instance Method Details

#reportReport

Generates a report object with all the data collected so far bay the profiler. This report can be displayed in various ways. See Report.

Returns:

  • (Report)

    A new report with all the data the profiler has collected.



27
28
29
# File 'lib/method_profiler/profiler.rb', line 27

def report
  Report.new(final_data, @obj.name)
end