logging: Add common api for getting memory usage
Logging v2 did not support getting memory usage data. Adding this support by creating common api for getting current and maximum usage. Tracking of maximum usage is optional and can be enabled using CONFIG_LOG_MEM_UTILIZATION. Updated shell command to use common API. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
9ea5c1e510
commit
81ce6db313
6 changed files with 103 additions and 18 deletions
|
@ -404,26 +404,28 @@ static int cmd_log_strdup_utilization(const struct shell *shell,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_log_memory_slabs(const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_log_mem(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
uint32_t slabs_free;
|
||||
uint32_t size;
|
||||
uint32_t used;
|
||||
uint32_t max;
|
||||
int err;
|
||||
|
||||
slabs_free = log_msg_mem_get_free();
|
||||
used = log_msg_mem_get_used();
|
||||
|
||||
shell_print(sh, "Blocks used:\t%d", used);
|
||||
shell_print(sh, "Blocks free:\t%d", slabs_free);
|
||||
if (IS_ENABLED(CONFIG_MEM_SLAB_TRACE_MAX_UTILIZATION)) {
|
||||
max = log_msg_mem_get_max_used();
|
||||
shell_print(sh, "Blocks max:\t%d", max);
|
||||
} else {
|
||||
shell_print(
|
||||
sh,
|
||||
"Enable CONFIG_MEM_SLAB_TRACE_MAX_UTILIZATION to get max memory utilization");
|
||||
err = log_mem_get_usage(&size, &used);
|
||||
if (err < 0) {
|
||||
shell_error(sh, "Failed to get usage (mode does not support it?)");
|
||||
}
|
||||
|
||||
shell_print(sh, "Log message buffer utilization report:");
|
||||
shell_print(sh, "\tCapacity: %u bytes", size);
|
||||
shell_print(sh, "\tCurrently in use: %u bytes", used);
|
||||
err = log_mem_get_max_usage(&max);
|
||||
if (err < 0) {
|
||||
shell_print(sh, "Enable CONFIG_LOG_MEM_UTILIZATION to get maximum usage");
|
||||
}
|
||||
|
||||
shell_print(sh, "\tMaximum usage: %u bytes", max);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -479,7 +481,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
|
|||
"Get utilization of string duplicates pool", cmd_log_strdup_utilization,
|
||||
1, 0),
|
||||
SHELL_COND_CMD(CONFIG_LOG_MODE_DEFERRED, mem, NULL, "Logger memory usage",
|
||||
cmd_log_memory_slabs),
|
||||
cmd_log_mem),
|
||||
SHELL_SUBCMD_SET_END);
|
||||
|
||||
SHELL_CMD_REGISTER(log, &sub_log_stat, "Commands for controlling logger",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue