Graphviz – Introduction

开发了一个perl脚本,自认为代码写得还算清晰,可以在添加一个功能的时候仍然要想半天,当然,这个新功能使得整个逻辑更加复杂。于是画了一幅图出来,一目了然。

然而,这幅图可不是我用手画出来的(最烦这种摆来摆去的工作,画个图麻烦死了)而是用GraphViz生成出来的,下面这段代码才是我真正输入的:

digraph G {
    handle_options -> start_test -> check_directory_file;
    check_directory_file -> get_cvs_branch -> working_revision_available;
    working_revision_available -> cvs_status_changes [label="No"];
    working_revision_available -> create_cvs_log_command [label="Yes"];
    cvs_status_changes -> exit_test [label="No"];
    cvs_status_changes -> get_working_revision [label="Yes"];
    get_working_revision -> create_cvs_log_command -> split_checkin_message;
    split_checkin_message -> exit_test [label="Test Report Only"];
    split_checkin_message -> cvs_update [label="Real Work"]
    cvs_update -> apply_codereview_patch [label="Before Check In"];
    cvs_update -> build_compiler [label="After Check In"];
    apply_codereview_patch -> build_compiler;
    build_compiler -> generate_unique_compiler_executable;
    generate_unique_compiler_executable -> submit_test;
    submit_test -> exit_test [label="Other Branch"];
    submit_test -> apply_cppunit_patch [label="MSA"];
    apply_cppunit_patch -> make_selftest -> exit_test;
}

然后把这段代码存为flowgraph.dot,最后运行命令:

$ dot -Tpng flowgraph.dot -o flowgraph.png

这样,就得到了上面那幅图,怎么样,还不错吧。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据