Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
mbed_stats.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2016-2019 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #ifndef MBED_STATS_H 00018 #define MBED_STATS_H 00019 #include <stdint.h> 00020 #include <stddef.h> 00021 #include "hal/ticker_api.h" 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /** \addtogroup platform-public-api */ 00028 /** @{*/ 00029 00030 /** 00031 * \defgroup platform_stats stats functions 00032 * @{ 00033 */ 00034 00035 #ifdef MBED_ALL_STATS_ENABLED 00036 00037 #ifndef MBED_SYS_STATS_ENABLED 00038 #define MBED_SYS_STATS_ENABLED 1 00039 #endif 00040 #ifndef MBED_STACK_STATS_ENABLED 00041 #define MBED_STACK_STATS_ENABLED 1 00042 #endif 00043 #ifndef MBED_CPU_STATS_ENABLED 00044 #define MBED_CPU_STATS_ENABLED 1 00045 #endif 00046 #ifndef MBED_HEAP_STATS_ENABLED 00047 #define MBED_HEAP_STATS_ENABLED 1 00048 #endif 00049 #ifndef MBED_THREAD_STATS_ENABLED 00050 #define MBED_THREAD_STATS_ENABLED 1 00051 #endif 00052 00053 #endif // MBED_ALL_STATS_ENABLED 00054 00055 /** Maximum memory regions reported by mbed-os memory statistics */ 00056 #define MBED_MAX_MEM_REGIONS 4 00057 00058 /** 00059 * struct mbed_stats_heap_t definition 00060 */ 00061 typedef struct { 00062 uint32_t current_size; /**< Bytes currently allocated on the heap */ 00063 uint32_t max_size; /**< Maximum bytes allocated on the heap at one time since reset */ 00064 uint32_t total_size; /**< Cumulative sum of bytes allocated on the heap that have not been freed */ 00065 uint32_t reserved_size; /**< Current number of bytes reserved for the heap */ 00066 uint32_t alloc_cnt; /**< Current number of allocations that have not been freed since reset */ 00067 uint32_t alloc_fail_cnt; /**< Number of failed allocations since reset */ 00068 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 */ 00069 } mbed_stats_heap_t; 00070 00071 /** 00072 * Fill the passed in heap stat structure with the heap statistics. 00073 * 00074 * @param stats A pointer to the mbed_stats_heap_t structure to fill 00075 */ 00076 void mbed_stats_heap_get(mbed_stats_heap_t *stats); 00077 00078 /** 00079 * struct mbed_stats_stack_t definition 00080 */ 00081 typedef struct { 00082 uint32_t thread_id; /**< Identifier for the thread that owns the stack or 0 if representing accumulated statistics */ 00083 uint32_t max_size; /**< Maximum number of bytes used on the stack since the thread was started */ 00084 uint32_t reserved_size; /**< Current number of bytes reserved for the stack */ 00085 uint32_t stack_cnt; /**< The number of stacks represented in the accumulated statistics or 1 if representing a single stack */ 00086 } mbed_stats_stack_t; 00087 00088 /** 00089 * Fill the passed in structure with stack statistics accumulated for all threads. The thread_id will be 0 00090 * and stack_cnt will represent number of threads. 00091 * 00092 * @param stats A pointer to the mbed_stats_stack_t structure to fill 00093 */ 00094 void mbed_stats_stack_get(mbed_stats_stack_t *stats); 00095 00096 /** 00097 * Fill the passed array of structures with the stack statistics for each available thread. 00098 * 00099 * @param stats A pointer to an array of mbed_stats_stack_t structures to fill 00100 * @param count The number of mbed_stats_stack_t structures in the provided array 00101 * @return The number of mbed_stats_stack_t structures that have been filled. 00102 * 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. 00103 * If the number of stacks on the system is greater than count, it will equal count. 00104 */ 00105 size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count); 00106 00107 /** 00108 * struct mbed_stats_cpu_t definition 00109 */ 00110 typedef struct { 00111 us_timestamp_t uptime; /**< Time since the system has started */ 00112 us_timestamp_t idle_time; /**< Time spent in the idle thread since the system has started */ 00113 us_timestamp_t sleep_time; /**< Time spent in sleep since the system has started */ 00114 us_timestamp_t deep_sleep_time; /**< Time spent in deep sleep since the system has started */ 00115 } mbed_stats_cpu_t; 00116 00117 /** 00118 * Fill the passed in CPU stat structure with CPU statistics. 00119 * 00120 * @param stats A pointer to the mbed_stats_cpu_t structure to fill 00121 */ 00122 void mbed_stats_cpu_get(mbed_stats_cpu_t *stats); 00123 00124 /** 00125 * struct mbed_stats_thread_t definition 00126 */ 00127 typedef struct { 00128 uint32_t id; /**< ID of the thread */ 00129 uint32_t state; /**< State of the thread */ 00130 uint32_t priority; /**< Priority of the thread (higher number indicates higher priority) */ 00131 uint32_t stack_size; /**< Current number of bytes reserved for the stack */ 00132 uint32_t stack_space; /**< Current number of free bytes remaining on the stack */ 00133 const char *name; /**< Name of the thread */ 00134 } mbed_stats_thread_t; 00135 00136 /** 00137 * Fill the passed array of stat structures with the thread statistics for each available thread. 00138 * 00139 * @param stats A pointer to an array of mbed_stats_thread_t structures to fill 00140 * @param count The number of mbed_stats_thread_t structures in the provided array 00141 * @return The number of mbed_stats_thread_t structures that have been filled. 00142 * 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. 00143 * If the number of threads on the system is greater than count, it will equal count. 00144 */ 00145 size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count); 00146 00147 /** 00148 * enum mbed_compiler_id_t definition 00149 */ 00150 typedef enum { 00151 ARM = 1, /**< ARM */ 00152 GCC_ARM, /**< GNU ARM */ 00153 IAR /**< IAR */ 00154 } mbed_compiler_id_t; 00155 00156 /** 00157 * struct mbed_stats_sys_t definition 00158 */ 00159 typedef struct { 00160 uint32_t os_version; /**< Mbed OS version (populated only for tagged releases) */ 00161 uint32_t cpu_id; /**< CPUID register data (Cortex-M only supported) */ 00162 mbed_compiler_id_t compiler_id; /**< Compiler ID \ref mbed_compiler_id_t */ 00163 uint32_t compiler_version; /**< Compiler version */ 00164 uint32_t ram_start[MBED_MAX_MEM_REGIONS]; /**< Start addresses of all internal RAM memories */ 00165 uint32_t ram_size[MBED_MAX_MEM_REGIONS]; /**< Size of all internal RAM memories in target */ 00166 uint32_t rom_start[MBED_MAX_MEM_REGIONS]; /**< Start addresses of all internal ROM memories */ 00167 uint32_t rom_size[MBED_MAX_MEM_REGIONS]; /**< Size of all internal ROM memories in target */ 00168 } mbed_stats_sys_t; 00169 00170 /** 00171 * Fill the passed in system stat structure with system statistics. 00172 * 00173 * @param stats A pointer to the mbed_stats_sys_t structure to fill 00174 */ 00175 void mbed_stats_sys_get(mbed_stats_sys_t *stats); 00176 00177 #ifdef __cplusplus 00178 } 00179 #endif 00180 00181 #endif 00182 00183 /** @}*/ 00184 00185 /** @}*/
Generated on Tue Jul 12 2022 13:54:34 by
