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