Module: InnerPerformance

Defined in:
lib/inner_performance/current_request.rb,
lib/inner_performance.rb,
lib/inner_performance/engine.rb,
lib/inner_performance/version.rb,
app/models/inner_performance/event.rb,
app/models/inner_performance/trace.rb,
lib/inner_performance/configuration.rb,
app/jobs/inner_performance/cleanup_job.rb,
app/models/inner_performance/traces/db.rb,
app/models/inner_performance/traces/view.rb,
app/jobs/inner_performance/save_event_job.rb,
app/jobs/inner_performance/application_job.rb,
app/models/inner_performance/application_record.rb,
app/helpers/inner_performance/application_helper.rb,
app/mailers/inner_performance/application_mailer.rb,
app/controllers/inner_performance/events_controller.rb,
app/controllers/inner_performance/dashboard_controller.rb,
app/controllers/inner_performance/frontends_controller.rb,
app/models/inner_performance/events/perform_active_job.rb,
app/controllers/inner_performance/application_controller.rb,
app/services/inner_performance/trace_for_insert_initializer.rb,
app/models/inner_performance/events/process_action_action_controller.rb

Overview

Defined Under Namespace

Modules: ApplicationHelper, Events, Traces Classes: ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, CleanupJob, Configuration, CurrentRequest, DashboardController, Engine, Event, EventsController, FrontendsController, SaveEventJob, Trace, TraceForInsertInitializer

Constant Summary collapse

VERSION =
"0.2.1"

Class Method Summary collapse

Class Method Details

.configurationObject



14
15
16
# File 'lib/inner_performance.rb', line 14

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



18
19
20
# File 'lib/inner_performance.rb', line 18

def configure
  yield(configuration)
end

.install!Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/inner_performance.rb', line 22

def install!
  ActiveSupport::Notifications.subscribe("render_template.action_view") do |event|
    CurrentRequest.current.trace({
      group: :view,
      name: event.name,
      payload: { identifier: event.payload[:identifier] },
      duration: event.duration.round(2),
    }) if InnerPerformance.configuration.traces_enabled
  end

  ActiveSupport::Notifications.subscribe("render_partial.action_view") do |event|
    CurrentRequest.current.trace({
      group: :view,
      name: event.name,
      payload: { identifier: event.payload[:identifier] },
      duration: event.duration.round(2),
    }) if InnerPerformance.configuration.traces_enabled
  end

  ActiveSupport::Notifications.subscribe("sql.active_record") do |event|
    unless event.payload[:name].in?(InnerPerformance.configuration.ignored_event_names)
      CurrentRequest.current.trace({
        group: :db,
        name: event.name,
        payload: { name: event.payload[:name], sql: event.payload[:sql] },
        duration: event.duration.round(2),
      }) if InnerPerformance.configuration.traces_enabled
    end
  end

  ActiveSupport::Notifications.subscribe("process_action.action_controller") do |event|
    if save_event?(event)
      InnerPerformance::SaveEventJob.perform_later(
        type: InnerPerformance::Events::ProcessActionActionController.name,
        created_at: event.payload[:started],
        event: event.name,
        name: "#{event.payload[:controller]}##{event.payload[:action]}",
        duration: event.duration,
        db_runtime: event.payload[:db_runtime],
        properties: {
          view_runtime: event.payload[:view_runtime],
        },
        traces: CurrentRequest.current.traces,
      )
    end

    CurrentRequest.cleanup
  end

  ActiveSupport::Notifications.subscribe("perform.active_job") do |event|
    if save_event?(event)
      InnerPerformance::SaveEventJob.perform_later(
        type: InnerPerformance::Events::PerformActiveJob.name,
        created_at: event.payload[:started],
        event: event.name,
        name: event.payload[:job].class.name,
        duration: event.duration,
        db_runtime: event.payload[:db_runtime],
        traces: CurrentRequest.current.traces,
      )
    end

    CurrentRequest.cleanup
  end
end

.save_event?(event) ⇒ Boolean

Check if all the ignore_rules returns false. If so, save the event.



89
90
91
92
93
# File 'lib/inner_performance.rb', line 89

def save_event?(event)
  InnerPerformance.configuration.ignore_rules.find do |rule|
    rule.call(event) == true
  end.nil?
end