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