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 = {
{ "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
{
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>");
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)
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;
}
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++;
}
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;
}