This is an automated email from the ASF dual-hosted git repository. jerzy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 0645b3deec84efe146bf0c1227f7ec4cc7f5da53 Author: Jerzy Kasenberg <[email protected]> AuthorDate: Mon Aug 5 14:36:12 2024 +0200 sys/log: Add option to limit number of printed logs Option -s allows to skip number of logs from the start Usage: log [-n <number>] [-s <skip_number> ] i.e.: log -s 100 -n 10 will print at most 10 entries from each log skipping first 100 entries Signed-off-by: Jerzy Kasenberg <[email protected]> --- sys/log/full/src/log_shell.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c index 0de60d776..e252d33f8 100644 --- a/sys/log/full/src/log_shell.c +++ b/sys/log/full/src/log_shell.c @@ -43,7 +43,11 @@ static uint32_t shell_log_count; struct walk_arg { + /* Number of entries to skip */ + uint32_t skip; + /* Number of entries to process */ uint32_t count_limit; + /* Entry number */ uint32_t count; }; @@ -56,7 +60,7 @@ shell_log_count_entry(struct log *log, struct log_offset *log_offset, shell_log_count++; if (arg) { arg->count++; - if (arg->count >= arg->count_limit) { + if ((arg->count_limit > 0) && (arg->count >= arg->count_limit)) { return 1; } } @@ -81,6 +85,14 @@ shell_log_dump_entry(struct log *log, struct log_offset *log_offset, bool read_data = ueh->ue_etype != LOG_ETYPE_CBOR; bool read_hash = ueh->ue_flags & LOG_FLAGS_IMG_HASH; + if (arg) { + arg->count++; + /* Continue walk if number of entries to skip not reached yet */ + if (arg->count <= arg->skip) { + return 0; + } + } + dlen = min(len, 128); if (read_data) { @@ -125,8 +137,7 @@ shell_log_dump_entry(struct log *log, struct log_offset *log_offset, console_write("\n", 1); if (arg) { - arg->count++; - if (arg->count >= arg->count_limit) { + if ((arg->count_limit > 0) && (arg->count - arg->skip >= arg->count_limit)) { return 1; } } @@ -137,7 +148,7 @@ int shell_log_dump_cmd(int argc, char **argv) { struct log *log; - struct log_offset log_offset; + struct log_offset log_offset = {}; bool list_only = false; char *log_name = NULL; uint32_t log_last_index = 0; @@ -167,6 +178,17 @@ shell_log_dump_cmd(int argc, char **argv) ++i; continue; } + if (0 == strcmp(argv[i], "-s")) { + if (i + 1 < argc) { + arg.skip = parse_ll_bounds(argv[i + 1], 0, 1000000, &rc); + if (rc) { + arg.skip = 0; + } + log_offset.lo_arg = &arg; + } + ++i; + continue; + } if (0 == strcmp(argv[i], "-t")) { dump_logs = false; continue; @@ -221,7 +243,6 @@ shell_log_dump_cmd(int argc, char **argv) console_printf("Dumping log %s\n", log->l_name); } - log_offset.lo_arg = NULL; log_offset.lo_ts = 0; log_last_index = log_get_last_index(log); if (log_limit == 0 || log_last_index < log_limit) { @@ -232,6 +253,7 @@ shell_log_dump_cmd(int argc, char **argv) log_offset.lo_data_len = 0; if (dump_logs) { + arg.count = 0; rc = log_walk_body(log, shell_log_dump_entry, &log_offset); } else { /* Measure time for log_walk */
