Class: RailsAnalyzer::Summarizer
- Inherits:
-
Base::Summarizer
- Object
- Base::Summarizer
- RailsAnalyzer::Summarizer
- Defined in:
- lib/rails_analyzer/summarizer.rb
Overview
Functions to summarize an array of requets. Can calculate request counts, duratations, mean times etc. of all the requests given.
Constant Summary
Constants inherited from Base::Summarizer
Base::Summarizer::DEFAULT_BLOCKER_DURATION
Instance Attribute Summary
Attributes inherited from Base::Summarizer
#actions, #blocker_duration, #errors, #first_request_at, #last_request_at, #methods, #request_count, #request_time_graph
Instance Method Summary collapse
-
#group(request, &block) ⇒ Object
Parse a request string into a hash containing all keys found in the string.
-
#initialize_hook(options = {}) ⇒ Object
Initializer.
Methods inherited from Base::Summarizer
#duration, #has_timestamps?, #initialize, #request_time_graph?, #sort_actions_by, #sort_blockers_by, #sort_errors_by
Constructor Details
This class inherits a constructor from Base::Summarizer
Instance Method Details
#group(request, &block) ⇒ Object
Parse a request string into a hash containing all keys found in the string. Yields the hash found to the block operator. request The request string to parse. &block Block operator
19 20 21 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 |
# File 'lib/rails_analyzer/summarizer.rb', line 19 def group(request, &block) request[:duration] ||= 0 case request[:type] when :started @first_request_at ||= request[:timestamp] # assume time-based order of file @last_request_at = request[:timestamp] # assume time-based order of file @request_time_graph[request[:timestamp][11..12].to_i] +=1 @methods[request[:method].to_sym] += 1 when :completed @request_count += 1 hash = block_given? ? yield(request) : request.hash @actions[hash] ||= {:count => 0, :total_time => 0.0, :total_db_time => 0.0, :total_rendering_time => 0.0, :min_time => request[:duration], :max_time => request[:duration] } @actions[hash][:count] += 1 @actions[hash][:total_time] += request[:duration] @actions[hash][:total_db_time] += request[:db] if request[:db] @actions[hash][:total_db_time] += request[:duration] - request[:rendering] if @calculate_database @actions[hash][:total_rendering_time] += request[:rendering] if request[:rendering] @actions[hash][:min_time] = [@actions[hash][:min_time], request[:duration]].min @actions[hash][:max_time] = [@actions[hash][:min_time], request[:duration]].max @actions[hash][:mean_time] = @actions[hash][:total_time] / @actions[hash][:count].to_f @actions[hash][:mean_db_time] = @actions[hash][:total_db_time] / @actions[hash][:count].to_f @actions[hash][:mean_rendering_time] = @actions[hash][:total_rendering_time] / @actions[hash][:count].to_f if request[:duration] > @blocker_duration @blockers[hash] ||= { :count => 0, :total_time => 0.0 } @blockers[hash][:count] += 1 @blockers[hash][:total_time] += request[:duration] end when :failed hash = request[:error] @errors[hash] ||= {:count => 0, :exception_strings => {}} @errors[hash][:count] +=1 @errors[hash][:exception_strings][request[:exception_string]] ||= 0 @errors[hash][:exception_strings][request[:exception_string]] += 1 end end |
#initialize_hook(options = {}) ⇒ Object
Initializer. Sets global variables Options
-
:calculate_databaseCalculate the database times if they are not explicitly logged.
11 12 13 |
# File 'lib/rails_analyzer/summarizer.rb', line 11 def initialize_hook( = {}) @calculate_database = [:calculate_database] end |