class RubyProf::FlameGraphJsonPrinter::FlameDataJsonPrinter
Attributes
output[R]
Public Class Methods
new(output, options={})
click to toggle source
# File lib/ruby-prof/printers/flame_graph_json_printer.rb, line 74 def initialize(output, options={}) @output = output @depth = options[:depth] || 0 @anchored = options.fetch(:anchored, false) @pretty = options.fetch(:pretty, false) @state = :root update_layout end
Public Instance Methods
enter(name, called, self_value, total_value)
click to toggle source
# File lib/ruby-prof/printers/flame_graph_json_printer.rb, line 83 def enter(name, called, self_value, total_value) case @state when :enter put_line "," put_part "\"children\": [" step_in(:enter) when :leave put_part ", " end put_line "{" step_in(:enter) put_line "\"name\": \"#{name}\"," put_line "\"called\": #{called}," put_line "\"lost\": #{self_value}," put_part "\"value\": #{total_value}" end
leave()
click to toggle source
# File lib/ruby-prof/printers/flame_graph_json_printer.rb, line 101 def leave case @state when :enter new_line when :leave step_out(:leave) put_line "]" end step_out(:leave) put_part "}" end
Private Instance Methods
new_line()
click to toggle source
# File lib/ruby-prof/printers/flame_graph_json_printer.rb, line 129 def new_line @output << @break if !@anchored @anchored = true end
put_line(str)
click to toggle source
# File lib/ruby-prof/printers/flame_graph_json_printer.rb, line 122 def put_line(str) @output << @indent if @anchored @output << str @output << @break @anchored = true end
put_part(str)
click to toggle source
# File lib/ruby-prof/printers/flame_graph_json_printer.rb, line 116 def put_part(str) @output << @indent if @anchored @output << str @anchored = false end
step_in(new_state)
click to toggle source
# File lib/ruby-prof/printers/flame_graph_json_printer.rb, line 134 def step_in(new_state) @state = new_state @depth += 1 update_layout end
step_out(new_state)
click to toggle source
# File lib/ruby-prof/printers/flame_graph_json_printer.rb, line 140 def step_out(new_state) @state = new_state @depth -=1 update_layout end
update_layout()
click to toggle source
# File lib/ruby-prof/printers/flame_graph_json_printer.rb, line 146 def update_layout if @pretty @break = "\n" @indent = "" else @break = " " @indent = "" end end