]> rtime.felk.cvut.cz Git - can-benchmark.git/blobdiff - recvmmsg/can_recvmmsg.c
Add scripts for running the benchmark on PowerPC
[can-benchmark.git] / recvmmsg / can_recvmmsg.c
index 4041f62fbd72da9d325d712a963a908b9802c863..4dee5f1326d7b2bd39f16eed06d8e252364a4616 100644 (file)
 #include <stdlib.h>
 #include <stdio.h>
 #include <time.h>
+#include <stdbool.h>
 
 #define CHECK(cmd) do { if ((cmd) == -1) { perror(#cmd); exit(1); } } while (0)
 
 char *dev = "vcan0";
 int count = 10000;
 enum { READ, RECVMMSG } recv_method = READ;
+bool quiet = false;
 
 /* Subtract the `struct timespec' values X and Y,
    storing the result in RESULT (result = x - y).
@@ -79,7 +81,7 @@ void benchmark()
        memset(&cf, 0, sizeof(cf));
        cf.can_dlc = 8;
 
-       fprintf(stderr, "Sending %d frames\n", count);
+       if (!quiet) fprintf(stderr, "Sending %d frames\n", count);
        for (i = 0; i < count; i++) {
                ret = write(ss, &cf, sizeof(cf));
                if (ret != sizeof(cf)) {
@@ -90,7 +92,7 @@ void benchmark()
 
        switch (recv_method) {
        case READ: {
-               fprintf(stderr, "Receiving %d frames with read()\n", count);
+               if (!quiet) fprintf(stderr, "Receiving %d frames with read()\n", count);
                clock_gettime(CLOCK_MONOTONIC, &t1);
                for (i = 0; i < count; i++) {
                        //fprintf(stderr, "Receiving frame %d\r", i);
@@ -105,7 +107,7 @@ void benchmark()
                break;
        }
        case RECVMMSG: {
-               fprintf(stderr, "Receiving %d frames with recvmmsg()\n", count);
+               if (!quiet) fprintf(stderr, "Receiving %d frames with recvmmsg()\n", count);
                struct mmsghdr msgs[count];
                struct iovec iovecs[count];
                char bufs[count][sizeof(struct can_frame)];
@@ -139,7 +141,7 @@ int main(int argc, char *argv[])
 {
        int opt;
 
-       while ((opt = getopt(argc, argv, "c:mr")) != -1) {
+       while ((opt = getopt(argc, argv, "c:mrq")) != -1) {
                switch (opt) {
                case 'c':
                        count = atoi(optarg);
@@ -150,6 +152,9 @@ int main(int argc, char *argv[])
                case 'r':
                        recv_method = READ;
                        break;
+               case 'q':
+                       quiet = true;
+                       break;
                default: /* '?' */
                        fprintf(stderr, "Usage: %s [-c <count>] [-r] [-m]  [interface]\n",
                                argv[0]);