You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2024/09/06 12:46:53 UTC

(mynewt-core) branch master updated (ddae64e9b -> 23b6eeb32)

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


    from ddae64e9b kernel/os: Fix msys allocation with multiply mpools
     new 652ee5239 sys/log: Add timing option to log command
     new 97a90d557 sys/log: Add log-fill command
     new 23b6eeb32 sys/log: Add option to limit number of printed logs

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 sys/log/full/pkg.yml         |   3 ++
 sys/log/full/src/log_shell.c | 112 +++++++++++++++++++++++++++++++++++++++++--
 sys/log/full/syscfg.yml      |   4 ++
 3 files changed, 115 insertions(+), 4 deletions(-)


(mynewt-core) 03/03: sys/log: Add option to limit number of printed logs

Posted by je...@apache.org.
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 23b6eeb325cd922f1e65825ea7ac0647635062ad
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Mon Aug 5 14:36:12 2024 +0200

    sys/log: Add option to limit number of printed logs
    
    This adds -n option that can be used to specify number of
    logs to print with log command.
    
    Usage:
    log -n <number>
    
    i.e.:
    log -n 10
    
    will print at most 10 entries from each log
    
    Signed-off-by: Jerzy Kasenberg <je...@codecoup.pl>
---
 sys/log/full/src/log_shell.c | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c
index a1d446c7e..0de60d776 100644
--- a/sys/log/full/src/log_shell.c
+++ b/sys/log/full/src/log_shell.c
@@ -41,11 +41,26 @@
 
 static uint32_t shell_log_count;
 
+
+struct walk_arg {
+    uint32_t count_limit;
+    uint32_t count;
+};
+
 static int
 shell_log_count_entry(struct log *log, struct log_offset *log_offset,
                       const struct log_entry_hdr *ueh, const void *dptr, uint16_t len)
 {
+    struct walk_arg *arg = (struct walk_arg *)log_offset->lo_arg;
+
     shell_log_count++;
+    if (arg) {
+        arg->count++;
+        if (arg->count >= arg->count_limit) {
+            return 1;
+        }
+    }
+
     return 0;
 }
 
@@ -59,6 +74,7 @@ shell_log_dump_entry(struct log *log, struct log_offset *log_offset,
     struct CborParser cbor_parser;
     struct CborValue cbor_value;
     struct log_cbor_reader cbor_reader;
+    struct walk_arg *arg = (struct walk_arg *)log_offset->lo_arg;
     char tmp[32 + 1];
     int off;
     int blksz;
@@ -108,6 +124,12 @@ 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) {
+            return 1;
+        }
+    }
     return 0;
 }
 
@@ -124,6 +146,7 @@ shell_log_dump_cmd(int argc, char **argv)
     bool partial_match = false;
     bool clear_log;
     bool dump_logs = true;
+    struct walk_arg arg = {};
     int i;
     int rc;
 
@@ -133,6 +156,17 @@ shell_log_dump_cmd(int argc, char **argv)
             list_only = true;
             break;
         }
