Ejemplo n.º 1
0
// createDOT creates a DOT graph with the given file name.
func createDOT(stepName string, graph *dot.Graph) error {
	dotPath := stepName + ".dot"
	if !flagQuiet {
		log.Printf("Creating: %q", dotPath)
	}
	buf := []byte(graph.String())
	if err := ioutil.WriteFile(dotPath, buf, 0644); err != nil {
		return errutil.Err(err)
	}

	// Generate an image representation of the control flow graph.
	if flagImage {
		pngPath := stepName + ".png"
		if !flagQuiet {
			log.Printf("Creating: %q", pngPath)
		}
		cmd := exec.Command("dot", "-Tpng", "-o", pngPath, dotPath)
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		if err := cmd.Run(); err != nil {
			return errutil.Err(err)
		}
	}
	return nil
}
Ejemplo n.º 2
0
// dump stores the graph as a DOT file and an image representation of the graph
// as a PNG file with filenames based on "-o" flag.
func dump(graph *dot.Graph) error {
	// Store graph to DOT file.
	dotPath := flagOut
	if !flagQuiet {
		log.Printf("Creating: %q\n", dotPath)
	}
	err := ioutil.WriteFile(dotPath, []byte(graph.String()), 0644)
	if err != nil {
		return errutil.Err(err)
	}

	// Generate an image representation of the graph.
	if flagImage {
		pngPath := pathutil.TrimExt(dotPath) + ".png"
		if !flagQuiet {
			log.Printf("Creating: %q\n", pngPath)
		}
		cmd := exec.Command("dot", "-Tpng", "-o", pngPath, dotPath)
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		err = cmd.Run()
		if err != nil {
			return errutil.Err(err)
		}
	}

	return nil
}