Skip to content

Instantly share code, notes, and snippets.

@chinmaygarde
Created June 12, 2018 22:52
Show Gist options
  • Select an option

  • Save chinmaygarde/8637e4ead1234c4746737ffdf0a51842 to your computer and use it in GitHub Desktop.

Select an option

Save chinmaygarde/8637e4ead1234c4746737ffdf0a51842 to your computer and use it in GitHub Desktop.
Bloaty Output 2 Flame Graph for Engine Size.
require 'pathname'
def make_relative_to_src(line)
line.gsub(/\.\.\/\.\.\//, '')
end
def split_path_components(path_name)
Pathname.new(path_name).each_filename.to_a
end
class SourceNode
def initialize
@name = ""
@size = 0.0
@children = Hash.new
end
attr_accessor :name, :size
def add_compile_unit(compile_unit_components, vm_size)
root = compile_unit_components.take(1)[0]
rest = compile_unit_components.drop(1)
if root == ""
throw "Root was empty"
end
if not @children[root]
@children[root] = SourceNode.new
end
node = @children[root]
node.name = root
if rest.length == 0
node.size = node.size + vm_size
end
node.add_compile_unit(rest, vm_size) if rest.length > 0
end
def collapsed_stack(prefix = "")
if prefix != ""
prefix = "#{prefix};"
end
entry = "#{prefix}#{@name}"
@children.each do |name, node|
node.collapsed_stack(entry)
end
puts("#{entry} #{@size}")
end
end
def collapse_csv(csv)
tree = SourceNode.new
csv.each_line do |line|
line_components = line.split(',')
compile_unit = line_components[0]
vm_size = line_components[1]
file_size = line_components[2]
compile_unit = make_relative_to_src(compile_unit)
compile_unit_components = split_path_components(compile_unit)
tree.add_compile_unit(compile_unit_components, vm_size.to_f)
end
tree.collapsed_stack
end
collapse_csv ARGF.read
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment