]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: emphasize the node being worked on in the tree dump
authorWilly Tarreau <w@1wt.eu>
Wed, 15 Nov 2017 17:51:29 +0000 (18:51 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 15 Nov 2017 18:43:05 +0000 (19:43 +0100)
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.

include/common/standard.h
src/standard.c

index 3762338210c7d9e7904ab54c54373b87d7bc7b05..b2d67edc516a22804b4b01eaae9bdff8dfd7041f 100644 (file)
@@ -37,6 +37,7 @@
 #include <common/config.h>
 #include <common/namespace.h>
 #include <eb32tree.h>
+#include <eb32sctree.h>
 
 #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 <file> in DOT format for debugging purposes */
-void eb32sc_to_file(FILE *file, struct eb_root *root);
+/* dump the full tree to <file> in DOT format for debugging purposes. Will
+ * optionally highlight node <subj> if found, depending on operation <op> :
+ *    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,
index a0f3d65d4bece3bdc16d0ceeb037ce70bb7f8d4d..acd136c27c384c256fde7dc7d15a2607d4cd1b56 100644 (file)
@@ -2228,14 +2228,28 @@ unsigned int get_next_id(struct eb_root *root, unsigned int key)
        return key;
 }
 
-/* dump the full tree to <file> in DOT format for debugging purposes */
-void eb32sc_to_file(FILE *file, struct eb_root *root)
+/* dump the full tree to <file> in DOT format for debugging purposes. Will
+ * optionally highlight node <subj> if found, depending on operation <op> :
+ *    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,