From: Michal Sojka Date: Thu, 9 Dec 2010 17:04:16 +0000 (+0100) Subject: All output files have the same prefix X-Git-Tag: fix-allnoconfig~233^2~24 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/can-benchmark.git/commitdiff_plain/9c7f01f350147569783a77597f38facc70580aed All output files have the same prefix --- diff --git a/latester/latester.c b/latester/latester.c index 619c258..a25fd10 100644 --- a/latester/latester.c +++ b/latester/latester.c @@ -59,10 +59,16 @@ struct options { unsigned timeout_ms; unsigned count; unsigned oneattime; - FILE *file; - FILE *histogram; + char *name; + int histogram; + int file; int length; int userhist; + + /* Temporary variables */ + FILE *f_msgs; + FILE *f_hist; + FILE *f_stat; }; struct options opt = { @@ -627,8 +633,9 @@ 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"}, + { "file", 'f', POPT_ARG_NONE, &opt.file, 0, "Store all message data in a file", "filename"}, + { "histogram", 'h', POPT_ARG_NONE, &opt.histogram, 0, "Store histogram in file", "filename"}, { "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 +646,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]* "); @@ -649,16 +657,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 +670,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 && opt.file) { + 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 && opt.histogram) { + 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; } @@ -731,7 +750,7 @@ int main(int argc, const char *argv[]) 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++; } @@ -764,18 +783,25 @@ int main(int argc, const char *argv[]) close(completion_pipe[1]); if (opt.histogram) { - histogram_fprint(&histogram, opt.histogram); - fclose(opt.histogram); + histogram_fprint(&histogram, opt.f_hist); + fclose(opt.f_hist); } if (opt.file) - fclose(opt.file); + 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; }