+        if (0 == strcmp(argv[i], "-n")) {
+            if (i + 1 < argc) {
+                arg.count_limit = parse_ll_bounds(argv[i + 1], 1, 1000000, &rc);
+                if (rc) {
+                    arg.count_limit = 1;
+                }
+                log_offset.lo_arg = &arg;
+            }
+            ++i;
+            continue;
+        }
         if (0 == strcmp(argv[i], "-t")) {
             dump_logs = false;
             continue;
@@ -241,8 +275,10 @@ shell_log_storage_cmd(int argc, char **argv)
         if (log_storage_info(log, &info)) {
             console_printf("Storage info not supported for %s\n", log->l_name);
         } else {
-            console_printf("%s: %d of %d used\n", log->l_name,
-                           (unsigned)info.used, (unsigned)info.size);
+            uint32_t entry_count = 0;
+            log_get_entry_count(log, &entry_count);
+            console_printf("%s: %d of %d used; %d entries\n", log->l_name,
+                           (unsigned)info.used, (unsigned)info.size, (int)entry_count);
 #if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
             console_printf("%s: %d of %d used by unread entries\n", log->l_name,
                            (unsigned)info.used_unread, (unsigned)info.size);


(mynewt-core) 02/03: sys/log: Add log-fill command

Posted by je...@apache.org.
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 97a90d5573e3939d97dfea5b3f5f9d8e10164972
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Jul 31 19:38:02 2024 +0200

    sys/log: Add log-fill command
    
    This adds log-fill command to the log cli.
    It allows to fill specific log with auto generated logs.
    usage:
    
    log-fill <count> [<log name>]
    
    i.e.:
    
    log-fill 1000 reboot_log
    
    Command is added when syscfg value LOG_CLI_FILL_CMD is set
    
    Signed-off-by: Jerzy Kasenberg <je...@codecoup.pl>
---
 sys/log/full/pkg.yml         |  3 +++
 sys/log/full/src/log_shell.c | 41 +++++++++++++++++++++++++++++++++++++++++
 sys/log/full/syscfg.yml      |  4 ++++
 3 files changed, 48 insertions(+)

diff --git a/sys/log/full/pkg.yml b/sys/log/full/pkg.yml
index c8b8b0abf..fe6f8c8b2 100644
--- a/sys/log/full/pkg.yml
+++ b/sys/log/full/pkg.yml
@@ -65,3 +65,6 @@ pkg.req_apis.LOG_STATS:
 
 pkg.init:
     log_init: 'MYNEWT_VAL(LOG_SYSINIT_STAGE_MAIN)'
+
+pkg.init.LOG_CLI_FILL_CMD:
+    shell_log_fill_register: $after:shell_init
diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c
index 0f0036e16..a1d446c7e 100644
--- a/sys/log/full/src/log_shell.c
+++ b/sys/log/full/src/log_shell.c
@@ -254,4 +254,45 @@ shell_log_storage_cmd(int argc, char **argv)
 }
 #endif
 
+static int
+log_fill_command(int argc, char **argv)
+{
+    const char *log_name;
+    struct log *log;
+    int num = 1;
+
+    if (argc > 2) {
+        log_name = argv[2];
+        log = log_find(log_name);
+    } else {
+        log = log_list_get_next(NULL);
+    }
+    if (log == NULL) {
+        console_printf("No log to fill\n");
+        return -1;
+    }
+    if (argc > 1) {
+        num = atoi(argv[1]);
+        if (num <= 0 || num > 10000) {
+            num = 1;
+        }
+    }
+
+    for (int i = 0; i < num; ++i) {
+        log_printf(log, MODLOG_MODULE_DFLT, LOG_LEVEL_INFO, "Log os_time %d", (int)os_time_get());
+    }
+
+    return 0;
+}
+
+static struct shell_cmd log_fill_cmd = {
+    .sc_cmd = "log-fill",
+    .sc_cmd_func = log_fill_command
+};
+
+void
+shell_log_fill_register(void)
+{
+    shell_cmd_register(&log_fill_cmd);
+}
 #endif
diff --git a/sys/log/full/syscfg.yml b/sys/log/full/syscfg.yml
index 91709976f..d48ae9703 100644
--- a/sys/log/full/syscfg.yml
+++ b/sys/log/full/syscfg.yml
@@ -85,6 +85,10 @@ syscfg.defs:
         restrictions:
             - SHELL_TASK
 
+    LOG_CLI_FILL_CMD:
+        description: 'Add "log-fill" command for filling up log'
+        value: 0
+
     LOG_SHELL_SHOW_INDEX:
         description: '"log" command shows log index when dumping entries'
         value: 0


(mynewt-core) 01/03: sys/log: Add timing option to log command

Posted by je...@apache.org.
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 652ee523942f33dca599fff93bf4373d3ec0c775
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Tue Jun 25 12:28:01 2024 +0200

    sys/log: Add timing option to log command
    
    Shell command log now has additional parameter -t
    that allows to measure time for log traversal
    
    Signed-off-by: Jerzy Kasenberg <je...@codecoup.pl>
---
 sys/log/full/src/log_shell.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c
index 5c2a1c00b..0f0036e16 100644
--- a/sys/log/full/src/log_shell.c
+++ b/sys/log/full/src/log_shell.c
@@ -39,6 +39,16 @@
 #include "tinycbor/compilersupport_p.h"
 #include "log_cbor_reader/log_cbor_reader.h"
 
+static uint32_t shell_log_count;
+
+static int
+shell_log_count_entry(struct log *log, struct log_offset *log_offset,
+                      const struct log_entry_hdr *ueh, const void *dptr, uint16_t len)
+{
+    shell_log_count++;
+    return 0;
+}
+
 static int
 shell_log_dump_entry(struct log *log, struct log_offset *log_offset,
                      const struct log_entry_hdr *ueh, const void *dptr, uint16_t len)
@@ -113,6 +123,7 @@ shell_log_dump_cmd(int argc, char **argv)
     bool stream;
     bool partial_match = false;
     bool clear_log;
+    bool dump_logs = true;
     int i;
     int rc;
 
@@ -122,6 +133,10 @@ shell_log_dump_cmd(int argc, char **argv)
             list_only = true;
             break;
         }
+        if (0 == strcmp(argv[i], "-t")) {
+            dump_logs = false;
+            continue;
+        }
 
         /* the -c option is to clear a log (or logs). */
         if (!strcmp(argv[i], "-c")) {
@@ -168,7 +183,9 @@ shell_log_dump_cmd(int argc, char **argv)
                 goto err;
             }
         } else {
-            console_printf("Dumping log %s\n", log->l_name);
+            if (dump_logs) {
+                console_printf("Dumping log %s\n", log->l_name);
+            }
 
             log_offset.lo_arg = NULL;
             log_offset.lo_ts = 0;
@@ -180,7 +197,17 @@ shell_log_dump_cmd(int argc, char **argv)
             }
             log_offset.lo_data_len = 0;
 
-            rc = log_walk_body(log, shell_log_dump_entry, &log_offset);
+            if (dump_logs) {
+                rc = log_walk_body(log, shell_log_dump_entry, &log_offset);
+            } else {
+                /* Measure time for log_walk */
+                shell_log_count = 0;
+                os_time_t start = os_time_get();
+                rc = log_walk_body(log, shell_log_count_entry, &log_offset);
+                os_time_t end = os_time_get();
+                console_printf("Log %s %d entries walked in %d ms\n", log->l_name,
+                               (int)shell_log_count, (int)os_time_ticks_to_ms32(end - start));
+            }
             if (rc != 0) {
                 goto err;
             }