Class: RequireProfiler::Printer::CallStack

Inherits:
Base
  • Object
show all
Defined in:
lib/require_profiler/printer/call_stack.rb

Overview

CallStack formatter prints collapsed stacks (Brendan Gregg's format)

Direct Known Subclasses

JSON

Constant Summary collapse

RAILS_LABEL_PARTS =

Rails labels are "rails:#type:#detail", e.g. "rails:initializer:name:file:line"

3
RAILS_TYPE_INDEX =
1

Instance Method Summary collapse

Methods inherited from Base

#finish, #initialize

Constructor Details

This class inherits a constructor from RequireProfiler::Printer::Base

Instance Method Details

#flush(node, parts: []) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/require_profiler/printer/call_stack.rb', line 11

def flush(node, parts: [])
  return unless flush?(node)

  path = strip_prefix(node.path)
  self_parts =
    case node.kind
    when :rails then rails_frames(path)
    when :path then path_frames(path)
    else [path]
    end

  parts += self_parts
  # We only show self-time, so exclude children
  val = ((node.time - node.children.sum(&:time)) * 1000).round(3)

  output << "#{parts.join(";")} #{val}\n"

  node.children.each { flush(_1, parts:) }
end