Commit fc34338d authored by Tom Burdick's avatar Tom Burdick Committed by Anas Nashif
Browse files

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: default avatarTom Burdick <thomas.burdick@intel.com>
parent 10fb5c20
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: Apache-2.0

zephyr_sources_ifdef(CONFIG_STATS stats.c)
zephyr_sources_ifdef(CONFIG_STATS_SHELL stats_shell.c)
+9 −0
Original line number Diff line number Diff line
@@ -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 −0
Original line number Diff line number Diff line
/*
 * 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);