Class: RailsRequestStats::NotificationSubscribers
- Inherits:
-
Object
- Object
- RailsRequestStats::NotificationSubscribers
- Defined in:
- lib/rails_request_stats/notification_subscribers.rb
Constant Summary collapse
- SCHEMA_NAME =
'SCHEMA'.freeze
- CACHE_NAME =
'CACHE'.freeze
Class Attribute Summary collapse
-
.after_object_space ⇒ Object
Returns the value of attribute after_object_space.
-
.before_object_space ⇒ Object
Returns the value of attribute before_object_space.
-
.cached_query_count ⇒ Object
Returns the value of attribute cached_query_count.
-
.query_count ⇒ Object
Returns the value of attribute query_count.
Class Method Summary collapse
- .at_exit_handler ⇒ Object
- .handle_process_action_event(event) ⇒ Object
- .handle_sql_event(event) ⇒ Object
- .handle_start_processing_event(event) ⇒ Object
- .print_report(request_stats) ⇒ Object
- .reset_counts ⇒ Object
- .reset_requests ⇒ Object
Class Attribute Details
.after_object_space ⇒ Object
Returns the value of attribute after_object_space.
7 8 9 |
# File 'lib/rails_request_stats/notification_subscribers.rb', line 7 def after_object_space @after_object_space end |
.before_object_space ⇒ Object
Returns the value of attribute before_object_space.
7 8 9 |
# File 'lib/rails_request_stats/notification_subscribers.rb', line 7 def before_object_space @before_object_space end |
.cached_query_count ⇒ Object
Returns the value of attribute cached_query_count.
7 8 9 |
# File 'lib/rails_request_stats/notification_subscribers.rb', line 7 def cached_query_count @cached_query_count end |
.query_count ⇒ Object
Returns the value of attribute query_count.
7 8 9 |
# File 'lib/rails_request_stats/notification_subscribers.rb', line 7 def query_count @query_count end |
Class Method Details
.at_exit_handler ⇒ Object
43 44 45 46 47 |
# File 'lib/rails_request_stats/notification_subscribers.rb', line 43 def self.at_exit_handler @requests.each_value do |request_stats| Rails.logger.info { Report.new(request_stats).exit_report_text } end end |
.handle_process_action_event(event) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rails_request_stats/notification_subscribers.rb', line 65 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_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], event[:db_runtime]) end print_report(request_stats) end |
.handle_sql_event(event) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/rails_request_stats/notification_subscribers.rb', line 49 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) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/rails_request_stats/notification_subscribers.rb', line 56 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) ⇒ Object
81 82 83 |
# File 'lib/rails_request_stats/notification_subscribers.rb', line 81 def self.print_report(request_stats) Rails.logger.info { Report.new(request_stats).report_text } end |
.reset_counts ⇒ Object
14 15 16 17 18 19 |
# File 'lib/rails_request_stats/notification_subscribers.rb', line 14 def self.reset_counts @query_count = 0 @cached_query_count = 0 @before_object_space = {} @after_object_space = {} end |
.reset_requests ⇒ Object
22 23 24 |
# File 'lib/rails_request_stats/notification_subscribers.rb', line 22 def self.reset_requests @requests = {} end |