diff options
author | Glenn Elliott <gelliott@cs.unc.edu> | 2014-08-04 20:58:02 -0400 |
---|---|---|
committer | Glenn Elliott <gelliott@cs.unc.edu> | 2014-08-04 20:58:02 -0400 |
commit | c84aed7b6f91cd0bdd2ee1c4e2113b3a233c6c77 (patch) | |
tree | eca58fb6447c49e99183fc7864bbe40f34926e48 | |
parent | 878bacd0f710547c1939ac38d9861b43cf137ab3 (diff) |
Dot: Clean up graph/node/edge labels in dot output
This patch removes control characters (including '\n')
from graph/node/edge names when used as labels in
dot output.
-rw-r--r-- | src/pgm.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/pgm.cpp b/src/pgm.cpp index 0c429e9..8765b37 100644 --- a/src/pgm.cpp +++ b/src/pgm.cpp | |||
@@ -3807,11 +3807,25 @@ static const char* edgeTypeStr(const struct pgm_edge* e) | |||
3807 | return "unknown"; | 3807 | return "unknown"; |
3808 | } | 3808 | } |
3809 | 3809 | ||
3810 | static void filter_ctrlchars(char* str, size_t len) | ||
3811 | { | ||
3812 | for(size_t i = 0; i < len && str[i] != '\0'; ++i) | ||
3813 | { | ||
3814 | if(iscntrl(str[i])) | ||
3815 | { | ||
3816 | str[i] = '\0'; | ||
3817 | break; | ||
3818 | } | ||
3819 | } | ||
3820 | } | ||
3821 | |||
3810 | int pgm_print_graph(graph_t graph, FILE* outs) | 3822 | int pgm_print_graph(graph_t graph, FILE* outs) |
3811 | { | 3823 | { |
3812 | int ret = -1; | 3824 | int ret = -1; |
3813 | struct pgm_graph* g; | 3825 | struct pgm_graph* g; |
3814 | 3826 | ||
3827 | char namebuf[PGM_NODE_NAME_LEN]; | ||
3828 | |||
3815 | if(!is_valid_graph(graph)) | 3829 | if(!is_valid_graph(graph)) |
3816 | goto out; | 3830 | goto out; |
3817 | 3831 | ||
@@ -3819,12 +3833,15 @@ int pgm_print_graph(graph_t graph, FILE* outs) | |||
3819 | 3833 | ||
3820 | pthread_mutex_lock(&g->lock); | 3834 | pthread_mutex_lock(&g->lock); |
3821 | 3835 | ||
3836 | strncpy(namebuf, g->name, PGM_NODE_NAME_LEN); | ||
3837 | filter_ctrlchars(namebuf, PGM_NODE_NAME_LEN); | ||
3838 | |||
3822 | fprintf(outs, | 3839 | fprintf(outs, |
3823 | "digraph G {\n" | 3840 | "digraph G {\n" |
3824 | "\trankdir=TB;\n" | 3841 | "\trankdir=TB;\n" |
3825 | "\tsize=\"11,8.5\";\n" | 3842 | "\tsize=\"11,8.5\";\n" |
3826 | "\tlabel=\"%s\";\n", | 3843 | "\tlabel=\"%s\";\n", |
3827 | g->name); | 3844 | namebuf); |
3828 | 3845 | ||
3829 | for(int i = 0; i < g->nr_nodes; ++i) | 3846 | for(int i = 0; i < g->nr_nodes; ++i) |
3830 | { | 3847 | { |
@@ -3852,28 +3869,34 @@ int pgm_print_graph(graph_t graph, FILE* outs) | |||
3852 | bool isSrc = (degreeIn == 0); | 3869 | bool isSrc = (degreeIn == 0); |
3853 | bool isSink = (degreeOut == 0); | 3870 | bool isSink = (degreeOut == 0); |
3854 | 3871 | ||
3872 | strncpy(namebuf, n->name, PGM_NODE_NAME_LEN); | ||
3873 | filter_ctrlchars(namebuf, PGM_NODE_NAME_LEN); | ||
3874 | |||
3855 | fprintf(outs, | 3875 | fprintf(outs, |
3856 | "\t%d [shape=%s, style=%s, color=%s, label=\"%s\"];\n", | 3876 | "\t%d [shape=%s, style=%s, color=%s, label=\"%s\"];\n", |
3857 | i, | 3877 | i, |
3858 | (isSrc || isSink) ? "doublecircle" : "circle", | 3878 | (isSrc || isSink) ? "doublecircle" : "circle", |
3859 | (isSrc || isSink) ? "filled" : "\"\"", | 3879 | (isSrc || isSink) ? "filled" : "\"\"", |
3860 | (isSrc) ? "\"#56A0D3\"" : (isSink) ? "\"#E04050D3\"" : "\"\"", | 3880 | (isSrc) ? "\"#56A0D3\"" : (isSink) ? "\"#E04050D3\"" : "\"\"", |
3861 | n->name); | 3881 | namebuf); |
3862 | } | 3882 | } |
3863 | 3883 | ||
3864 | for(int i = 0; i < g->nr_edges; ++i) | 3884 | for(int i = 0; i < g->nr_edges; ++i) |
3865 | { | 3885 | { |
3866 | const struct pgm_edge* e = &g->edges[i]; | 3886 | const struct pgm_edge* e = &g->edges[i]; |
3867 | 3887 | ||
3888 | strncpy(namebuf, e->name, PGM_NODE_NAME_LEN); | ||
3889 | filter_ctrlchars(namebuf, PGM_NODE_NAME_LEN); | ||
3890 | |||
3868 | fprintf(outs, | 3891 | fprintf(outs, |
3869 | "\t%d -> %d [style=%s, color=%s, label=\"%s%s_%s\", headlabel=\"%lu (%lu)\", taillabel=\"%lu\"]\n", | 3892 | "\t%d -> %d [style=%s, color=%s, label=\"%s%s_%s\", headlabel=\"%lu (%lu)\", taillabel=\"%lu\"]\n", |
3870 | e->producer, | 3893 | e->producer, |
3871 | e->consumer, | 3894 | e->consumer, |
3872 | (!e->is_backedge) ? "solid" : "dashed", | 3895 | (!e->is_backedge) ? "solid" : "dashed", |
3873 | (is_data_passing(e)) ? "blue" : "green", | 3896 | (is_data_passing(e)) ? "blue" : "dimgray", |
3874 | (is_signal_driven(e) && e->ops != &pgm_cv_edge_ops) ? "fast_" : "", | 3897 | (is_signal_driven(e) && e->ops != &pgm_cv_edge_ops) ? "fast_" : "", |
3875 | edgeTypeStr(e), | 3898 | edgeTypeStr(e), |
3876 | e->name, | 3899 | namebuf, |
3877 | e->attr.nr_consume, | 3900 | e->attr.nr_consume, |
3878 | e->attr.nr_threshold, | 3901 | e->attr.nr_threshold, |
3879 | e->attr.nr_produce); | 3902 | e->attr.nr_produce); |