Class: RailsPerformance::Reports::RequestsReport

Inherits:
BaseReport
  • Object
show all
Defined in:
lib/rails_performance/reports/requests_report.rb

Instance Attribute Summary

Attributes inherited from BaseReport

#db, #group, #sort, #title

Instance Method Summary collapse

Methods inherited from BaseReport

#calculate_data, #collect, #initialize, time_in_app_time_zone

Constructor Details

This class inherits a constructor from RailsPerformance::Reports::BaseReport

Instance Method Details

#dataObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rails_performance/reports/requests_report.rb', line 8

def data
  collect do |k, v|
    durations = v.collect { |e| e["duration"] }.compact
    view_runtimes = v.collect { |e| e["view_runtime"] }.compact
    db_runtimes = v.collect { |e| e["db_runtime"] }.compact
    {
      group: k,
      count: v.size,
      duration_average: durations.sum.to_f / durations.size,
      view_runtime_average: view_runtimes.sum.to_f / view_runtimes.size,
      db_runtime_average: db_runtimes.sum.to_f / db_runtimes.size,
      duration_slowest: durations.max,
      view_runtime_slowest: view_runtimes.max,
      db_runtime_slowest: db_runtimes.max,
      p50_duration: RailsPerformance::Utils.percentile(durations, 50),
      p95_duration: RailsPerformance::Utils.percentile(durations, 95),
      p99_duration: RailsPerformance::Utils.percentile(durations, 99)
    }
  end.sort_by { |e| -e[sort].to_f } # to_f because could ne NaN or nil
end

#set_defaultsObject



4
5
6
# File 'lib/rails_performance/reports/requests_report.rb', line 4

def set_defaults
  @sort ||= :count
end