#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <dlog.h>
#include <logcommon.h>
struct parsed_params {
log_id_t buffer;
log_priority priority;
- int help;
+ int help;
const char *tag;
char *msg;
+ unsigned count;
+ bool print_stats;
};
void parse_options(int argc, const char **argv, struct parsed_params *params)
assert(!params->msg);
for (;;) {
- int opt = getopt(argc, (char **) argv, "b:p:t:h");
+ int opt = getopt(argc, (char **) argv, "b:p:t:hc:s");
if (opt < 0)
break;
case 'h':
params->help = 1;
return;
+ case 'c':
+ params->count = atoi(optarg);
+ break;
+ case 's':
+ params->print_stats = true;
+ break;
default:
break;
}
void send_log(struct parsed_params *params)
{
+ unsigned i;
+ struct timespec start, end;
+
assert(params);
- dlog_error_e ret = __dlog_print(params->buffer, params->priority, params->tag, "%s", params->msg);
- if (ret != DLOG_ERROR_NONE) {
- // Ignore for now because the API does not actually return DLOG_ERROR_NONE on success.
- // printf("Log #%d: error %d\n", i, ret);
+ if (params->print_stats) {
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ }
+
+ for (i = 0; i < params->count; ++i) {
+ dlog_error_e ret = __dlog_print(params->buffer, params->priority, params->tag, "%s", params->msg);
+ if (ret != DLOG_ERROR_NONE) {
+ // Ignore for now because the API does not actually return DLOG_ERROR_NONE on success.
+ // printf("Log #%d: error %d\n", i, ret);
+ }
+ }
+
+ if (params->print_stats) {
+ clock_gettime(CLOCK_MONOTONIC, &end);
+ printf("Sending log took %ld us\n", (end.tv_sec - start.tv_sec)*1000000 + (end.tv_nsec - start.tv_nsec) / 1000);
}
}
{
assert(progname);
- printf("Usage: %s [-p priority] [-b buffer] [-t tag] message\n"
+ printf("Usage: %s [-p priority] [-b buffer] [-t tag] [-c number] [-s] [message]\n"
"\t-p priority \tone of {Debug, Info, Warning, Error, Verbose, Fatal}\n"
"\t \tfirst letter is enough; defaults to Info\n"
"\t-b buffer \tone of {main, system, radio, apps, kmsg, syslog}\n"
"\t \tdefaults to main\n"
"\t-t tag \ta short identification string for identification and filtering purposes\n"
"\t \tcan be anything, defaults to DLOG_SEND\n"
- "\t-h \tshow this help\n",
+ "\t-c number \tspecify how many times each message should be logged\n"
+ "\t-s \tcollect and print statistics\n"
+ "\t-h \tshow this help\n"
+ "\tmessage \tmessage for logging; if not specified, each line from standard input\n"
+ "\t \tis logged separately until EOF\n",
progname);
}
.priority = DLOG_INFO,
.help = 0,
.tag = "DLOG_SEND",
- .msg = NULL
+ .msg = NULL,
+ .count = 1,
+ .print_stats = false
};
parse_options(argc, argv, ¶ms);
if (!params.msg) {