lib/rails_analyzer/summarizer.rb in wvanbergen-request-log-analyzer-0.2.2 vs lib/rails_analyzer/summarizer.rb in wvanbergen-request-log-analyzer-0.3.0

- old
+ new

@@ -20,30 +20,38 @@ request[:duration] ||= 0 case request[:type] when :started if request[:timestamp] - @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 + if @first_request_at.nil? || hamburger_compare_string_dates(request[:timestamp], @first_request_at) == -1 + @first_request_at = request[:timestamp] + end + + if @last_request_at.nil? || hamburger_compare_string_dates(request[:timestamp], @last_request_at) == 1 + @last_request_at = request[:timestamp] + end + + @request_time_graph[request[:timestamp][11..12].to_i] +=1 end + if request[:method] @methods[request[:method].to_sym] ||= 0 @methods[request[:method].to_sym] += 1 else @methods[:unknown] += 1 end + 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_db_time] += request[:duration] - request[:rendering] if @calculate_database && request[:duration] && request[:rendering] @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