From: Guus Sliepen Date: Thu, 17 May 2007 21:14:30 +0000 (+0000) Subject: Use libevent to dump graphs when necessary. X-Git-Tag: import-tinc-1.1~665 X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=4d0621b1f39537699b0ec4655b0c6e6b84581c9a;p=meshlink Use libevent to dump graphs when necessary. event_add() can be called repeatedly, the second and later calls are ignored if the event hasn't been removed yet. --- diff --git a/src/graph.c b/src/graph.c index 1f006606..02650f73 100644 --- a/src/graph.c +++ b/src/graph.c @@ -58,8 +58,6 @@ #include "subnet.h" #include "utils.h" -static bool graph_changed = true; - /* Implementation of Kruskal's algorithm. Running time: O(EN) Please note that sorting on weight is already done by add_edge(). @@ -311,22 +309,13 @@ void sssp_bfs(void) } } -void graph(void) -{ - sssp_bfs(); - mst_kruskal(); - graph_changed = true; -} - - - /* Dump nodes and edges to a graphviz file. The file can be converted to an image with dot -Tpng graph_filename -o image_filename.png -Gconcentrate=true */ -void dump_graph(void) +static void dump_graph(int fd, short events, void *data) { avl_node_t *node; node_t *n; @@ -334,11 +323,9 @@ void dump_graph(void) char *filename = NULL, *tmpname = NULL; FILE *file; - if(!graph_changed || !get_config_string(lookup_config(config_tree, "GraphDumpFile"), &filename)) + if(!get_config_string(lookup_config(config_tree, "GraphDumpFile"), &filename)) return; - graph_changed = false; - ifdebug(PROTOCOL) logger(LOG_NOTICE, "Dumping graph"); if(filename[0] == '|') { @@ -381,3 +368,15 @@ void dump_graph(void) free(tmpname); } } + +void graph(void) +{ + static struct event ev; + + sssp_bfs(); + mst_kruskal(); + + if(!ev.ev_callback) + timeout_set(&ev, dump_graph, NULL); + event_add(&ev, &(struct timeval){5, 0}); +} diff --git a/src/net.c b/src/net.c index 8259a367..a1ca9ab9 100644 --- a/src/net.c +++ b/src/net.c @@ -301,7 +301,7 @@ int main_loop(void) { struct timeval tv; int r; - time_t last_ping_check, last_config_check, last_graph_dump; + time_t last_ping_check, last_config_check; tevent_t *event; struct event timeout; @@ -309,7 +309,6 @@ int main_loop(void) last_ping_check = now; last_config_check = now; - last_graph_dump = now; srand(now); @@ -431,13 +430,6 @@ int main_loop(void) try_outgoing_connections(); } - - /* Dump graph if wanted every 60 seconds*/ - - if(last_graph_dump + 60 < now) { - dump_graph(); - last_graph_dump = now; - } } return 0;