instance method exclusive_duration_sum

Ruby on Rails edge

Since edge Private — implementation detail, not part of the public API

Signature

exclusive_duration_sum(events)

Sum durations for one event name without double-counting nested events. Nested notifications (e.g. a partial that renders another partial) report inclusive durations; subtracting direct same-name children yields exclusive time so the metric stays within wall-clock bounds.

Parameters

events req
Source
# File actionpack/lib/action_dispatch/middleware/server_timing.rb, line 83
      def exclusive_duration_sum(events)
        return 0.0 if events.empty?
        return events.first.duration if events.one?

        sorted = events.sort_by { |event| [event.time, -event.duration] }
        children_ms = Hash.new(0.0)
        stack = []

        sorted.each do |event|
          while stack.any? && stack.last.end <= event.time
            stack.pop
          end

          if stack.any? && event.end <= stack.last.end
            children_ms[stack.last] += event.duration
          end

          stack << event
        end

        events.sum { |event| event.duration - children_ms[event] }
      end

Defined in actionpack/lib/action_dispatch/middleware/server_timing.rb line 83 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionDispatch::ServerTiming

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close