Mistake on this page?
Report an issue in GitHub or email us
mbed_stats.h
1 
2 /** \addtogroup platform */
3 /** @{*/
4 /**
5  * \defgroup platform_stats stats functions
6  * @{
7  */
8 /* mbed Microcontroller Library
9  * Copyright (c) 2016-2018 ARM Limited
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24 #ifndef MBED_STATS_H
25 #define MBED_STATS_H
26 #include <stdint.h>
27 #include <stddef.h>
28 #include "hal/ticker_api.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #ifdef MBED_ALL_STATS_ENABLED
35 
36 #ifndef MBED_SYS_STATS_ENABLED
37 #define MBED_SYS_STATS_ENABLED 1
38 #endif
39 #ifndef MBED_STACK_STATS_ENABLED
40 #define MBED_STACK_STATS_ENABLED 1
41 #endif
42 #ifndef MBED_CPU_STATS_ENABLED
43 #define MBED_CPU_STATS_ENABLED 1
44 #endif
45 #ifndef MBED_HEAP_STATS_ENABLED
46 #define MBED_HEAP_STATS_ENABLED 1
47 #endif
48 #ifndef MBED_THREAD_STATS_ENABLED
49 #define MBED_THREAD_STATS_ENABLED 1
50 #endif
51 
52 #endif // MBED_ALL_STATS_ENABLED
53 
54 /** Maximum memory regions reported by mbed-os memory statistics */
55 #define MBED_MAX_MEM_REGIONS 4
56 
57 /**
58  * struct mbed_stats_heap_t definition
59  */
60 typedef struct {
61  uint32_t current_size; /**< Bytes currently allocated on the heap */
62  uint32_t max_size; /**< Maximum bytes allocated on the heap at one time since reset */
63  uint32_t total_size; /**< Cumulative sum of bytes allocated on the heap that have not been freed */
64  uint32_t reserved_size; /**< Current number of bytes reserved for the heap */
65  uint32_t alloc_cnt; /**< Current number of allocations that have not been freed since reset */
66  uint32_t alloc_fail_cnt; /**< Number of failed allocations since reset */
67  uint32_t overhead_size; /**< Number of bytes used to store heap statistics. This overhead takes up space on the heap, reducing the available heap space */
69 
70 /**
71  * Fill the passed in heap stat structure with the heap statistics.
72  *
73  * @param stats A pointer to the mbed_stats_heap_t structure to fill
74  */
76 
77 /**
78  * struct mbed_stats_stack_t definition
79  */
80 typedef struct {
81  uint32_t thread_id; /**< Identifier for the thread that owns the stack or 0 if representing accumulated statistics */
82  uint32_t max_size; /**< Maximum number of bytes used on the stack since the thread was started */
83  uint32_t reserved_size; /**< Current number of bytes reserved for the stack */
84  uint32_t stack_cnt; /**< The number of stacks represented in the accumulated statistics or 1 if representing a single stack */
86 
87 /**
88  * Fill the passed in structure with stack statistics accumulated for all threads. The thread_id will be 0
89  * and stack_cnt will represent number of threads.
90  *
91  * @param stats A pointer to the mbed_stats_stack_t structure to fill
92  */
94 
95 /**
96  * Fill the passed array of structures with the stack statistics for each available thread.
97  *
98  * @param stats A pointer to an array of mbed_stats_stack_t structures to fill
99  * @param count The number of mbed_stats_stack_t structures in the provided array
100  * @return The number of mbed_stats_stack_t structures that have been filled.
101  * If the number of stacks on the system is less than or equal to count, it will equal the number of stacks on the system.
102  * If the number of stacks on the system is greater than count, it will equal count.
103  */
104 size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count);
105 
106 /**
107  * struct mbed_stats_cpu_t definition
108  */
109 typedef struct {
110  us_timestamp_t uptime; /**< Time since the system has started */
111  us_timestamp_t idle_time; /**< Time spent in the idle thread since the system has started */
112  us_timestamp_t sleep_time; /**< Time spent in sleep since the system has started */
113  us_timestamp_t deep_sleep_time; /**< Time spent in deep sleep since the system has started */
115 
116 /**
117  * Fill the passed in CPU stat structure with CPU statistics.
118  *
119  * @param stats A pointer to the mbed_stats_cpu_t structure to fill
120  */
122 
123 /**
124  * struct mbed_stats_thread_t definition
125  */
126 typedef struct {
127  uint32_t id; /**< ID of the thread */
128  uint32_t state; /**< State of the thread */
129  uint32_t priority; /**< Priority of the thread (higher number indicates higher priority) */
130  uint32_t stack_size; /**< Current number of bytes reserved for the stack */
131  uint32_t stack_space; /**< Current number of free bytes remaining on the stack */
132  const char *name; /**< Name of the thread */
134 
135 /**
136  * Fill the passed array of stat structures with the thread statistics for each available thread.
137  *
138  * @param stats A pointer to an array of mbed_stats_thread_t structures to fill
139  * @param count The number of mbed_stats_thread_t structures in the provided array
140  * @return The number of mbed_stats_thread_t structures that have been filled.
141  * If the number of threads on the system is less than or equal to count, it will equal the number of threads on the system.
142  * If the number of threads on the system is greater than count, it will equal count.
143  */
144 size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count);
145 
146 /**
147  * enum mbed_compiler_id_t definition
148  */
149 typedef enum {
150  ARM = 1, /**< ARM */
151  GCC_ARM, /**< GNU ARM */
152  IAR /**< IAR */
154 
155 /**
156  * struct mbed_stats_sys_t definition
157  */
158 typedef struct {
159  uint32_t os_version; /**< Mbed OS version (populated only for tagged releases) */
160  uint32_t cpu_id; /**< CPUID register data (Cortex-M only supported) */
161  mbed_compiler_id_t compiler_id; /**< Compiler ID \ref mbed_compiler_id_t */
162  uint32_t compiler_version; /**< Compiler version */
163  uint32_t ram_start[MBED_MAX_MEM_REGIONS]; /**< Start addresses of all internal RAM memories */
164  uint32_t ram_size[MBED_MAX_MEM_REGIONS]; /**< Size of all internal RAM memories in target */
165  uint32_t rom_start[MBED_MAX_MEM_REGIONS]; /**< Start addresses of all internal ROM memories */
166  uint32_t rom_size[MBED_MAX_MEM_REGIONS]; /**< Size of all internal ROM memories in target */
168 
169 /**
170  * Fill the passed in system stat structure with system statistics.
171  *
172  * @param stats A pointer to the mbed_stats_sys_t structure to fill
173  */
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif
181 
182 /** @}*/
183 
184 /** @}*/
uint32_t stack_size
Current number of bytes reserved for the stack.
Definition: mbed_stats.h:130
struct mbed_stats_thread_t definition
Definition: mbed_stats.h:126
ARM.
Definition: mbed_stats.h:150
uint32_t priority
Priority of the thread (higher number indicates higher priority)
Definition: mbed_stats.h:129
mbed_compiler_id_t compiler_id
Compiler ID mbed_compiler_id_t.
Definition: mbed_stats.h:161
void mbed_stats_sys_get(mbed_stats_sys_t *stats)
Fill the passed in system stat structure with system statistics.
uint32_t alloc_fail_cnt
Number of failed allocations since reset.
Definition: mbed_stats.h:66
void mbed_stats_cpu_get(mbed_stats_cpu_t *stats)
Fill the passed in CPU stat structure with CPU statistics.
struct mbed_stats_sys_t definition
Definition: mbed_stats.h:158
uint32_t cpu_id
CPUID register data (Cortex-M only supported)
Definition: mbed_stats.h:160
void mbed_stats_stack_get(mbed_stats_stack_t *stats)
Fill the passed in structure with stack statistics accumulated for all threads.
uint32_t id
ID of the thread.
Definition: mbed_stats.h:127
GNU ARM.
Definition: mbed_stats.h:151
us_timestamp_t sleep_time
Time spent in sleep since the system has started.
Definition: mbed_stats.h:112
struct mbed_stats_heap_t definition
Definition: mbed_stats.h:60
uint64_t us_timestamp_t
A us timestamp stored in a 64 bit integer.
Definition: ticker_api.h:39
uint32_t reserved_size
Current number of bytes reserved for the heap.
Definition: mbed_stats.h:64
#define MBED_MAX_MEM_REGIONS
Maximum memory regions reported by mbed-os memory statistics.
Definition: mbed_stats.h:55
mbed_compiler_id_t
enum mbed_compiler_id_t definition
Definition: mbed_stats.h:149
uint32_t stack_space
Current number of free bytes remaining on the stack.
Definition: mbed_stats.h:131
uint32_t os_version
Mbed OS version (populated only for tagged releases)
Definition: mbed_stats.h:159
void mbed_stats_heap_get(mbed_stats_heap_t *stats)
Fill the passed in heap stat structure with the heap statistics.
uint32_t thread_id
Identifier for the thread that owns the stack or 0 if representing accumulated statistics.
Definition: mbed_stats.h:81
us_timestamp_t deep_sleep_time
Time spent in deep sleep since the system has started.
Definition: mbed_stats.h:113
us_timestamp_t uptime
Time since the system has started.
Definition: mbed_stats.h:110
const char * name
Name of the thread.
Definition: mbed_stats.h:132
struct mbed_stats_stack_t definition
Definition: mbed_stats.h:80
uint32_t alloc_cnt
Current number of allocations that have not been freed since reset.
Definition: mbed_stats.h:65
uint32_t state
State of the thread.
Definition: mbed_stats.h:128
uint32_t compiler_version
Compiler version.
Definition: mbed_stats.h:162
size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count)
Fill the passed array of structures with the stack statistics for each available thread.
uint32_t total_size
Cumulative sum of bytes allocated on the heap that have not been freed.
Definition: mbed_stats.h:63
uint32_t max_size
Maximum bytes allocated on the heap at one time since reset.
Definition: mbed_stats.h:62
size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count)
Fill the passed array of stat structures with the thread statistics for each available thread...
uint32_t stack_cnt
The number of stacks represented in the accumulated statistics or 1 if representing a single stack...
Definition: mbed_stats.h:84
us_timestamp_t idle_time
Time spent in the idle thread since the system has started.
Definition: mbed_stats.h:111
IAR.
Definition: mbed_stats.h:152
uint32_t max_size
Maximum number of bytes used on the stack since the thread was started.
Definition: mbed_stats.h:82
uint32_t current_size
Bytes currently allocated on the heap.
Definition: mbed_stats.h:61
uint32_t overhead_size
Number of bytes used to store heap statistics.
Definition: mbed_stats.h:67
uint32_t reserved_size
Current number of bytes reserved for the stack.
Definition: mbed_stats.h:83
struct mbed_stats_cpu_t definition
Definition: mbed_stats.h:109
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.