class Stackviz
Constants
- VERSION
Public Class Methods
new(path)
click to toggle source
# File lib/stackviz.rb, line 12 def initialize(path) return @path = path if path temp = `mktemp /tmp/stackviz-XXXXXXXX`.strip @path = "#{temp}.gif" `mv #{temp} #{@path}` end
profile(mode: :cpu, path: nil, open: true, &block)
click to toggle source
# File lib/stackviz.rb, line 6 def self.profile(mode: :cpu, path: nil, open: true, &block) stackviz = self.new(path) stackviz.run(mode, &block) stackviz.open_graph if open end
Public Instance Methods
open_graph()
click to toggle source
# File lib/stackviz.rb, line 35 def open_graph system("open #{@path}") end
run(mode, &block)
click to toggle source
# File lib/stackviz.rb, line 20 def run(mode, &block) ensure_dot_existence result = StackProf.run(mode: mode, &block) Tempfile.open('stackviz') do |f| StackProf::Report.new(result).print_graphviz(nil, f) f.flush File.open(@path, 'w') do |graph| `dot -Tgif #{f.path} -o #{graph.path}` end end end
Private Instance Methods
ensure_dot_existence()
click to toggle source
# File lib/stackviz.rb, line 41 def ensure_dot_existence unless system("which dot > /dev/null") abort "`dot` does not exist. Please install graphviz first." end end