stats: Add a stats shell command
Adds the stats shell command to list all stats and enable the command in the shell sample app. Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
This commit is contained in:
parent
10fb5c203b
commit
fc34338d77
4 changed files with 63 additions and 0 deletions
|
|
@ -12,3 +12,5 @@ CONFIG_POSIX_CLOCK=y
|
|||
CONFIG_DATE_SHELL=y
|
||||
CONFIG_THREAD_RUNTIME_STATS=y
|
||||
CONFIG_THREAD_RUNTIME_STATS_USE_TIMING_FUNCTIONS=y
|
||||
CONFIG_STATS=y
|
||||
CONFIG_STATS_SHELL=y
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
zephyr_sources_ifdef(CONFIG_STATS stats.c)
|
||||
zephyr_sources_ifdef(CONFIG_STATS_SHELL stats_shell.c)
|
||||
|
|
|
|||
|
|
@ -17,3 +17,12 @@ config STATS_NAMES
|
|||
setting is disabled, statistics are assigned generic names of the
|
||||
form "s0", "s1", etc. Enabling this setting simplifies debugging,
|
||||
but results in a larger code size.
|
||||
|
||||
config STATS_SHELL
|
||||
bool "Statistics Shell Command"
|
||||
depends on STATS && SHELL
|
||||
help
|
||||
Include a full name string for each statistic in the build. If this
|
||||
setting is disabled, statistics are assigned generic names of the
|
||||
form "s0", "s1", etc. Enabling this setting simplifies debugging,
|
||||
but results in a larger code size.
|
||||
|
|
|
|||
51
subsys/stats/stats_shell.c
Normal file
51
subsys/stats/stats_shell.c
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <shell/shell.h>
|
||||
#include <stats/stats.h>
|
||||
|
||||
static int stats_cb(struct stats_hdr *hdr, void *arg, const char *name, uint16_t off)
|
||||
{
|
||||
struct shell *sh = arg;
|
||||
void *addr = (uint8_t *)hdr + off;
|
||||
uint64_t val = 0;
|
||||
|
||||
switch (hdr->s_size) {
|
||||
case sizeof(uint16_t):
|
||||
val = *(uint16_t *)(addr);
|
||||
break;
|
||||
|
||||
case sizeof(uint32_t):
|
||||
val = *(uint32_t *)(addr);
|
||||
break;
|
||||
case sizeof(uint64_t):
|
||||
val = *(uint64_t *)(addr);
|
||||
break;
|
||||
}
|
||||
shell_print(sh, "\t%s (offset: %u, addr: %p): %llu", name, off, addr, val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int stats_group_cb(struct stats_hdr *hdr, void *arg)
|
||||
{
|
||||
struct shell *sh = arg;
|
||||
|
||||
shell_print(sh, "Stats Group %s (hdr addr: %x)", hdr->s_name, (void *)hdr);
|
||||
return stats_walk(hdr, stats_cb, arg);
|
||||
}
|
||||
|
||||
static int cmd_stats_list(const struct shell *sh, size_t argc,
|
||||
char **argv)
|
||||
{
|
||||
return stats_group_walk(stats_group_cb, (struct shell *)sh);
|
||||
}
|
||||
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(sub_stats,
|
||||
SHELL_CMD(list, NULL, "List stats", cmd_stats_list),
|
||||
SHELL_SUBCMD_SET_END /* Array terminated. */
|
||||
);
|
||||
|
||||
SHELL_CMD_REGISTER(stats, &sub_stats, "Stats commands", NULL);
|
||||
Loading…
Reference in a new issue