Sha256: 078457c7ece06a138d8e8a8bb4e938a454234c2d14aeb64746e24284fa6fb1e7

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module RailsMiniProfiler
  class TracePresenter < BasePresenter
    def initialize(trace, view, context: {})
      super(trace, view)
      @start = context[:start]
      @finish = context[:finish]
      @total_duration = context[:total_duration]
      @total_allocations = context[:total_allocations]
    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 / @total_duration * 100).round
    end

    def allocations
      formatted_allocations(model.allocations)
    end

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_mini_profiler-0.7.0 app/presenters/rails_mini_profiler/trace_presenter.rb