Class: Stackviz
- Inherits:
-
Object
- Object
- Stackviz
- Defined in:
- lib/stackviz.rb,
lib/stackviz/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ Stackviz
constructor
A new instance of Stackviz.
- #open_graph ⇒ Object
- #run(mode, &block) ⇒ Object
Constructor Details
#initialize(path) ⇒ Stackviz
Returns a new instance of Stackviz.
11 12 13 14 15 16 17 |
# File 'lib/stackviz.rb', line 11 def initialize(path) return @path = path if path temp = `mktemp /tmp/stackviz-XXXXXXXX`.strip @path = "#{temp}.gif" `mv #{temp} #{@path}` end |
Class Method Details
.profile(mode: :cpu, path: nil, open: true, &block) ⇒ Object
5 6 7 8 9 |
# File 'lib/stackviz.rb', line 5 def self.profile(mode: :cpu, path: nil, open: true, &block) stackviz = self.new(path) stackviz.run(mode, &block) stackviz.open_graph if open end |
Instance Method Details
#open_graph ⇒ Object
34 35 36 |
# File 'lib/stackviz.rb', line 34 def open_graph system("open #{@path}") end |
#run(mode, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stackviz.rb', line 19 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 |