1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/test_utils/print_stack_usage/print_stack_usage.c
Kaspar Schleiser fbe57de85e sys/test_utils: add print_stack_usage
This commit adds a module that can print stack metrics in the format as
understood by CI.
2022-03-29 21:49:35 +02:00

43 lines
1.0 KiB
C

/*
* 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