Class: MerbAnalyzer::Summarizer

Inherits:
Base::Summarizer show all
Defined in:
lib/merb_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

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



17
18
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
# File 'lib/merb_analyzer/summarizer.rb', line 17

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
      
    when :params
      params_hash = {}
      request[:raw_hash].split(',').collect{|x| x.split('=>')}.each do |k,v|
        key = k.gsub('"', '').gsub(' ', '').to_sym
        value = v.gsub('"', '')
        request.store(key, value)
      end
      
      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
      request[:method] = 'GET' unless request[:method]
      @methods[request[:method].upcase.to_sym] += 1

      @hash_cache = hash
    when :completed
      @request_count += 1 
      
      @actions[@hash_cache][:total_time] += request[:dispatch_time]
      @actions[@hash_cache][:mean_time] = @actions[@hash_cache][:total_time] / @actions[@hash_cache][:count].to_f          
      @actions[@hash_cache][:min_time] = [@actions[@hash_cache][:min_time], request[:dispatch_time]].min
      @actions[@hash_cache][:max_time] = [@actions[@hash_cache][:min_time], request[:dispatch_time]].max
      
      @actions[@hash_cache][:total_db_time] = 0
      @actions[@hash_cache][:mean_db_time] = 0
      @actions[@hash_cache][:mean_rendering_time] = 0
      
    when :failed

  end
end

#initialize_hook(options = {}) ⇒ Object

Initializer. Sets global variables



9
10
11
# File 'lib/merb_analyzer/summarizer.rb', line 9

def initialize_hook(options = {})
  @hash_cache = nil
end