mbed library sources. Supersedes mbed-src.

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_stats.h Source File

mbed_stats.h

00001 
00002 /** \addtogroup platform */
00003 /** @{*/
00004 /**
00005  * \defgroup platform_stats stats functions
00006  * @{
00007  */
00008 /* mbed Microcontroller Library
00009  * Copyright (c) 2016-2018 ARM Limited
00010  * SPDX-License-Identifier: Apache-2.0
00011  *
00012  * Licensed under the Apache License, Version 2.0 (the "License");
00013  * you may not use this file except in compliance with the License.
00014  * You may obtain a copy of the License at
00015  *
00016  *     http://www.apache.org/licenses/LICENSE-2.0
00017  *
00018  * Unless required by applicable law or agreed to in writing, software
00019  * distributed under the License is distributed on an "AS IS" BASIS,
00020  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00021  * See the License for the specific language governing permissions and
00022  * limitations under the License.
00023  */
00024 #ifndef MBED_STATS_H
00025 #define MBED_STATS_H
00026 #include <stdint.h>
00027 #include <stddef.h>
00028 #include "hal/ticker_api.h"
00029 
00030 #ifdef __cplusplus
00031 extern "C" {
00032 #endif
00033 
00034 #ifdef MBED_ALL_STATS_ENABLED
00035 
00036 #ifndef MBED_SYS_STATS_ENABLED
00037 #define MBED_SYS_STATS_ENABLED      1
00038 #endif
00039 #ifndef MBED_STACK_STATS_ENABLED
00040 #define MBED_STACK_STATS_ENABLED    1
00041 #endif
00042 #ifndef MBED_CPU_STATS_ENABLED
00043 #define MBED_CPU_STATS_ENABLED      1
00044 #endif
00045 #ifndef MBED_HEAP_STATS_ENABLED
00046 #define MBED_HEAP_STATS_ENABLED     1
00047 #endif
00048 #ifndef MBED_THREAD_STATS_ENABLED
00049 #define MBED_THREAD_STATS_ENABLED   1
00050 #endif
00051 
00052 #endif // MBED_ALL_STATS_ENABLED
00053 
00054 /** Maximum memory regions reported by mbed-os memory statistics */
00055 #define MBED_MAX_MEM_REGIONS     4
00056 
00057 /**
00058  * struct mbed_stats_heap_t definition
00059  */
00060 typedef struct {
00061     uint32_t current_size;      /**< Bytes currently allocated on the heap */
00062     uint32_t max_size;          /**< Maximum bytes allocated on the heap at one time since reset */
00063     uint32_t total_size;        /**< Cumulative sum of bytes allocated on the heap that have not been freed */
00064     uint32_t reserved_size;     /**< Current number of bytes reserved for the heap */
00065     uint32_t alloc_cnt;         /**< Current number of allocations that have not been freed since reset */
00066     uint32_t alloc_fail_cnt;    /**< Number of failed allocations since reset */
00067     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 */
00068 } mbed_stats_heap_t;
00069 
00070 /**
00071  *  Fill the passed in heap stat structure with the heap statistics.
00072  *
00073  *  @param stats    A pointer to the mbed_stats_heap_t structure to fill
00074  */
00075 void mbed_stats_heap_get(mbed_stats_heap_t *stats);
00076 
00077 /**
00078  * struct mbed_stats_stack_t definition
00079  */
00080 typedef struct {
00081     uint32_t thread_id;         /**< Identifier for the thread that owns the stack or 0 if representing accumulated statistics */
00082     uint32_t max_size;          /**< Maximum number of bytes used on the stack since the thread was started */
00083     uint32_t reserved_size;     /**< Current number of bytes reserved for the stack */
00084     uint32_t stack_cnt;         /**< The number of stacks represented in the accumulated statistics or 1 if representing a single stack */
00085 } mbed_stats_stack_t;
00086 
00087 /**
00088  *  Fill the passed in structure with stack statistics accumulated for all threads. The thread_id will be 0
00089  *  and stack_cnt will represent number of threads.
00090  *
00091  *  @param stats    A pointer to the mbed_stats_stack_t structure to fill
00092  */
00093 void mbed_stats_stack_get(mbed_stats_stack_t *stats);
00094 
00095 /**
00096  *  Fill the passed array of structures with the stack statistics for each available thread.
00097  *
00098  *  @param stats    A pointer to an array of mbed_stats_stack_t structures to fill
00099  *  @param count    The number of mbed_stats_stack_t structures in the provided array
00100  *  @return         The number of mbed_stats_stack_t structures that have been filled.
00101  *                  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.
00102  *                  If the number of stacks on the system is greater than count, it will equal count.
00103  */
00104 size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count);
00105 
00106 /**
00107  * struct mbed_stats_cpu_t definition
00108  */
00109 typedef struct {
00110     us_timestamp_t uptime;            /**< Time since the system has started */
00111     us_timestamp_t idle_time;         /**< Time spent in the idle thread since the system has started */
00112     us_timestamp_t sleep_time;        /**< Time spent in sleep since the system has started */
00113     us_timestamp_t deep_sleep_time;   /**< Time spent in deep sleep since the system has started */
00114 } mbed_stats_cpu_t;
00115 
00116 /**
00117  *  Fill the passed in CPU stat structure with CPU statistics.
00118  *
00119  *  @param stats    A pointer to the mbed_stats_cpu_t structure to fill
00120  */
00121 void mbed_stats_cpu_get(mbed_stats_cpu_t *stats);
00122 
00123 /**
00124  * struct mbed_stats_thread_t definition
00125  */
00126 typedef struct {
00127     uint32_t id;                /**< ID of the thread */
00128     uint32_t state;             /**< State of the thread */
00129     uint32_t priority;          /**< Priority of the thread (higher number indicates higher priority) */
00130     uint32_t stack_size;        /**< Current number of bytes reserved for the stack */
00131     uint32_t stack_space;       /**< Current number of free bytes remaining on the stack */
00132     const char   *name;         /**< Name of the thread */
00133 } mbed_stats_thread_t;
00134 
00135 /**
00136  *  Fill the passed array of stat structures with the thread statistics for each available thread.
00137  *
00138  *  @param stats    A pointer to an array of mbed_stats_thread_t structures to fill
00139  *  @param count    The number of mbed_stats_thread_t structures in the provided array
00140  *  @return         The number of mbed_stats_thread_t structures that have been filled.
00141  *                  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.
00142  *                  If the number of threads on the system is greater than count, it will equal count.
00143  */
00144 size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count);
00145 
00146 /**
00147  * enum mbed_compiler_id_t definition
00148  */
00149 typedef enum {
00150     ARM = 1,                    /**< ARM */
00151     GCC_ARM,                    /**< GNU ARM */
00152     IAR                         /**< IAR */
00153 } mbed_compiler_id_t;
00154 
00155 /**
00156  * struct mbed_stats_sys_t definition
00157  */
00158 typedef struct {
00159     uint32_t os_version;                        /**< Mbed OS version (populated only for tagged releases) */
00160     uint32_t cpu_id;                            /**< CPUID register data (Cortex-M only supported) */
00161     mbed_compiler_id_t compiler_id;             /**< Compiler ID \ref mbed_compiler_id_t */
00162     uint32_t compiler_version;                  /**< Compiler version */
00163     uint32_t ram_start[MBED_MAX_MEM_REGIONS];   /**< Start addresses of all internal RAM memories */
00164     uint32_t ram_size[MBED_MAX_MEM_REGIONS];    /**< Size of all internal RAM memories in target */
00165     uint32_t rom_start[MBED_MAX_MEM_REGIONS];   /**< Start addresses of all internal ROM memories */
00166     uint32_t rom_size[MBED_MAX_MEM_REGIONS];    /**< Size of all internal ROM memories in target */
00167 } mbed_stats_sys_t;
00168 
00169 /**
00170  *  Fill the passed in system stat structure with system statistics.
00171  *
00172  *  @param stats    A pointer to the mbed_stats_sys_t structure to fill
00173  */
00174 void mbed_stats_sys_get(mbed_stats_sys_t *stats);
00175 
00176 #ifdef __cplusplus
00177 }
00178 #endif
00179 
00180 #endif
00181 
00182 /** @}*/
00183 
00184 /** @}*/