test

Dependencies:   mbed Watchdog

Dependents:   STM32-MC_node

Committer:
ommpy
Date:
Mon Jul 06 17:18:59 2020 +0530
Revision:
0:d383e2dee0f7
first commit

Who changed what in which revision?

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