class Stackprofiler::Filter::JsTree

Public Class Methods

new(options={}) click to toggle source
# File lib/stackprofiler/filters/js_tree.rb, line 4
def initialize(options={})

end

Public Instance Methods

filter(root, run) click to toggle source
# File lib/stackprofiler/filters/js_tree.rb, line 8
def filter root, run
  addrs = root.content[:addrs]
  name = addrs.first
  frames = run.profile[:frames]
  frame = frames[name]

  escaped = addrs.map do |addr|
    this_frame = frames[addr]
    this_name = CGI::escapeHTML(this_frame[:name])
    "#{this_name} (<b>#{this_frame[:samples]}</b>)"
  end
  text = escaped.join("<br> ↳ ").presence || root.name

  sorted_children = root.children.sort_by do |child|
    addr = child.content[:addrs].first
    cframe = frames[addr]
    cframe[:samples]
  end.reverse

  children = sorted_children.map { |n| filter(n, run) }
  open = root.content.has_key?(:open) ? root.content[:open] : frame[:total_samples] > 100
  {text: text, state: {opened: open}, children: children, icon: false, data: {addrs: addrs}}
end