Initial commit
mbed-dev-master/platform/mbed_stats.h@0:bb348c97df44, 2020-09-16 (annotated)
- Committer:
- lypinator
- Date:
- Wed Sep 16 01:11:49 2020 +0000
- Revision:
- 0:bb348c97df44
Added PWM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lypinator | 0:bb348c97df44 | 1 | |
lypinator | 0:bb348c97df44 | 2 | /** \addtogroup platform */ |
lypinator | 0:bb348c97df44 | 3 | /** @{*/ |
lypinator | 0:bb348c97df44 | 4 | /** |
lypinator | 0:bb348c97df44 | 5 | * \defgroup platform_stats stats functions |
lypinator | 0:bb348c97df44 | 6 | * @{ |
lypinator | 0:bb348c97df44 | 7 | */ |
lypinator | 0:bb348c97df44 | 8 | /* mbed Microcontroller Library |
lypinator | 0:bb348c97df44 | 9 | * Copyright (c) 2016-2018 ARM Limited |
lypinator | 0:bb348c97df44 | 10 | * |
lypinator | 0:bb348c97df44 | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
lypinator | 0:bb348c97df44 | 12 | * you may not use this file except in compliance with the License. |
lypinator | 0:bb348c97df44 | 13 | * You may obtain a copy of the License at |
lypinator | 0:bb348c97df44 | 14 | * |
lypinator | 0:bb348c97df44 | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
lypinator | 0:bb348c97df44 | 16 | * |
lypinator | 0:bb348c97df44 | 17 | * Unless required by applicable law or agreed to in writing, software |
lypinator | 0:bb348c97df44 | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
lypinator | 0:bb348c97df44 | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
lypinator | 0:bb348c97df44 | 20 | * See the License for the specific language governing permissions and |
lypinator | 0:bb348c97df44 | 21 | * limitations under the License. |
lypinator | 0:bb348c97df44 | 22 | */ |
lypinator | 0:bb348c97df44 | 23 | #ifndef MBED_STATS_H |
lypinator | 0:bb348c97df44 | 24 | #define MBED_STATS_H |
lypinator | 0:bb348c97df44 | 25 | #include <stdint.h> |
lypinator | 0:bb348c97df44 | 26 | #include <stddef.h> |
lypinator | 0:bb348c97df44 | 27 | #include "hal/ticker_api.h" |
lypinator | 0:bb348c97df44 | 28 | |
lypinator | 0:bb348c97df44 | 29 | #ifdef __cplusplus |
lypinator | 0:bb348c97df44 | 30 | extern "C" { |
lypinator | 0:bb348c97df44 | 31 | #endif |
lypinator | 0:bb348c97df44 | 32 | |
lypinator | 0:bb348c97df44 | 33 | #ifdef MBED_ALL_STATS_ENABLED |
lypinator | 0:bb348c97df44 | 34 | #define MBED_SYS_STATS_ENABLED 1 |
lypinator | 0:bb348c97df44 | 35 | #define MBED_STACK_STATS_ENABLED 1 |
lypinator | 0:bb348c97df44 | 36 | #define MBED_CPU_STATS_ENABLED 1 |
lypinator | 0:bb348c97df44 | 37 | #define MBED_HEAP_STATS_ENABLED 1 |
lypinator | 0:bb348c97df44 | 38 | #define MBED_THREAD_STATS_ENABLED 1 |
lypinator | 0:bb348c97df44 | 39 | #endif |
lypinator | 0:bb348c97df44 | 40 | |
lypinator | 0:bb348c97df44 | 41 | /** |
lypinator | 0:bb348c97df44 | 42 | * struct mbed_stats_heap_t definition |
lypinator | 0:bb348c97df44 | 43 | */ |
lypinator | 0:bb348c97df44 | 44 | typedef struct { |
lypinator | 0:bb348c97df44 | 45 | uint32_t current_size; /**< Bytes allocated currently. */ |
lypinator | 0:bb348c97df44 | 46 | uint32_t max_size; /**< Max bytes allocated at a given time. */ |
lypinator | 0:bb348c97df44 | 47 | uint32_t total_size; /**< Cumulative sum of bytes ever allocated. */ |
lypinator | 0:bb348c97df44 | 48 | uint32_t reserved_size; /**< Current number of bytes allocated for the heap. */ |
lypinator | 0:bb348c97df44 | 49 | uint32_t alloc_cnt; /**< Current number of allocations. */ |
lypinator | 0:bb348c97df44 | 50 | uint32_t alloc_fail_cnt; /**< Number of failed allocations. */ |
lypinator | 0:bb348c97df44 | 51 | } mbed_stats_heap_t; |
lypinator | 0:bb348c97df44 | 52 | |
lypinator | 0:bb348c97df44 | 53 | /** |
lypinator | 0:bb348c97df44 | 54 | * Fill the passed in heap stat structure with heap stats. |
lypinator | 0:bb348c97df44 | 55 | * |
lypinator | 0:bb348c97df44 | 56 | * @param stats A pointer to the mbed_stats_heap_t structure to fill |
lypinator | 0:bb348c97df44 | 57 | */ |
lypinator | 0:bb348c97df44 | 58 | void mbed_stats_heap_get(mbed_stats_heap_t *stats); |
lypinator | 0:bb348c97df44 | 59 | |
lypinator | 0:bb348c97df44 | 60 | /** |
lypinator | 0:bb348c97df44 | 61 | * struct mbed_stats_stack_t definition |
lypinator | 0:bb348c97df44 | 62 | */ |
lypinator | 0:bb348c97df44 | 63 | typedef struct { |
lypinator | 0:bb348c97df44 | 64 | uint32_t thread_id; /**< Identifier for thread that owns the stack or 0 if multiple threads. */ |
lypinator | 0:bb348c97df44 | 65 | uint32_t max_size; /**< Maximum number of bytes used on the stack. */ |
lypinator | 0:bb348c97df44 | 66 | uint32_t reserved_size; /**< Current number of bytes allocated for the stack. */ |
lypinator | 0:bb348c97df44 | 67 | uint32_t stack_cnt; /**< Number of stacks stats accumulated in the structure. */ |
lypinator | 0:bb348c97df44 | 68 | } mbed_stats_stack_t; |
lypinator | 0:bb348c97df44 | 69 | |
lypinator | 0:bb348c97df44 | 70 | /** |
lypinator | 0:bb348c97df44 | 71 | * Fill the passed in structure with stack stats accumulated for all threads. The thread_id will be 0 |
lypinator | 0:bb348c97df44 | 72 | * and stack_cnt will represent number of threads. |
lypinator | 0:bb348c97df44 | 73 | * |
lypinator | 0:bb348c97df44 | 74 | * @param stats A pointer to the mbed_stats_stack_t structure to fill |
lypinator | 0:bb348c97df44 | 75 | */ |
lypinator | 0:bb348c97df44 | 76 | void mbed_stats_stack_get(mbed_stats_stack_t *stats); |
lypinator | 0:bb348c97df44 | 77 | |
lypinator | 0:bb348c97df44 | 78 | /** |
lypinator | 0:bb348c97df44 | 79 | * Fill the passed array of stat structures with the stack stats for each available thread. |
lypinator | 0:bb348c97df44 | 80 | * |
lypinator | 0:bb348c97df44 | 81 | * @param stats A pointer to an array of mbed_stats_stack_t structures to fill |
lypinator | 0:bb348c97df44 | 82 | * @param count The number of mbed_stats_stack_t structures in the provided array |
lypinator | 0:bb348c97df44 | 83 | * @return The number of mbed_stats_stack_t structures that have been filled, |
lypinator | 0:bb348c97df44 | 84 | * this is equal to the number of stacks on the system. |
lypinator | 0:bb348c97df44 | 85 | */ |
lypinator | 0:bb348c97df44 | 86 | size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count); |
lypinator | 0:bb348c97df44 | 87 | |
lypinator | 0:bb348c97df44 | 88 | /** |
lypinator | 0:bb348c97df44 | 89 | * struct mbed_stats_cpu_t definition |
lypinator | 0:bb348c97df44 | 90 | */ |
lypinator | 0:bb348c97df44 | 91 | typedef struct { |
lypinator | 0:bb348c97df44 | 92 | us_timestamp_t uptime; /**< Time since system is up and running */ |
lypinator | 0:bb348c97df44 | 93 | us_timestamp_t idle_time; /**< Time spent in idle thread since system is up and running */ |
lypinator | 0:bb348c97df44 | 94 | us_timestamp_t sleep_time; /**< Time spent in sleep since system is up and running */ |
lypinator | 0:bb348c97df44 | 95 | us_timestamp_t deep_sleep_time; /**< Time spent in deep sleep since system is up and running */ |
lypinator | 0:bb348c97df44 | 96 | } mbed_stats_cpu_t; |
lypinator | 0:bb348c97df44 | 97 | |
lypinator | 0:bb348c97df44 | 98 | /** |
lypinator | 0:bb348c97df44 | 99 | * Fill the passed in CPU stat structure with CPU statistics. |
lypinator | 0:bb348c97df44 | 100 | * |
lypinator | 0:bb348c97df44 | 101 | * @param stats A pointer to the mbed_stats_cpu_t structure to fill |
lypinator | 0:bb348c97df44 | 102 | */ |
lypinator | 0:bb348c97df44 | 103 | void mbed_stats_cpu_get(mbed_stats_cpu_t *stats); |
lypinator | 0:bb348c97df44 | 104 | |
lypinator | 0:bb348c97df44 | 105 | /** |
lypinator | 0:bb348c97df44 | 106 | * struct mbed_stats_thread_t definition |
lypinator | 0:bb348c97df44 | 107 | */ |
lypinator | 0:bb348c97df44 | 108 | typedef struct { |
lypinator | 0:bb348c97df44 | 109 | uint32_t id; /**< Thread Object Identifier */ |
lypinator | 0:bb348c97df44 | 110 | uint32_t state; /**< Thread Object State */ |
lypinator | 0:bb348c97df44 | 111 | uint32_t priority; /**< Thread Priority */ |
lypinator | 0:bb348c97df44 | 112 | uint32_t stack_size; /**< Thread Stack Size */ |
lypinator | 0:bb348c97df44 | 113 | uint32_t stack_space; /**< Thread remaining stack size */ |
lypinator | 0:bb348c97df44 | 114 | const char *name; /**< Thread Object name */ |
lypinator | 0:bb348c97df44 | 115 | } mbed_stats_thread_t; |
lypinator | 0:bb348c97df44 | 116 | |
lypinator | 0:bb348c97df44 | 117 | /** |
lypinator | 0:bb348c97df44 | 118 | * Fill the passed array of stat structures with the thread stats for each available thread. |
lypinator | 0:bb348c97df44 | 119 | * |
lypinator | 0:bb348c97df44 | 120 | * @param stats A pointer to an array of mbed_stats_thread_t structures to fill |
lypinator | 0:bb348c97df44 | 121 | * @param count The number of mbed_stats_thread_t structures in the provided array |
lypinator | 0:bb348c97df44 | 122 | * @return The number of mbed_stats_thread_t structures that have been filled, |
lypinator | 0:bb348c97df44 | 123 | * this is equal to the number of threads on the system. |
lypinator | 0:bb348c97df44 | 124 | */ |
lypinator | 0:bb348c97df44 | 125 | size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count); |
lypinator | 0:bb348c97df44 | 126 | |
lypinator | 0:bb348c97df44 | 127 | /** |
lypinator | 0:bb348c97df44 | 128 | * enum mbed_compiler_id_t definition |
lypinator | 0:bb348c97df44 | 129 | */ |
lypinator | 0:bb348c97df44 | 130 | typedef enum { |
lypinator | 0:bb348c97df44 | 131 | ARM = 1, /**< ARM */ |
lypinator | 0:bb348c97df44 | 132 | GCC_ARM, /**< GNU ARM */ |
lypinator | 0:bb348c97df44 | 133 | IAR /**< IAR */ |
lypinator | 0:bb348c97df44 | 134 | } mbed_compiler_id_t; |
lypinator | 0:bb348c97df44 | 135 | |
lypinator | 0:bb348c97df44 | 136 | /** |
lypinator | 0:bb348c97df44 | 137 | * struct mbed_stats_sys_t definition |
lypinator | 0:bb348c97df44 | 138 | */ |
lypinator | 0:bb348c97df44 | 139 | typedef struct { |
lypinator | 0:bb348c97df44 | 140 | uint32_t os_version; /**< Mbed OS Version (Release only) */ |
lypinator | 0:bb348c97df44 | 141 | uint32_t cpu_id; /**< CPUID Register data (Cortex-M only supported) */ |
lypinator | 0:bb348c97df44 | 142 | mbed_compiler_id_t compiler_id; /**< Compiler ID \ref mbed_compiler_id_t */ |
lypinator | 0:bb348c97df44 | 143 | uint32_t compiler_version; /**< Compiler version */ |
lypinator | 0:bb348c97df44 | 144 | } mbed_stats_sys_t; |
lypinator | 0:bb348c97df44 | 145 | |
lypinator | 0:bb348c97df44 | 146 | /** |
lypinator | 0:bb348c97df44 | 147 | * Fill the passed in sys stat structure with system stats. |
lypinator | 0:bb348c97df44 | 148 | * |
lypinator | 0:bb348c97df44 | 149 | * @param stats A pointer to the mbed_stats_sys_t structure to fill |
lypinator | 0:bb348c97df44 | 150 | */ |
lypinator | 0:bb348c97df44 | 151 | void mbed_stats_sys_get(mbed_stats_sys_t *stats); |
lypinator | 0:bb348c97df44 | 152 | |
lypinator | 0:bb348c97df44 | 153 | #ifdef __cplusplus |
lypinator | 0:bb348c97df44 | 154 | } |
lypinator | 0:bb348c97df44 | 155 | #endif |
lypinator | 0:bb348c97df44 | 156 | |
lypinator | 0:bb348c97df44 | 157 | #endif |
lypinator | 0:bb348c97df44 | 158 | |
lypinator | 0:bb348c97df44 | 159 | /** @}*/ |
lypinator | 0:bb348c97df44 | 160 | |
lypinator | 0:bb348c97df44 | 161 | /** @}*/ |