Class: Profiler::Collectors::PerformanceCollector
- Inherits:
-
BaseCollector
- Object
- BaseCollector
- Profiler::Collectors::PerformanceCollector
- Defined in:
- lib/profiler/collectors/performance_collector.rb
Instance Attribute Summary
Attributes inherited from BaseCollector
Instance Method Summary collapse
- #collect ⇒ Object
- #icon ⇒ Object
-
#initialize(profile) ⇒ PerformanceCollector
constructor
A new instance of PerformanceCollector.
- #priority ⇒ Object
- #subscribe ⇒ Object
- #tab_config ⇒ Object
- #toolbar_summary ⇒ Object
Methods inherited from BaseCollector
descendants, #has_data?, inherited, #name, #panel_content, #render_html, #render_mode
Constructor Details
#initialize(profile) ⇒ PerformanceCollector
Returns a new instance of PerformanceCollector.
9 10 11 12 13 |
# File 'lib/profiler/collectors/performance_collector.rb', line 9 def initialize(profile) super @events = [] @subscriptions = [] end |
Instance Method Details
#collect ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/profiler/collectors/performance_collector.rb', line 80 def collect # Unsubscribe from all notifications @subscriptions.each { |sub| ActiveSupport::Notifications.unsubscribe(sub) } data = { total_events: @events.size, total_duration: @events.sum(&:duration).round(2), events: @events.map(&:to_h) } store_data(data) end |
#icon ⇒ Object
15 16 17 |
# File 'lib/profiler/collectors/performance_collector.rb', line 15 def icon "⚡" end |
#priority ⇒ Object
19 20 21 |
# File 'lib/profiler/collectors/performance_collector.rb', line 19 def priority 30 end |
#subscribe ⇒ Object
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 |
# File 'lib/profiler/collectors/performance_collector.rb', line 34 def subscribe return unless defined?(ActiveSupport::Notifications) # Subscribe to controller processing @subscriptions << ActiveSupport::Notifications.monotonic_subscribe("process_action.action_controller") do |name, started, finished, unique_id, payload| @events << Models::TimelineEvent.new( name: "Controller: #{payload[:controller]}##{payload[:action]}", started_at: started, finished_at: finished, payload: { controller: payload[:controller], action: payload[:action], format: payload[:format], method: payload[:method], path: payload[:path], status: payload[:status] } ) end # Subscribe to view rendering @subscriptions << ActiveSupport::Notifications.monotonic_subscribe("render_template.action_view") do |name, started, finished, unique_id, payload| @events << Models::TimelineEvent.new( name: "Render: #{payload[:identifier]}", started_at: started, finished_at: finished, payload: { identifier: payload[:identifier], layout: payload[:layout] } ) end # Subscribe to partial rendering @subscriptions << ActiveSupport::Notifications.monotonic_subscribe("render_partial.action_view") do |name, started, finished, unique_id, payload| @events << Models::TimelineEvent.new( name: "Partial: #{payload[:identifier]}", started_at: started, finished_at: finished, payload: { identifier: payload[:identifier] } ) end end |
#tab_config ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/profiler/collectors/performance_collector.rb', line 23 def tab_config { key: "performance", label: "Performance", icon: icon, priority: priority, enabled: true, default_active: false } end |
#toolbar_summary ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/profiler/collectors/performance_collector.rb', line 93 def duration = @events.sum(&:duration).round(2) { text: "#{@events.size} events (#{duration}ms)", color: "blue" } end |