From: Willy Tarreau Date: Wed, 15 Nov 2017 17:51:29 +0000 (+0100) Subject: MINOR: tools: emphasize the node being worked on in the tree dump X-Git-Tag: v1.8-rc4~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c1e15d8cd1ca748915cbc75094daae67f17b56c;p=thirdparty%2Fhaproxy.git MINOR: tools: emphasize the node being worked on in the tree dump Now we can show in dotted red the node being removed or surrounded in red a node having been inserted, and add a description on the graph related to the operation in progress for example. --- diff --git a/include/common/standard.h b/include/common/standard.h index 3762338210..b2d67edc51 100644 --- a/include/common/standard.h +++ b/include/common/standard.h @@ -37,6 +37,7 @@ #include #include #include +#include #ifndef LLONG_MAX # define LLONG_MAX 9223372036854775807LL @@ -823,8 +824,15 @@ const void *my_memmem(const void *, size_t, const void *, size_t); */ unsigned int get_next_id(struct eb_root *root, unsigned int key); -/* dump the full tree to in DOT format for debugging purposes */ -void eb32sc_to_file(FILE *file, struct eb_root *root); +/* dump the full tree to in DOT format for debugging purposes. Will + * optionally highlight node if found, depending on operation : + * 0 : nothing + * >0 : insertion, node/leaf are surrounded in red + * <0 : removal, node/leaf are dashed with no background + * Will optionally add "desc" as a label on the graph if set and non-null. + */ +void eb32sc_to_file(FILE *file, struct eb_root *root, const struct eb32sc_node *subj, + int op, const char *desc); /* This function compares a sample word possibly followed by blanks to another * clean word. The compare is case-insensitive. 1 is returned if both are equal, diff --git a/src/standard.c b/src/standard.c index a0f3d65d4b..acd136c27c 100644 --- a/src/standard.c +++ b/src/standard.c @@ -2228,14 +2228,28 @@ unsigned int get_next_id(struct eb_root *root, unsigned int key) return key; } -/* dump the full tree to in DOT format for debugging purposes */ -void eb32sc_to_file(FILE *file, struct eb_root *root) +/* dump the full tree to in DOT format for debugging purposes. Will + * optionally highlight node if found, depending on operation : + * 0 : nothing + * >0 : insertion, node/leaf are surrounded in red + * <0 : removal, node/leaf are dashed with no background + * Will optionally add "desc" as a label on the graph if set and non-null. + */ +void eb32sc_to_file(FILE *file, struct eb_root *root, const struct eb32sc_node *subj, int op, const char *desc) { struct eb32sc_node *node; unsigned long scope = -1; + fprintf(file, "digraph ebtree {\n"); + + if (desc && *desc) { + fprintf(file, + " fontname=\"fixed\";\n" + " fontsize=8;\n" + " label=\"%s\";\n", desc); + } + fprintf(file, - "digraph ebtree {\n" " node [fontname=\"fixed\" fontsize=8 shape=\"box\" style=\"filled\" color=\"black\" fillcolor=\"white\"];\n" " edge [fontname=\"fixed\" fontsize=8 style=\"solid\" color=\"magenta\" dir=\"forward\"];\n" " \"%lx_n\" [label=\"root\\n%lx\"]\n", (long)eb_root_to_node(root), (long)root @@ -2250,8 +2264,9 @@ void eb32sc_to_file(FILE *file, struct eb_root *root) while (node) { if (node->node.node_p) { /* node part is used */ - fprintf(file, " \"%lx_n\" [label=\"%lx\\nkey=%u\\nscope=%lx\\nbit=%d\" fillcolor=\"lightskyblue1\"];\n", - (long)node, (long)node, node->key, node->node_s, node->node.bit); + fprintf(file, " \"%lx_n\" [label=\"%lx\\nkey=%u\\nscope=%lx\\nbit=%d\" fillcolor=\"lightskyblue1\" %s];\n", + (long)node, (long)node, node->key, node->node_s, node->node.bit, + (node == subj) ? (op < 0 ? "color=\"red\" style=\"dashed\"" : op > 0 ? "color=\"red\"" : "") : ""); fprintf(file, " \"%lx_n\" -> \"%lx_n\" [taillabel=\"%c\"];\n", (long)node, @@ -2269,8 +2284,9 @@ void eb32sc_to_file(FILE *file, struct eb_root *root) eb_gettag(node->node.branches.b[1]) == EB_LEAF ? 'l' : 'n'); } - fprintf(file, " \"%lx_l\" [label=\"%lx\\nkey=%u\\nscope=%lx\\npfx=%u\" fillcolor=\"yellow\"];\n", - (long)node, (long)node, node->key, node->leaf_s, node->node.pfx); + fprintf(file, " \"%lx_l\" [label=\"%lx\\nkey=%u\\nscope=%lx\\npfx=%u\" fillcolor=\"yellow\" %s];\n", + (long)node, (long)node, node->key, node->leaf_s, node->node.pfx, + (node == subj) ? (op < 0 ? "color=\"red\" style=\"dashed\"" : op > 0 ? "color=\"red\"" : "") : ""); fprintf(file, " \"%lx_l\" -> \"%lx_n\" [taillabel=\"%c\"];\n", (long)node,