1 /*******************************************************************************/
2 /* CAN latency tester */
3 /* Copyright (C) 2010, 2011, 2012, 2013, 2014 Michal Sojka, DCE FEE CTU Prague */
5 /*******************************************************************************/
16 #include <semaphore.h>
24 #include <sys/ioctl.h>
26 #include <sys/socket.h>
29 #include <sys/types.h>
33 #include "canframelen.h"
34 #include <linux/can.h>
35 #include <linux/can/raw.h>
37 #include "histogram.h"
42 #define dbg(level, fmt, arg...) do {} while (0)
44 #define dbg(level, fmt, arg...) do { if (level <= DEBUG) { printf("candping: " fmt, ## arg); } } while (0)
47 #define INTERRUPTED_SYSCALL(errno) (errno == EINTR || errno == ERESTART)
49 #define MEMSET_ZERO(obj) memset(&(obj), 0, sizeof(obj))
51 /* Global variables */
52 volatile sig_atomic_t finish_flag = 0; /* Threads should terminate. */
53 sem_t finish_sem; /* Thread signals a termination */
55 /* Command line options */
68 /* Temporary variables */
75 struct options opt = {
86 struct timespec tic, tac;
88 unsigned invalid_frame;
91 int num_interfaces = 0;
92 int count = 0; /* Number of sent messages */
93 unsigned msg_in_progress = 0;
94 int completion_pipe[2];
99 struct timespec ts_sent, ts_sent_kern;
100 struct timespec ts_rx_onwire, ts_rx_onwire_kern;
101 struct timespec ts_rx_final, ts_rx_final_kern;
102 struct can_frame sent, received;
103 unsigned lat_measured_us, tx_time_us;
106 #define MAX_INFOS 10000
107 struct msg_info msg_infos[MAX_INFOS];
109 struct histogram histogram, histogram_gw;
111 void sprint_canframe(char *buf , struct can_frame *cf, int sep) {
112 /* documentation see lib.h */
115 int dlc = (cf->can_dlc > 8)? 8 : cf->can_dlc;
117 if (cf->can_id & CAN_ERR_FLAG) {
118 sprintf(buf, "%08X#", cf->can_id & (CAN_ERR_MASK|CAN_ERR_FLAG));
120 } else if (cf->can_id & CAN_EFF_FLAG) {
121 sprintf(buf, "%08X#", cf->can_id & CAN_EFF_MASK);
124 sprintf(buf, "%03X#", cf->can_id & CAN_SFF_MASK);
128 if (cf->can_id & CAN_RTR_FLAG) /* there are no ERR frames with RTR */
129 sprintf(buf+offset, "R");
131 for (i = 0; i < dlc; i++) {
132 sprintf(buf+offset, "%02X", cf->data[i]);
134 if (sep && (i+1 < dlc))
135 sprintf(buf+offset++, ".");
139 static inline uint16_t frame_index(struct can_frame *frame)
142 if (frame->can_dlc >= 2) {
143 memcpy(&idx, frame->data, sizeof(idx));
144 if (idx >= MAX_INFOS)
145 error(1, 0, "%s idx too high", __FUNCTION__);
148 error(1, 0, "%s error", __FUNCTION__);
153 static inline struct msg_info *frame2info(struct can_frame *frame)
155 return &msg_infos[frame_index(frame)];
158 static inline char *tstamp_str(const void *ctx, struct timespec *tstamp)
160 return talloc_asprintf(ctx, "%ld.%06ld",
161 tstamp->tv_sec, tstamp->tv_nsec/1000);
164 void msg_info_print(FILE *f, struct msg_info *mi)
166 struct timespec diff;
167 void *local = talloc_new (NULL);
169 char sent[64], received[64];
174 sprint_canframe(sent, &mi->sent, true);
175 sprint_canframe(received, &mi->received, true);
177 #define S(ts) tstamp_str(local, &ts)
178 #define DIFF(a, b) (timespec_subtract(&diff, &b, &a), S(diff))
180 switch (num_interfaces) {
182 fprintf(f, "%ld: %s %s -> %s (%s) %s = %s (%s) %d\n",
183 num, S(mi->ts_sent), sent, S(mi->ts_rx_final_kern), S(mi->ts_rx_final), received,
184 DIFF(mi->ts_sent, mi->ts_rx_final_kern),
185 DIFF(mi->ts_sent, mi->ts_rx_final),
189 fprintf(f, "%ld: %s %s -> %s (%s) -> %s (%s) %s = %s (%s), %s (%s) %d\n",
190 num, S(mi->ts_sent), sent,
191 S(mi->ts_rx_onwire_kern), S(mi->ts_rx_onwire),
192 S(mi->ts_rx_final_kern), S(mi->ts_rx_final), received,
193 DIFF(mi->ts_sent, mi->ts_rx_onwire_kern),
194 DIFF(mi->ts_sent, mi->ts_rx_onwire),
195 DIFF(mi->ts_rx_onwire_kern, mi->ts_rx_final_kern),
196 DIFF(mi->ts_rx_onwire, mi->ts_rx_final),
206 /* Subtract the `struct timespec' values X and Y, storing the result in
207 RESULT. Return 1 if the difference is negative, otherwise 0. */
209 int timespec_subtract (struct timespec *result, struct timespec *x, struct timespec *yy)
211 struct timespec ylocal = *yy, *y = &ylocal;
212 /* Perform the carry for the later subtraction by updating Y. */
213 if (x->tv_nsec < y->tv_nsec) {
214 int nsec = (y->tv_nsec - x->tv_nsec) / 1000000000 + 1;
215 y->tv_nsec -= 1000000000 * nsec;
218 if (x->tv_nsec - y->tv_nsec > 1000000000) {
219 int nsec = (x->tv_nsec - y->tv_nsec) / 1000000000;
220 y->tv_nsec += 1000000000 * nsec;
224 /* Compute the time remaining to wait.
225 `tv_nsec' is certainly positive. */
226 result->tv_sec = x->tv_sec - y->tv_sec;
227 result->tv_nsec = x->tv_nsec - y->tv_nsec;
229 /* Return 1 if result is negative. */
230 return x->tv_sec < y->tv_sec;
233 void dbg_print_timespec(char *msg, struct timespec *tv)
236 printf("%s sec=%ld nsec=%ld\n", msg, tv->tv_sec, tv->tv_nsec);
239 static inline void calc_msg_latencies(struct msg_info *mi)
241 struct timespec diff;
242 switch (num_interfaces) {
245 timespec_subtract(&diff, &mi->ts_rx_final, &mi->ts_rx_onwire);
247 timespec_subtract(&diff, &mi->ts_rx_final_kern, &mi->ts_rx_onwire_kern);
251 timespec_subtract(&diff, &mi->ts_rx_final, &mi->ts_sent);
253 timespec_subtract(&diff, &mi->ts_rx_final_kern, &mi->ts_sent);
258 mi->lat_measured_us = diff.tv_sec * 1000000 + diff.tv_nsec/1000;
259 mi->tx_time_us = calc_frame_length(&mi->received);
262 void set_sched_policy_and_prio(int policy, int rtprio)
264 struct sched_param scheduling_parameters;
265 int maxprio=sched_get_priority_max(policy);
266 int minprio=sched_get_priority_min(policy);
268 if((rtprio < minprio) || (rtprio > maxprio))
269 error(1, 0, "The priority for requested policy is out of <%d, %d> range\n",
272 scheduling_parameters.sched_priority = rtprio;
274 if (0 != pthread_setschedparam(pthread_self(), policy, &scheduling_parameters))
275 error(1, errno, "pthread_setschedparam error");
278 void term_handler(int signum)
283 static inline int sock_get_if_index(int s, const char *if_name)
288 strcpy(ifr.ifr_name, if_name);
289 if (ioctl(s, SIOCGIFINDEX, &ifr) < 0)
290 error(1, errno, "SIOCGIFINDEX '%s'", if_name);
291 return ifr.ifr_ifindex;
294 static inline get_tstamp(struct timespec *ts)
296 clock_gettime(CLOCK_REALTIME, ts);
310 debugfs = "/sys/kernel/debug";
312 strcpy(path, debugfs);
313 strcat(path,"/tracing/tracing_on");
314 trace_fd = open(path, O_WRONLY);
316 write(trace_fd, "1", 1);
318 strcpy(path, debugfs);
319 strcat(path,"/tracing/trace_marker");
320 marker_fd = open(path, O_WRONLY);
322 strcpy(path, debugfs);
323 strcat(path,"/tracing/set_ftrace_pid");
324 f = fopen(path, "w");
325 fprintf(f, "%d\n", getpid());
327 system("echo function_graph > /sys/kernel/debug/tracing/current_tracer");
328 system("echo can_send > /sys/kernel/debug/tracing/set_graph_function");
329 system("echo > /sys/kernel/debug/tracing/trace");
330 system("echo 1 > /sys/kernel/debug/tracing/tracing_enabled");
335 static inline void trace_on()
338 write(trace_fd, "1", 1);
341 static inline void trace_off(int ret)
343 if (marker_fd >= 0) {
345 sprintf(marker, "write returned %d\n", ret);
346 write(marker_fd, marker, strlen(marker));
349 write(trace_fd, "0", 1);
352 static inline void msg_info_free(struct msg_info *mi)
357 static inline bool msg_info_used(struct msg_info *mi)
362 int send_frame(int socket)
364 struct can_frame frame;
367 static int curr_msg = -1;
373 while (msg_info_used(&msg_infos[i]) && i != curr_msg) {
379 error(1, 0, "Msg info table is full! Probably, many packets were lost.");
383 frame.can_id = opt.id;
385 error(1, 0, "Length < 2 is not yet supported");
386 frame.can_dlc = opt.length;
388 memcpy(frame.data, &idx, sizeof(idx));
389 mi = frame2info(&frame);
391 mi->id = frame.can_id;
392 mi->length = frame.can_dlc;
393 get_tstamp(&mi->ts_sent);
397 ret = write(socket, &frame, sizeof(frame));
400 if (ret == -1 || num_interfaces == 1)
405 static inline send_and_check(int s)
409 if (ret != sizeof(struct can_frame)) {
410 /* if (ret == -1 && errno == ENOBUFS && opt.period_us == 0 && !opt.oneattime) { */
411 /* stats.enobufs++; */
412 /* /\* Ignore this error - pfifo_fast qeuue is full *\/ */
414 error(1, errno, "send_frame (line %d)", __LINE__);
421 static inline void get_next_timeout(struct timespec *timeout)
424 static struct timespec last = {-1, 0 };
426 clock_gettime(CLOCK_MONOTONIC, &now);
428 if (last.tv_sec == -1)
430 if (opt.period_us != 0) {
431 last.tv_sec += opt.period_us/1000000;
432 last.tv_nsec += (opt.period_us%1000000)*1000;
433 while (last.tv_nsec >= 1000000000) {
434 last.tv_nsec -= 1000000000;
437 if (timespec_subtract(timeout, &last, &now) /* is negative */) {
439 memset(timeout, 0, sizeof(*timeout));
441 } else if (opt.timeout_ms != 0) {
442 timeout->tv_sec = opt.timeout_ms/1000;
443 timeout->tv_nsec = (opt.timeout_ms%1000)*1000000;
445 error(1, 0, "Timeout and period cannot be both zero");
448 void receive(int s, struct can_frame *frame, struct timespec *ts_kern, struct timespec *ts_user)
450 char ctrlmsg[CMSG_SPACE(sizeof(struct timeval)) + CMSG_SPACE(sizeof(__u32))];
453 struct cmsghdr *cmsg;
454 struct sockaddr_can addr;
456 static uint64_t dropcnt = 0;
458 iov.iov_base = frame;
459 msg.msg_name = &addr;
462 msg.msg_control = &ctrlmsg;
464 /* these settings may be modified by recvmsg() */
465 iov.iov_len = sizeof(*frame);
466 msg.msg_namelen = sizeof(addr);
467 msg.msg_controllen = sizeof(ctrlmsg);
470 nbytes = recvmsg(s, &msg, 0);
472 error(1, errno, "recvmsg");
474 if (nbytes < sizeof(struct can_frame))
475 error(1, 0, "recvmsg: incomplete CAN frame\n");
478 MEMSET_ZERO(*ts_kern);
479 for (cmsg = CMSG_FIRSTHDR(&msg);
480 cmsg && (cmsg->cmsg_level == SOL_SOCKET);
481 cmsg = CMSG_NXTHDR(&msg,cmsg)) {
482 if (cmsg->cmsg_type == SO_TIMESTAMPNS)
483 *ts_kern = *(struct timespec *)CMSG_DATA(cmsg);
484 else if (cmsg->cmsg_type == SO_RXQ_OVFL)
485 dropcnt += *(__u32 *)CMSG_DATA(cmsg);
490 void process_tx(int s)
492 error(1, 0, "%s: not implemented", __FUNCTION__);
495 void process_on_wire_rx(int s)
497 struct timespec ts_kern, ts_user, ts_diff;
498 struct can_frame frame;
500 receive(s, &frame, &ts_kern, &ts_user);
501 mi = frame2info(&frame);
502 if (msg_info_used(mi)) {
503 mi->ts_rx_onwire_kern = ts_kern;
504 mi->ts_rx_onwire = ts_user;
506 stats.invalid_frame++;
510 void process_final_rx(int s)
512 struct timespec ts_kern, ts_user, ts_diff;
513 struct can_frame frame;
517 receive(s, &frame, &ts_kern, &ts_user);
518 mi = frame2info(&frame);
519 mi->ts_rx_final_kern = ts_kern;
520 mi->ts_rx_final = ts_user;
521 mi->received = frame;
523 calc_msg_latencies(mi);
525 histogram_add(&histogram, mi->lat_measured_us);
526 histogram_add(&histogram_gw, mi->lat_measured_us - mi->tx_time_us);
528 ret = write(completion_pipe[1], &mi, sizeof(mi));
530 error(1, errno, "completion_pipe write");
533 void *measure_thread(void *arg)
536 struct pollfd pfd[3];
537 struct timespec timeout;
538 struct sockaddr_can addr;
540 int consecutive_timeouts = 0;
544 for (i=0; i<num_interfaces; i++) {
545 if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0)
546 error(1, errno, "socket");
548 addr.can_family = AF_CAN;
549 addr.can_ifindex = sock_get_if_index(s, opt.interface[i]);
551 if (i == 0) { /* TX socket */
552 /* disable default receive filter on this RAW socket */
553 /* This is obsolete as we do not read from the socket at all, but for */
554 /* this reason we can remove the receive list in the Kernel to save a */
555 /* little (really a very little!) CPU usage. */
556 if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0) == -1)
557 error(1, errno, "SOL_CAN_RAW");
560 if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0)
561 error(1, errno, "bind");
563 const int timestamp_on = 1;
564 if (setsockopt(s, SOL_SOCKET, SO_TIMESTAMPNS,
565 ×tamp_on, sizeof(timestamp_on)) < 0)
566 error(1, errno, "setsockopt SO_TIMESTAMP");
568 const int dropmonitor_on = 1;
569 if (setsockopt(s, SOL_SOCKET, SO_RXQ_OVFL,
570 &dropmonitor_on, sizeof(dropmonitor_on)) < 0)
571 error(1, errno, "setsockopt SO_RXQ_OVFL not supported by your Linux Kernel");
575 pfd[i].events = POLLIN | POLLERR | ((opt.period_us == 0 && !opt.oneattime) ? POLLOUT : 0);
577 pfd[i].events = POLLIN;
580 set_sched_policy_and_prio(SCHED_FIFO, 40);
582 #define SEND() send_and_check(pfd[0].fd)
587 get_tstamp(&stats.tic);
589 while (!finish_flag &&
590 (opt.count == 0 || count < opt.count || msg_in_progress != 0)) {
592 get_next_timeout(&timeout);
593 //printf("ppoll"); fflush(stdout);
594 ret = ppoll(pfd, num_interfaces, &timeout, NULL);
595 //printf("=%d\n", ret);
598 if (!INTERRUPTED_SYSCALL(errno))
599 error(1, errno, "ppoll");
603 if (opt.count == 0 || count < opt.count) {
607 /* Lost message - send a new one */
609 consecutive_timeouts++;
610 if (consecutive_timeouts < 10)
612 else /* Something is really broken */
617 if (pfd[0].revents & (POLLIN|POLLERR)) {
618 process_tx(pfd[0].fd);
620 if (pfd[0].revents & POLLOUT) {
621 if (opt.count == 0 || count < opt.count)
626 if (num_interfaces == 3 && pfd[1].revents & POLLIN) {
627 process_on_wire_rx(pfd[1].fd);
630 if (num_interfaces == 3 && pfd[1].revents & ~POLLIN)
631 error(1, 0, "Unexpected pfd[1].revents: 0x%04x\n", pfd[1].revents);
633 i = (num_interfaces == 2) ? 1 : 2;
634 if (pfd[i].revents & POLLIN) {
635 consecutive_timeouts = 0;
636 process_final_rx(pfd[i].fd);
639 if ((opt.count == 0 || count < opt.count) &&
644 if (pfd[i].revents & ~POLLIN)
645 error(1, 0, "Unexpected pfd[%d].revents: 0x%04x\n", pfd[i].revents);
649 get_tstamp(&stats.tac);
651 for (i=0; i<num_interfaces; i++)
657 struct poptOption optionsTable[] = {
658 { "device", 'd', POPT_ARG_ARGV, &opt.interface, 'd', "Interface to use. Must be given two times (tx, rx) or three times (tx, rx1, rx2)", "interface" },
659 { "count", 'c', POPT_ARG_INT|POPT_ARGFLAG_SHOW_DEFAULT, &opt.count, 0, "The count of messages to send, zero corresponds to infinity", "num"},
660 { "id", 'i', POPT_ARG_INT|POPT_ARGFLAG_SHOW_DEFAULT, &opt.id, 0, "CAN ID of sent messages", "id"},
661 { "period", 'p', POPT_ARG_INT|POPT_ARGFLAG_SHOW_DEFAULT, &opt.period_us, 0, "Period for sending messages or zero (default) to send as fast as possible", "us"},
662 { "timeout",'t', POPT_ARG_INT|POPT_ARGFLAG_SHOW_DEFAULT, &opt.timeout_ms,0, "Timeout when period is zero", "ms"},
663 { "oneattime",'o', POPT_ARG_NONE, &opt.oneattime,0, "Send the next message only when the previous was finally received"},
664 { "verbose",'v', POPT_ARG_NONE, NULL, 'v', "Send the next message only when the previous was finally received"},
665 { "name", 'n', POPT_ARG_STRING, &opt.name, 0, "Prefix of the generated files"},
666 { "length", 'l', POPT_ARG_INT|POPT_ARGFLAG_SHOW_DEFAULT, &opt.length, 0, "The length of generated messages", "bytes"},
667 { "userhist", 'u', POPT_ARG_NONE, &opt.userhist, 0, "Generate histogram from userspace timestamps"},
668 { "quiet", 'q', POPT_ARG_NONE, &opt.quiet, 0, "Do not print progress and statistics"},
670 { NULL, 0, 0, NULL, 0 }
673 int parse_options(int argc, const char *argv[])
676 poptContext optCon; /* context for parsing command-line options */
677 void *local = talloc_new (NULL);
679 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
680 //poptSetOtherOptionHelp(optCon, "[OPTIONS]* <port>");
682 /* Now do options processing */
683 while ((c = poptGetNextOpt(optCon)) >= 0) {
691 error(1, 0, "%s: %s\n",
692 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
695 if (num_interfaces < 1 || num_interfaces > 3)
696 error(1, 0, "-d option must only be given one, two or three times");
698 if (opt.oneattime && opt.period_us)
699 error(1, 0, "oneattime and period cannot be specified at the same time");
702 char *f = talloc_asprintf(local, "%s-msgs.txt", opt.name);
703 opt.f_msgs = fopen(f, "w");
705 error(1, errno, "fopen: %s", f);
709 char *f = talloc_asprintf(local, "%s-hist-raw.txt", opt.name);
710 opt.f_hist = fopen(f, "w");
712 error(1, errno, "fopen: %s", f);
716 char *f = talloc_asprintf(local, "%s-hist.txt", opt.name);
717 opt.f_hist_gw = fopen(f, "w");
719 error(1, errno, "fopen: %s", f);
723 char *f = talloc_asprintf(local, "%s-stat.txt", opt.name);
724 opt.f_stat = fopen(f, "w");
726 error(1, errno, "fopen: %s", f);
729 poptFreeContext(optCon);
734 void print_progress()
737 if (num_interfaces > 1)
738 printf("\rSent %5d, in progress %5d", count, msg_in_progress);
740 printf("\rSent %5d", count);
745 int main(int argc, const char *argv[])
751 parse_options(argc, argv);
753 mlockall(MCL_CURRENT | MCL_FUTURE);
755 signal(SIGINT, term_handler);
756 signal(SIGTERM, term_handler);
758 for (i=0; i<MAX_INFOS; i++)
759 msg_infos[i].id = -1;
761 histogram_init(&histogram, 5000000, 1);
762 histogram_init(&histogram_gw, 5000000, 1);
764 ret = pipe(completion_pipe);
766 error(1, errno, "pipe");
767 ret = fcntl(completion_pipe[1], F_SETFL, O_NONBLOCK);
769 error(1, errno, "pipe fcntl");
772 if (getenv("LATESTER_CONTROL_HACKBENCH")) {
774 sprintf(cmd, "ssh -x -a -S $HOME/.ssh/cangw-connection root@192.168.2.3 'kill -CONT -%s'",
775 getenv("LATESTER_CONTROL_HACKBENCH"));
776 printf("Running: %s\n", cmd);
780 pthread_create(&thread, 0, measure_thread, NULL);
782 struct timespec next, now, diff, allsent = {0,0};
783 clock_gettime(CLOCK_MONOTONIC, &next);
785 while (!finish_flag && (opt.count == 0 || completed < opt.count)) {
786 struct pollfd pfd[1];
787 pfd[0].fd = completion_pipe[0];
788 pfd[0].events = POLLIN;
789 ret = poll(pfd, 1, 100);
790 if (ret == -1 && !INTERRUPTED_SYSCALL(errno))
791 error(1, errno, "poll main");
792 if (ret > 0 && (pfd[0].revents & POLLIN)) {
795 ret = read(completion_pipe[0], &mi, sizeof(mi));
796 if (ret < sizeof(mi))
797 error(1, errno, "read completion returned %d", ret);
798 msg_info_print(opt.f_msgs, mi);
803 clock_gettime(CLOCK_MONOTONIC, &now);
804 if (timespec_subtract(&diff, &next, &now)) {
806 next.tv_nsec += 100000000;
807 while (next.tv_nsec >= 1000000000) {
808 next.tv_nsec -= 1000000000;
812 if (opt.count != 0 && count >= opt.count) {
813 if (allsent.tv_sec == 0)
815 timespec_subtract(&diff, &now, &allsent);
816 if (diff.tv_sec >= 1)
824 stats.lost = msg_in_progress;
826 pthread_join(thread, NULL);
828 if (getenv("LATESTER_CONTROL_HACKBENCH")) {
830 sprintf(cmd, "ssh -x -a -S $HOME/.ssh/cangw-connection root@192.168.2.3 'kill -STOP -%s'",
831 getenv("LATESTER_CONTROL_HACKBENCH"));
832 printf("Running: %s\n", cmd);
836 close(completion_pipe[0]);
837 close(completion_pipe[1]);
839 histogram_fprint(&histogram, opt.f_hist);
840 histogram_fprint(&histogram_gw, opt.f_hist_gw);
844 fclose(opt.f_hist_gw);
849 fprintf(opt.f_stat, "cmdline='");
850 for (i=0; i<argc; i++)
851 fprintf(opt.f_stat, "%s%s", argv[i], i < argc-1 ? " " : "");
852 fprintf(opt.f_stat, "'\n");
854 timespec_subtract(&diff, &stats.tac, &stats.tic);
855 fprintf(opt.f_stat, "duration=%s # seconds\n", tstamp_str(NULL, &diff));
857 fprintf(opt.f_stat, "sent=%d\n", count);
858 fprintf(opt.f_stat, "overrun=%d\n", stats.overrun);
859 if (stats.overrun && !opt.quiet)
860 printf("overrun=%d\n", stats.overrun);
861 fprintf(opt.f_stat, "enobufs=%d\n", stats.enobufs);
862 if (stats.enobufs && !opt.quiet)
863 printf("enobufs=%d\n", stats.enobufs);
864 fprintf(opt.f_stat, "lost=%d\n", stats.lost);
865 if (stats.lost && !opt.quiet)
866 printf("lost=%d\n", stats.lost);
867 fprintf(opt.f_stat, "timeouts=%d\n", stats.timeouts);
868 if (stats.timeouts && !opt.quiet)
869 printf("timeouts=%d\n", stats.timeouts);
870 fprintf(opt.f_stat, "invalid_frame=%d\n", stats.timeouts);
871 if (stats.timeouts && !opt.quiet)
872 printf("invalid_frame=%d\n", stats.timeouts);