From ee57a3c105f8367c93912039e7ddb0548ef46eb7 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Tue, 23 Jan 2018 09:33:10 +0100 Subject: [PATCH] logsend: send each message multiple times; print statistics This commit adds two simple features: 1. Sending each message multiple times. This is aimed to help with testing dlog performance; 2. Printing statistics. Prints time taken by each sending operation. Change-Id: I1c1dc935ea93e7e1ea9aa5cbbc5c4399c2efb171 --- src/logsend/logsend.c | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/src/logsend/logsend.c b/src/logsend/logsend.c index 560d241..4ce5e11 100644 --- a/src/logsend/logsend.c +++ b/src/logsend/logsend.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -9,9 +10,11 @@ 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) @@ -21,7 +24,7 @@ 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; @@ -38,6 +41,12 @@ void parse_options(int argc, const char **argv, struct parsed_params *params) case 'h': params->help = 1; return; + case 'c': + params->count = atoi(optarg); + break; + case 's': + params->print_stats = true; + break; default: break; } @@ -51,12 +60,26 @@ void parse_options(int argc, const char **argv, struct parsed_params *params) 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); } } @@ -73,14 +96,18 @@ void print_help(const char *progname) { 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); } @@ -91,7 +118,9 @@ int main(int argc, const char **argv) .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) { -- 2.7.4