Sha256: a03ba54e021c0a0fba0136348d294a0e732d6829d184e7637bfb00667639cd68

Contents?: true

Size: 1.27 KB

Versions: 11

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module RailsMiniProfiler
  class TracePresenter < BasePresenter
    def initialize(trace, view, profiled_request:)
      super(trace, view)
      @profiled_request = profiled_request
    end

    def label
      ''
    end

    def description
      label
    end

    def payload
      nil
    end

    def backtrace
      return if model.backtrace.empty?

      model.backtrace.first
    end

    def type
      # Turn this class name into a dasherized version for use in assigning CSS classes. E.g. 'RmpTracePresenter'
      # becomes 'rmp-trace'
      self.class.name.demodulize.delete_suffix('Presenter')
        .underscore
        .dasherize
    end

    def duration
      formatted_duration(model.duration)
    end

    def duration_percent
      (model.duration.to_f / @profiled_request.duration * 100).round
    end

    def allocations
      formatted_allocations(model.allocations)
    end

    def allocations_percent
      (model.allocations.to_f / @profiled_request.allocations * 100).round
    end

    def from_start
      (model.start - @profiled_request.start).to_f / 100
    end

    def from_start_percent
      ((model.start - @profiled_request.start).to_f /
        (@profiled_request.finish - @profiled_request.start)).to_f * 100
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rails_mini_profiler-0.6.0 app/presenters/rails_mini_profiler/trace_presenter.rb
rails_mini_profiler-0.5.0 app/presenters/rails_mini_profiler/trace_presenter.rb
rails_mini_profiler-0 app/presenters/rails_mini_profiler/trace_presenter.rb
rails_mini_profiler-0.4.0 app/presenters/rails_mini_profiler/trace_presenter.rb
rails_mini_profiler-0.3.0 app/presenters/rails_mini_profiler/trace_presenter.rb
rails_mini_profiler-0.2.1 app/presenters/rails_mini_profiler/trace_presenter.rb
rails_mini_profiler-0.2.0 app/presenters/rails_mini_profiler/trace_presenter.rb
rails_mini_profiler-0.1.3 app/presenters/rails_mini_profiler/trace_presenter.rb
rails_mini_profiler-0.1.2 app/presenters/rails_mini_profiler/trace_presenter.rb
rails_mini_profiler-0.1.1 app/presenters/rails_mini_profiler/trace_presenter.rb
rails_mini_profiler-0.1.0 app/presenters/rails_mini_profiler/trace_presenter.rb