mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #17706 from kaspar030/add_stack_usage_metrics
tests: add stack usage metrics
This commit is contained in:
commit
fd7c185653
@ -438,7 +438,6 @@ void thread_add_to_list(list_node_t *list, thread_t *thread);
|
||||
*/
|
||||
const char *thread_getname(kernel_pid_t pid);
|
||||
|
||||
#ifdef DEVELHELP
|
||||
/**
|
||||
* @brief Measures the stack usage of a stack
|
||||
*
|
||||
@ -449,7 +448,6 @@ const char *thread_getname(kernel_pid_t pid);
|
||||
* @return the amount of unused space of the thread's stack
|
||||
*/
|
||||
uintptr_t thread_measure_stack_free(const char *stack);
|
||||
#endif /* DEVELHELP */
|
||||
|
||||
/**
|
||||
* @brief Get the number of bytes used on the ISR stack
|
||||
|
@ -40,6 +40,9 @@
|
||||
|
||||
extern int main(void);
|
||||
|
||||
static char main_stack[THREAD_STACKSIZE_MAIN];
|
||||
static char idle_stack[THREAD_STACKSIZE_IDLE];
|
||||
|
||||
static void *main_trampoline(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
@ -54,12 +57,16 @@ static void *main_trampoline(void *arg)
|
||||
|
||||
main();
|
||||
|
||||
#ifdef MODULE_TEST_UTILS_PRINT_STACK_USAGE
|
||||
void print_stack_usage_metric(const char *name, void *stack, unsigned max_size);
|
||||
if (IS_USED(MODULE_CORE_IDLE_THREAD)) {
|
||||
print_stack_usage_metric("idle", idle_stack, THREAD_STACKSIZE_IDLE);
|
||||
}
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char main_stack[THREAD_STACKSIZE_MAIN];
|
||||
static char idle_stack[THREAD_STACKSIZE_IDLE];
|
||||
|
||||
static void *idle_thread(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
@ -304,6 +304,12 @@ NORETURN void sched_task_exit(void)
|
||||
DEBUG("sched_task_exit: ending thread %" PRIkernel_pid "...\n",
|
||||
thread_getpid());
|
||||
|
||||
#if defined(MODULE_TEST_UTILS_PRINT_STACK_USAGE) && defined(DEVELHELP)
|
||||
void print_stack_usage_metric(const char *name, void *stack, unsigned max_size);
|
||||
thread_t *me = thread_get_active();
|
||||
print_stack_usage_metric(me->name, me->stack_start, me->stack_size);
|
||||
#endif
|
||||
|
||||
(void)irq_disable();
|
||||
sched_threads[thread_getpid()] = NULL;
|
||||
sched_num_threads--;
|
||||
|
@ -171,7 +171,6 @@ void thread_add_to_list(list_node_t *list, thread_t *thread)
|
||||
list->next = new_node;
|
||||
}
|
||||
|
||||
#ifdef DEVELHELP
|
||||
uintptr_t thread_measure_stack_free(const char *stack)
|
||||
{
|
||||
/* Alignment of stack has been fixed (if needed) by thread_create(), so
|
||||
@ -188,7 +187,6 @@ uintptr_t thread_measure_stack_free(const char *stack)
|
||||
|
||||
return space_free;
|
||||
}
|
||||
#endif
|
||||
|
||||
kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority,
|
||||
int flags, thread_task_func_t function, void *arg,
|
||||
@ -234,7 +232,8 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority,
|
||||
_init_tls(thread->tls);
|
||||
#endif
|
||||
|
||||
#if defined(DEVELHELP) || IS_ACTIVE(SCHED_TEST_STACK)
|
||||
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) \
|
||||
|| defined(MODULE_TEST_UTILS_PRINT_STACK_USAGE)
|
||||
if (flags & THREAD_CREATE_STACKTEST) {
|
||||
/* assign each int of the stack the value of it's address. Alignment
|
||||
* has been handled above, so silence -Wcast-align */
|
||||
|
@ -191,6 +191,9 @@ endif
|
||||
ifneq (,$(filter test_utils_netdev_eth_minimal,$(USEMODULE)))
|
||||
DIRS += test_utils/netdev_eth_minimal
|
||||
endif
|
||||
ifneq (,$(filter test_utils_print_stack_usage,$(USEMODULE)))
|
||||
DIRS += test_utils/print_stack_usage
|
||||
endif
|
||||
ifneq (,$(filter test_utils_result_output,$(USEMODULE)))
|
||||
DIRS += test_utils/result_output
|
||||
endif
|
||||
|
@ -10,5 +10,6 @@ menu "Test utilities"
|
||||
|
||||
rsource "dummy_thread/Kconfig"
|
||||
rsource "interactive_sync/Kconfig"
|
||||
rsource "print_stack_usage/Kconfig"
|
||||
rsource "result_output/Kconfig"
|
||||
endmenu # Test utilities
|
||||
|
10
sys/test_utils/print_stack_usage/Kconfig
Normal file
10
sys/test_utils/print_stack_usage/Kconfig
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022 Freie Universität Berlin
|
||||
# 2022 Inria
|
||||
#
|
||||
# This file is subject to the terms and conditions of the GNU Lesser
|
||||
# General Public License v2.1. See the file LICENSE in the top level
|
||||
# directory for more details.
|
||||
#
|
||||
|
||||
config MODULE_TEST_UTILS_PRINT_STACK_USAGE
|
||||
bool "Print stack usage metrics on stack exit"
|
3
sys/test_utils/print_stack_usage/Makefile
Normal file
3
sys/test_utils/print_stack_usage/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
MODULE = test_utils_print_stack_usage
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
42
sys/test_utils/print_stack_usage/print_stack_usage.c
Normal file
42
sys/test_utils/print_stack_usage/print_stack_usage.c
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup sys
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Prints stack usage in JSON metric format, when a thread ends
|
||||
*
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*/
|
||||
|
||||
#include "thread.h"
|
||||
#include "log.h"
|
||||
|
||||
void print_stack_usage_metric(const char *name, void *stack, unsigned max_size)
|
||||
{
|
||||
unsigned free = thread_measure_stack_free(stack);
|
||||
LOG_INFO("{ \"threads\": [{ \"name\": \"%s\", \"stack_size\": %u, \"stack_used\": %u }]}\n",
|
||||
name, max_size, max_size - free);
|
||||
}
|
||||
|
||||
#ifdef DEVELHELP
|
||||
void test_utils_print_stack_usage(void)
|
||||
{
|
||||
for (kernel_pid_t i = KERNEL_PID_FIRST; i <= KERNEL_PID_LAST; i++) {
|
||||
thread_t *p = (thread_t *)sched_threads[i];
|
||||
|
||||
if (p == NULL) {
|
||||
continue;
|
||||
}
|
||||
print_stack_usage_metric(p->name, p->stack_start, p->stack_size);
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,10 +1,14 @@
|
||||
APPLICATION ?= tests_$(notdir $(patsubst %/,%,$(CURDIR)))
|
||||
|
||||
ifneq (,$(wildcard $(CURDIR)/tests*/.))
|
||||
DEFAULT_MODULE += test_utils_interactive_sync
|
||||
# add interactive test configuration when testing Kconfig
|
||||
DEFAULT_MODULE += test_utils_interactive_sync
|
||||
# add stack metric printing configuration when testing Kconfig
|
||||
DEFAULT_MODULE += test_utils_print_stack_usage
|
||||
|
||||
# do the same for Kconfig builds
|
||||
ifeq (1,$(TEST_KCONFIG))
|
||||
KCONFIG_ADD_CONFIG += $(RIOTBASE)/tests/test_interactive.config
|
||||
KCONFIG_ADD_CONFIG += $(RIOTBASE)/tests/test_utils.config
|
||||
endif
|
||||
endif
|
||||
|
||||
|
@ -11,6 +11,9 @@ USEMODULE += gnrc
|
||||
USEMODULE += gnrc_netif_ieee802154
|
||||
USEMODULE += gnrc_pktdump
|
||||
|
||||
# somehow this breaks the test
|
||||
DISABLE_MODULE += test_utils_print_stack_usage
|
||||
|
||||
TEST_ON_CI_WHITELIST += native
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
@ -1,5 +1,6 @@
|
||||
BOARD_INSUFFICIENT_MEMORY := \
|
||||
arduino-duemilanove \
|
||||
arduino-leonardo \
|
||||
arduino-nano \
|
||||
arduino-uno \
|
||||
atmega328p \
|
||||
|
@ -5,6 +5,7 @@ CFLAGS += -DNDEBUG -DLOG_LEVEL=LOG_NONE
|
||||
|
||||
DISABLE_MODULE += auto_init auto_init_%
|
||||
DISABLE_MODULE += test_utils_interactive_sync
|
||||
DISABLE_MODULE += test_utils_print_stack_usage
|
||||
|
||||
USEMODULE += stdio_null
|
||||
|
||||
|
@ -2,4 +2,8 @@ include ../Makefile.tests_common
|
||||
USEPKG += fff
|
||||
# If periph_i2c is pulled in the real implementation conflicts with the mock
|
||||
FEATURES_BLACKLIST += periph_i2c
|
||||
|
||||
# only two threads used
|
||||
CFLAGS += -DMAXTHREADS=2
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
@ -23,5 +23,6 @@ BOARD_INSUFFICIENT_MEMORY := \
|
||||
stm32g0316-disco \
|
||||
stm32l0538-disco \
|
||||
telosb \
|
||||
waspmote-pro \
|
||||
z1 \
|
||||
#
|
||||
|
@ -1 +0,0 @@
|
||||
CONFIG_MODULE_TEST_UTILS_INTERACTIVE_SYNC=y
|
1
tests/test_print_stack_usage.config
Normal file
1
tests/test_print_stack_usage.config
Normal file
@ -0,0 +1 @@
|
||||
CONFIG_MODULE_TEST_UTILS_PRINT_STACK_USAGE=y
|
2
tests/test_utils.config
Normal file
2
tests/test_utils.config
Normal file
@ -0,0 +1,2 @@
|
||||
CONFIG_MODULE_TEST_UTILS_INTERACTIVE_SYNC=y
|
||||
CONFIG_MODULE_TEST_UTILS_PRINT_STACK_USAGE=y
|
Loading…
Reference in New Issue
Block a user