mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			stats - Added stack stats api
Matched heap stats api - void mbed_stats_heap_get(mbed_stats_heap_t *) - void mbed_stats_stack_get(mbed_stats_stack_t *)pull/3141/head
							parent
							
								
									03b8ae1811
								
							
						
					
					
						commit
						b6e8f44c0d
					
				| 
						 | 
				
			
			@ -0,0 +1,37 @@
 | 
			
		|||
#include "mbed_stats.h"
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#if MBED_CONF_RTOS_PRESENT
 | 
			
		||||
#include "cmsis_os.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// note: mbed_stats_heap_get defined in mbed_alloc_wrappers.cpp
 | 
			
		||||
 | 
			
		||||
void mbed_stats_stack_get(mbed_stats_stack_t *stats)
 | 
			
		||||
{
 | 
			
		||||
    memset(stats, 0, sizeof(mbed_stats_stack_t));
 | 
			
		||||
 | 
			
		||||
#if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT
 | 
			
		||||
    osThreadEnumId enumid = _osThreadsEnumStart();
 | 
			
		||||
    osThreadId threadid;
 | 
			
		||||
 | 
			
		||||
    while ((threadid = _osThreadEnumNext(enumid))) {
 | 
			
		||||
        osEvent e;
 | 
			
		||||
 | 
			
		||||
        e = _osThreadGetInfo(threadid, osThreadInfoStackMax);
 | 
			
		||||
        if (e.status == osOK) {
 | 
			
		||||
           stats->max_size += (uint32_t)e.value.p;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        e = _osThreadGetInfo(threadid, osThreadInfoStackSize);
 | 
			
		||||
        if (e.status == osOK) {
 | 
			
		||||
           stats->reserved_size += (uint32_t)e.value.p;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        stats->stack_cnt += 1;
 | 
			
		||||
    }
 | 
			
		||||
#elif MBED_STACK_STATS_ENABLED
 | 
			
		||||
#warning Stack statistics are not supported without the rtos.
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -18,6 +18,7 @@
 | 
			
		|||
 */
 | 
			
		||||
#ifndef MBED_STATS_H
 | 
			
		||||
#define MBED_STATS_H
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
| 
						 | 
				
			
			@ -36,6 +37,17 @@ typedef struct {
 | 
			
		|||
 */
 | 
			
		||||
void mbed_stats_heap_get(mbed_stats_heap_t *stats);
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    uint32_t max_size;          /**< Sum of the maximum number of bytes used in each stack. */
 | 
			
		||||
    uint32_t reserved_size;     /**< Current number of bytes allocated for all stacks. */
 | 
			
		||||
    uint32_t stack_cnt;         /**< Number of stacks currently allocated. */
 | 
			
		||||
} mbed_stats_stack_t;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Fill the passed in structure with stack stats.
 | 
			
		||||
 */
 | 
			
		||||
void mbed_stats_stack_get(mbed_stats_stack_t *stats);
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue