Class: Upkeep::Capture::Request::ActionProfiler
- Inherits:
-
Object
- Object
- Upkeep::Capture::Request::ActionProfiler
- Defined in:
- lib/upkeep/capture/request.rb
Constant Summary collapse
- EVENT_MAP =
{ "sql.active_record" => :sql, "render_template.action_view" => :render_template, "render_partial.action_view" => :render_partial, "render_collection.action_view" => :render_collection }.freeze
Instance Attribute Summary collapse
-
#counters ⇒ Object
readonly
Returns the value of attribute counters.
-
#timings ⇒ Object
readonly
Returns the value of attribute timings.
Instance Method Summary collapse
- #capture ⇒ Object
-
#initialize ⇒ ActionProfiler
constructor
A new instance of ActionProfiler.
Constructor Details
#initialize ⇒ ActionProfiler
Returns a new instance of ActionProfiler.
111 112 113 114 115 |
# File 'lib/upkeep/capture/request.rb', line 111 def initialize @thread = Thread.current @timings = Hash.new(0.0) @counters = Hash.new(0) end |
Instance Attribute Details
#counters ⇒ Object (readonly)
Returns the value of attribute counters.
109 110 111 |
# File 'lib/upkeep/capture/request.rb', line 109 def counters @counters end |
#timings ⇒ Object (readonly)
Returns the value of attribute timings.
109 110 111 |
# File 'lib/upkeep/capture/request.rb', line 109 def timings @timings end |
Instance Method Details
#capture ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/upkeep/capture/request.rb', line 117 def capture callback = lambda do |name, started, finished, unique_id, payload| next unless Thread.current.equal?(@thread) event = ActiveSupport::Notifications::Event.new(name, started, finished, unique_id, payload) record(event) end ActiveSupport::Notifications.subscribed(callback, /\A(sql\.active_record|render_(template|partial|collection)\.action_view)\z/) do yield end ensure @timings.transform_values! { |value| value.round(3) } end |