From 7ba8f3cc5088eb58fbf46cb74af312449c210051 Mon Sep 17 00:00:00 2001 From: Niklas Hofmann Date: Wed, 13 Aug 2014 21:30:53 +0200 Subject: [PATCH] start graph export timer via command line paramter in manynodes example --- examples/manynodes.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/examples/manynodes.c b/examples/manynodes.c index 3215cfcc..bc3a1a17 100644 --- a/examples/manynodes.c +++ b/examples/manynodes.c @@ -111,7 +111,7 @@ void exportmeshgraph_timer(int signum) gettimeofday(&ts, NULL); char name[1024]; - snprintf(name, sizeof(name), "graph_%ld_%ld.json", ts.tv_sec, ts.tv_usec/1000); + snprintf(name, sizeof(name), "graph_%ld_%03ld.json", ts.tv_sec, ts.tv_usec/1000); exportmeshgraph(name); } @@ -154,10 +154,10 @@ static bool exportmeshgraph_begin(const char* timeout_str) /* Install timer_handler as the signal handler for SIGALRM. */ signal(SIGALRM, exportmeshgraph_timer); - /* Configure the timer to expire after X msec... */ + /* Configure the timer to expire immediately... */ struct itimerval timer; - timer.it_value.tv_sec = timeout_sec; - timer.it_value.tv_usec = timeout_msec * 1000; + timer.it_value.tv_sec = 0; + timer.it_value.tv_usec = 1000; /* ... and every X msec after that. */ timer.it_interval.tv_sec = timeout_sec; @@ -330,13 +330,14 @@ static void parse_input(char *buf) { int main(int argc, char *argv[]) { const char *basebase = ".manynodes"; const char *namesprefix = "machine1"; + const char *graphexporttimeout = NULL; char buf[1024]; if(argc > 1) n = atoi(argv[1]); if(n < 1) { - fprintf(stderr, "Usage: %s [number of local nodes] [confbase] [prefixnodenames]\n", argv[0]); + fprintf(stderr, "Usage: %s [number of local nodes] [confbase] [prefixnodenames] [graphexport timeout]\n", argv[0]); return 1; } @@ -346,6 +347,9 @@ int main(int argc, char *argv[]) { if(argc > 3) namesprefix = argv[3]; + if(argc > 4) + graphexporttimeout = argv[4]; + mesh = calloc(n, sizeof *mesh); meshlink_set_log_cb(NULL, MESHLINK_WARNING, log_message); @@ -382,12 +386,17 @@ int main(int argc, char *argv[]) { return 1; } + if(graphexporttimeout) + { exportmeshgraph_begin(graphexporttimeout); } + printf("%d nodes started.\nType /help for a list of commands.\n", started); // handle input while(fgets(buf, sizeof buf, stdin)) parse_input(buf); + exportmeshgraph_end(NULL); + printf("Nodes stopping.\n"); for(int i = 0; i < n; i++) -- 2.39.5