From: Michal Sojka Date: Thu, 18 Jun 2009 14:56:21 +0000 (+0200) Subject: Added options to ignore first few messages to to store ping times to a file X-Git-Url: http://rtime.felk.cvut.cz/gitweb/canping.git/commitdiff_plain/e746bdc0fa1b65c87d0f9e87e2bd5d202ea72de3?ds=sidebyside Added options to ignore first few messages to to store ping times to a file --- diff --git a/src/vca_canping.c b/src/vca_canping.c index c3fbb07..64ea3c2 100644 --- a/src/vca_canping.c +++ b/src/vca_canping.c @@ -103,7 +103,8 @@ int option_open_once = 0; int option_synch_start = 0; bool option_background = false; char *option_histogram = NULL; - +int option_msg_to_ignore = 0; +char *option_save_all_times = NULL; /* Lists */ typedef struct threads { ul_list_head_t head; @@ -127,6 +128,7 @@ typedef struct thread_data { int timeout; /* number of timeouts */ struct histogram hist; + unsigned *times; /* Array of all measured times */ ul_list_node_t node; } thread_data_t; @@ -269,6 +271,12 @@ void *master_thread(void *arg) if (option_histogram) histogram_init(&td->hist, 1000*1000/*max [us]*/, 5/*resolution [us]*/); + + if (option_save_all_times) { + td->times = malloc(sizeof(*td->times)*option_count); + if (!td->times) + error(1, errno, "malloc times"); + } /* Prepare data structures for the select syscall. */ FD_ZERO (&rdset); @@ -283,7 +291,7 @@ void *master_thread(void *arg) pthread_mutex_unlock(&mut_start); } - while (!IS_FINISH_FLAG() && (option_count == 0 || ping_count++ < option_count)) { + while (!IS_FINISH_FLAG() && (option_count == 0 || ping_count++ < option_count + option_msg_to_ignore)) { /* Send a ping message */ pingmsg.flags=0; pingmsg.id=ping_id; @@ -336,21 +344,25 @@ void *master_thread(void *arg) printf("%d:%ld\n", ping_id, time); break; case 3: - printf("Pong response for id %d received in %ld us\n", ping_id, time); + printf("Pong response %d for id %d received in %ld us\n", ping_count, ping_id, time); break; } /* Update statistics */ - td->count++; - td->mean = - td->mean * ((double)(td->count - 1) / td->count) + - (double)time / td->count; - td->moment2nd = - td->moment2nd * ((double)(td->count - 1) / td->count) + - (double)time*time / td->count; - if (time > td->max) td->max = time; - if (time < td->min) td->min = time; - if (option_histogram) - histogram_add(&td->hist, time); + if (ping_count > option_msg_to_ignore) { + td->count++; + td->mean = + td->mean * ((double)(td->count - 1) / td->count) + + (double)time / td->count; + td->moment2nd = + td->moment2nd * ((double)(td->count - 1) / td->count) + + (double)time*time / td->count; + if (time > td->max) td->max = time; + if (time < td->min) td->min = time; + if (option_histogram) + histogram_add(&td->hist, time); + if (option_save_all_times) + td->times[ping_count - 1 - option_msg_to_ignore] = time; + } total_count++; } /* read */ } @@ -384,6 +396,17 @@ void *master_thread(void *arg) fclose(f); } + if (option_save_all_times) { + FILE *f; + char buf[100]; + int i; + snprintf(buf, sizeof(buf), "%s-%d.dat", option_save_all_times, ping_id); + f = fopen(buf, "w"); + for (i=0; itimes[i]); + fclose(f); + } + sem_post(&finish_sem); return (void *)ret; } @@ -575,10 +598,12 @@ void print_help(void) " -b go to background (fork) after initialization, prints child PID\n" " -c count how many messages each master sends\n" " -d dev device (e.g. /dev/can1)\n" + " -e prefix save all measured times in file -.dat\n" " -g prefix store cumulative histogram in file -.dat\n" " -h print this help\n" " -i id id of first master message\n" " -l length length of the messages (0..8)\n" + " -n number ignore first messages\n" " -o open a device only once for all threads (doesn't work)\n" /* due to filters */ " -t timeout timeout in seconds (default 4 s)\n" " -v be verbose (use more than once to increase verbosity)\n" @@ -599,7 +624,7 @@ int parse_options(int argc, char *argv[]) int c; opterr = 0; - while ((c = getopt (argc, argv, "bc:d:g:hi:l:m:os:t:vw:yrR:")) != -1) + while ((c = getopt (argc, argv, "bc:d:e:g:hi:l:m:n:os:t:vw:yrR:")) != -1) switch (c) { case 'b': @@ -611,6 +636,9 @@ int parse_options(int argc, char *argv[]) case 'd': option_device = optarg; break; + case 'e': + option_save_all_times = optarg; + break; case 'g': option_histogram = optarg; break; @@ -629,6 +657,9 @@ int parse_options(int argc, char *argv[]) case 'm': option_masters = atoi(optarg); break; + case 'n': + option_msg_to_ignore = atoi(optarg); + break; case 'o': option_open_once = 1; break;