Class: RubyProf::FlameGraphJsonPrinter::FlameDataJsonPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-prof/printers/flame_graph_json_printer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, options = {}) ⇒ FlameDataJsonPrinter

Returns a new instance of FlameDataJsonPrinter.



74
75
76
77
78
79
80
81
# 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

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



72
73
74
# File 'lib/ruby-prof/printers/flame_graph_json_printer.rb', line 72

def output
  @output
end

Instance Method Details

#enter(name, called, self_value, total_value) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 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

#leaveObject



101
102
103
104
105
106
107
108
109
110
111
112
# 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