1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/test_utils: add print_stack_usage

This commit adds a module that can print stack metrics in the format as
understood by CI.
This commit is contained in:
Kaspar Schleiser 2020-08-06 13:22:49 +02:00
parent c0f26fcaaa
commit fbe57de85e
3 changed files with 48 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,3 @@
MODULE = test_utils_print_stack_usage
include $(RIOTBASE)/Makefile.base

View 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