Sha256: 9ee74326588ebc85e99ff013fc28359b165c84bbef33f5c9134ae5dbd5047a03

Contents?: true

Size: 1.82 KB

Versions: 10

Compression:

Stored size: 1.82 KB

Contents

module RequestLogAnalyzer::Tracker

  # Analyze the duration of a specific attribute
  #
  # === Options
  # * <tt>:category</tt> Proc that handles request categorization for given fileformat (REQUEST_CATEGORIZER)
  # * <tt>:duration</tt> The field containing the duration in the request hash.
  # * <tt>:if</tt> Proc that has to return !nil for a request to be passed to the tracker.
  # * <tt>:line_type</tt> The line type that contains the duration field (determined by the category proc).
  # * <tt>:title</tt> Title do be displayed above the report
  # * <tt>:unless</tt> Handle request if this proc is false for the handled request.
  #
  # The items in the update request hash are set during the creation of the Duration tracker.
  #
  # Example output:
  #  Request duration - top 20 by cumulative time   |    Hits |      Sum. |      Avg.
  #  ---------------------------------------------------------------------------------
  #  EmployeeController#show.html [GET]             |    4742 |  4922.56s |     1.04s
  #  EmployeeController#update.html [POST]          |    4647 |  2731.23s |     0.59s
  #  EmployeeController#index.html [GET]            |    5802 |  1477.32s |     0.25s
  #  .............
  class Duration < NumericValue

    # Check if duration and catagory option have been received,
    def prepare
      options[:value] = options[:duration] if options[:duration]
      super
    end

    # Display a duration
    def display_value(time)
      case time
      when nil       then '-'
      when 0...60    then "%0.02fs" % time
      when 60...3600 then "%dm%02ds" % [time / 60, (time % 60).round]
      else                "%dh%02dm%02ds" % [time / 3600, (time % 3600) / 60, (time % 60).round]
      end
    end

    # Returns the title of this tracker for reports
    def title
      options[:title]  || 'Request duration'
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
request-log-analyzer-1.8.1 lib/request_log_analyzer/tracker/duration.rb
request-log-analyzer-1.8.0 lib/request_log_analyzer/tracker/duration.rb
request-log-analyzer-1.7.0 lib/request_log_analyzer/tracker/duration.rb
request-log-analyzer-1.6.4 lib/request_log_analyzer/tracker/duration.rb
request-log-analyzer-1.6.3 lib/request_log_analyzer/tracker/duration.rb
request-log-analyzer-1.6.2 lib/request_log_analyzer/tracker/duration.rb
request-log-analyzer-1.6.1 lib/request_log_analyzer/tracker/duration.rb
request-log-analyzer-1.6.0 lib/request_log_analyzer/tracker/duration.rb
request-log-analyzer-1.5.4 lib/request_log_analyzer/tracker/duration.rb
request-log-analyzer-1.5.3 lib/request_log_analyzer/tracker/duration.rb