Class: Flows::Plugin::Profiler::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/flows/plugin/profiler/report.rb,
lib/flows/plugin/profiler/report/raw.rb,
lib/flows/plugin/profiler/report/flat.rb,
lib/flows/plugin/profiler/report/tree.rb,
lib/flows/plugin/profiler/report/events.rb,
lib/flows/plugin/profiler/report/tree/node.rb,
lib/flows/plugin/profiler/report/flat/method_report.rb,
lib/flows/plugin/profiler/report/tree/calculated_node.rb

Overview

Base class for Flows::Plugin::Profiler reports.

Since:

  • 0.4.0

Direct Known Subclasses

Raw, Tree

Defined Under Namespace

Classes: Event, FinishEvent, Flat, Raw, StartEvent, Tree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReport

Returns a new instance of Report.

Since:

  • 0.4.0



18
19
20
# File 'lib/flows/plugin/profiler/report.rb', line 18

def initialize
  @raw_data = []
end

Instance Attribute Details

#raw_dataArray<Array> (readonly)

Returns raw profiler events.

Returns:

  • (Array<Array>)

    raw profiler events

Since:

  • 0.4.0



16
17
18
# File 'lib/flows/plugin/profiler/report.rb', line 16

def raw_data
  @raw_data
end

Instance Method Details

#add(*args) ⇒ Object

Add event to profile report.

Parameters:

  • event_type (:started, :finished)

    event type

  • klass (Class)

    class where called method is placed

  • method_type (:instance, :singleton)

    method type

  • method_name (Symbol)

    name of the called method

  • data (nil, Float)

    event data, time represented as a Float microseconds value.

Since:

  • 0.4.0



30
31
32
# File 'lib/flows/plugin/profiler/report.rb', line 30

def add(*args)
  raw_data << args
end

#eventsArray<Event>

Returns array of events.

Returns:

  • (Array<Event>)

    array of events

Since:

  • 0.4.0



35
36
37
38
39
40
41
42
43
44
# File 'lib/flows/plugin/profiler/report.rb', line 35

def events
  raw_data.map do |raw_event|
    klass = case raw_event.first
            when :started then StartEvent
            when :finished then FinishEvent
            end

    klass.new(*raw_event[1..-1])
  end
end

#to_sString

This method is abstract.

Returns human-readable representation.

Returns:

  • (String)

    human-readable representation.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/flows/plugin/profiler/report.rb', line 14

class Report
  # @return [Array<Array>] raw profiler events
  attr_reader :raw_data

  def initialize
    @raw_data = []
  end

  # Add event to profile report.
  #
  # @param event_type [:started, :finished] event type
  # @param klass [Class] class where called method is placed
  # @param method_type [:instance, :singleton] method type
  # @param method_name [Symbol] name of the called method
  # @param data [nil, Float] event data, time represented as
  #   a Float microseconds value.
  def add(*args)
    raw_data << args
  end

  # @return [Array<Event>] array of events
  def events
    raw_data.map do |raw_event|
      klass = case raw_event.first
              when :started then StartEvent
              when :finished then FinishEvent
              end

      klass.new(*raw_event[1..-1])
    end
  end
end