]> rtime.felk.cvut.cz Git - can-benchmark.git/blobdiff - latester/latester.c
Generate files without switches and update strips
[can-benchmark.git] / latester / latester.c
index 619c2582838a59a86959dd035b16485c4597d383..6a78872afeb1ebd25e627485d6713cb0594c8296 100644 (file)
@@ -59,10 +59,14 @@ struct options {
        unsigned timeout_ms;
        unsigned count;
        unsigned oneattime;
-       FILE *file;
-       FILE *histogram;
+       char *name;
        int length;
        int userhist;
+
+       /* Temporary variables */
+       FILE *f_msgs;
+       FILE *f_hist;
+       FILE *f_stat;
 };
 
 struct options opt = {
@@ -503,8 +507,7 @@ void process_final_rx(int s)
        mi->ts_rx_final = ts_user;
        mi->received = frame;
 
-       if (opt.histogram)
-               histogram_add(&histogram, get_msg_latency_us(mi));
+       histogram_add(&histogram, get_msg_latency_us(mi));
 
        ret = write(completion_pipe[1], &mi, sizeof(mi));
        if (ret == -1)
@@ -627,8 +630,7 @@ struct poptOption optionsTable[] = {
        { "timeout",'t', POPT_ARG_INT|POPT_ARGFLAG_SHOW_DEFAULT,  &opt.timeout_ms,0, "Timeout when period is zero", "ms"},
        { "oneattime",'o', POPT_ARG_NONE,                         &opt.oneattime,0,  "Send the next message only when the previous was finally received"},
        { "verbose",'v', POPT_ARG_NONE,                           NULL, 'v',         "Send the next message only when the previous was finally received"},
-       { "file",   'f', POPT_ARG_STRING,                         NULL, 'f',         "File where to store results", "filename"},
-       { "histogram", 'h', POPT_ARG_STRING,                      NULL, 'h',         "Store histogram in file", "filename"},
+       { "name",   'n', POPT_ARG_STRING,                         &opt.name, 0,      "Prefix of the generated files"},
        { "length", 'l', POPT_ARG_INT|POPT_ARGFLAG_SHOW_DEFAULT,  &opt.length, 0,    "The length of generated messages", "bytes"},
        { "userhist", 'u', POPT_ARG_NONE,                         &opt.userhist, 0,  "Generate histogram from userspace timestamps"},
        POPT_AUTOHELP
@@ -639,6 +641,7 @@ int parse_options(int argc, const char *argv[])
 {
        int c;
        poptContext optCon;   /* context for parsing command-line options */
+       void *local = talloc_new (NULL);
 
        optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
        //poptSetOtherOptionHelp(optCon, "[OPTIONS]* <port>");
@@ -649,16 +652,6 @@ int parse_options(int argc, const char *argv[])
                case 'd':
                        num_interfaces++;
                        break;
-               case 'f':
-                       opt.file = fopen(poptGetOptArg(optCon), "w");
-                       if (!opt.file)
-                               error(1, errno, "fopen: %s", poptGetOptArg(optCon));
-                       break;
-               case 'h':
-                       opt.histogram = fopen(poptGetOptArg(optCon), "w");
-                       if (!opt.histogram)
-                               error(1, errno, "fopen: %s", poptGetOptArg(optCon));
-                       break;
                }
        }
        if (c < -1)
@@ -672,8 +665,29 @@ int parse_options(int argc, const char *argv[])
        if (opt.oneattime && opt.period_us)
                error(1, 0, "oneattime and period cannot be specified at the same time");
 
-       poptFreeContext(optCon);
+       if (opt.name) {
+               char *f = talloc_asprintf(local, "%s-msgs.txt", opt.name);
+               opt.f_msgs = fopen(f, "w");
+               if (!opt.f_msgs)
+                       error(1, errno, "fopen: %s", f);
+       }
+
+       if (opt.name) {
+               char *f = talloc_asprintf(local, "%s-hist.txt", opt.name);
+               opt.f_hist = fopen(f, "w");
+               if (!opt.f_hist)
+                       error(1, errno, "fopen: %s", f);
+       }
+
+       if (opt.name) {
+               char *f = talloc_asprintf(local, "%s-stat.txt", opt.name);
+               opt.f_stat = fopen(f, "w");
+               if (!opt.f_stat)
+                       error(1, errno, "fopen: %s", f);
+       }
 
+       poptFreeContext(optCon);
+       talloc_free(local);
        return 0;
 }
 
@@ -699,9 +713,7 @@ int main(int argc, const char *argv[])
        for (i=0; i<MAX_INFOS; i++)
                msg_infos[i].id = -1;
 
-       if (opt.histogram) {
-               histogram_init(&histogram, 5000000, 1);
-       }
+       histogram_init(&histogram, 5000000, 1);
 
        ret = pipe(completion_pipe);
        if (ret == -1)
@@ -730,8 +742,7 @@ int main(int argc, const char *argv[])
                        ret = read(completion_pipe[0], &mi, sizeof(mi));
                        if (ret < sizeof(mi))
                                error(1, errno, "read completion returned %d", ret);
-                       if (opt.file)
-                               msg_info_print(opt.file, mi);
+                       msg_info_print(opt.f_msgs, mi);
                        msg_info_free(mi);
                        completed++;
                }
@@ -763,19 +774,23 @@ int main(int argc, const char *argv[])
        close(completion_pipe[0]);
        close(completion_pipe[1]);
 
-       if (opt.histogram) {
-               histogram_fprint(&histogram, opt.histogram);
-               fclose(opt.histogram);
-       }
-       if (opt.file)
-               fclose(opt.file);
+       histogram_fprint(&histogram, opt.f_hist);
+       fclose(opt.f_hist);
+       fclose(opt.f_msgs);
 
+       
+       fprintf(opt.f_stat, "sent=%d\n", count);
+       fprintf(opt.f_stat, "overrun=%d\n", stats.overrun);
        if (stats.overrun)
                printf("overrun=%d\n", stats.overrun);
+       fprintf(opt.f_stat, "enobufs=%d\n", stats.enobufs);
        if (stats.enobufs)
                printf("enobufs=%d\n", stats.enobufs);
+       fprintf(opt.f_stat, "lost=%d\n", stats.lost);
        if (stats.lost)
                printf("lost=%d\n", stats.lost);
 
+       fclose(opt.f_stat);
+
        return 0;
 }