class RailsRequestStats::NotificationSubscribers
Constants
- CACHE_NAME
- SCHEMA_NAME
Attributes
after_object_space[RW]
before_object_space[RW]
cache_hit_count[RW]
cache_read_count[RW]
cached_query_count[RW]
query_count[RW]
requests[RW]
Public Class Methods
at_exit_handler()
click to toggle source
# File lib/rails_request_stats/notification_subscribers.rb, line 55 def self.at_exit_handler @requests.each_value do |request_stats| Rails.logger.info { Report.new(request_stats).exit_report_text } end end
handle_cache_fetch_hit_event(event)
click to toggle source
# File lib/rails_request_stats/notification_subscribers.rb, line 66 def self.handle_cache_fetch_hit_event(event) @cache_hit_count += 1 end
handle_cache_read_event(event)
click to toggle source
# File lib/rails_request_stats/notification_subscribers.rb, line 61 def self.handle_cache_read_event(event) @cache_read_count += 1 @cache_hit_count += 1 if event.fetch(:hit, false) end
handle_process_action_event(event)
click to toggle source
# File lib/rails_request_stats/notification_subscribers.rb, line 86 def self.handle_process_action_event(event) @after_object_space = ObjectSpace.count_objects(@after_object_space) GC.enable request_key = { action: event[:action], format: event[:format], method: event[:method], path: event[:path] } request_stats = @requests[request_key] || RequestStats.new(request_key) @requests[request_key] = request_stats.tap do |stats| stats.add_cache_stats(@cache_read_count, @cache_hit_count) stats.add_database_query_stats(@query_count, @cached_query_count) stats.add_object_space_stats(@before_object_space, @after_object_space) stats.add_runtime_stats(event[:view_runtime] || 0, event[:db_runtime] || 0) end print_report(request_stats) end
handle_sql_event(event)
click to toggle source
# File lib/rails_request_stats/notification_subscribers.rb, line 70 def self.handle_sql_event(event) return if event[:name] == SCHEMA_NAME @cached_query_count += 1 if event[:name] == CACHE_NAME @query_count += 1 end
handle_start_processing_event(event)
click to toggle source
# File lib/rails_request_stats/notification_subscribers.rb, line 77 def self.handle_start_processing_event(event) reset_counts GC.start GC.disable @before_object_space = ObjectSpace.count_objects(@before_object_space) end
print_report(request_stats)
click to toggle source
# File lib/rails_request_stats/notification_subscribers.rb, line 103 def self.print_report(request_stats) Rails.logger.info { Report.new(request_stats).report_text } end
reset_counts()
click to toggle source
# File lib/rails_request_stats/notification_subscribers.rb, line 16 def self.reset_counts @query_count = 0 @cached_query_count = 0 @cache_read_count = 0 @cache_hit_count = 0 @before_object_space = {} @after_object_space = {} end
reset_requests()
click to toggle source
# File lib/rails_request_stats/notification_subscribers.rb, line 26 def self.reset_requests @requests = {} end