mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
188:bcfe06ba3d64
mbed library release version 165

Who changed what in which revision?

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