MoJo / ER2_Robot_gnuarmeclipse_lpc1768-V2

Dependencies:   mbed

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