Created
February 23, 2015 21:33
-
-
Save mattgillooly/f056dfa230a37794f3a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'graphviz' | |
| class Step < Struct.new(:inputs, :outputs) | |
| def each_edge(&block) | |
| inputs.product(outputs).each(&block) | |
| end | |
| end | |
| unless TARGET_FILENAME = ARGV[0] | |
| fail "missing TARGET_FILENAME" | |
| end | |
| steps = [] | |
| current_step = nil | |
| # Parse output from `drake --print` | |
| $stdin.each_line do |line| | |
| line_type, path = line.split | |
| case line_type | |
| when 'S' | |
| steps << current_step if current_step | |
| current_step = Step.new([], []) | |
| when 'I' | |
| current_step.inputs << path | |
| when 'O' | |
| current_step.outputs << path | |
| else | |
| $stderr.puts "Unknown line type: #{line_type.inspect}" | |
| end | |
| end | |
| steps << current_step | |
| # Create a new graph | |
| g = GraphViz.new(:G, :type => :digraph) | |
| # Create an edge between each input and output of each step | |
| steps.each do |step| | |
| step.each_edge do |input, output| | |
| g.add_edges(input, output) | |
| end | |
| end | |
| # Generate output image | |
| g.output(:png => TARGET_FILENAME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment