takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

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 allocated currently. */
00046     uint32_t max_size;          /**< Max bytes allocated at a given time. */
00047     uint32_t total_size;        /**< Cumulative sum of bytes ever allocated. */
00048     uint32_t reserved_size;     /**< Current number of bytes allocated for the heap. */
00049     uint32_t alloc_cnt;         /**< Current number of allocations. */
00050     uint32_t alloc_fail_cnt;    /**< Number of failed allocations. */
00051     uint32_t overhead_size;     /**< Overhead added to heap for stats. */
00052 } mbed_stats_heap_t;
00053 
00054 /**
00055  *  Fill the passed in heap stat structure with heap stats.
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 thread that owns the stack or 0 if multiple threads. */
00066     uint32_t max_size;          /**< Maximum number of bytes used on the stack. */
00067     uint32_t reserved_size;     /**< Current number of bytes allocated for the stack. */
00068     uint32_t stack_cnt;         /**< Number of stacks stats accumulated in the structure. */
00069 } mbed_stats_stack_t;
00070 
00071 /**
00072  *  Fill the passed in structure with stack stats 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 stat structures with the stack stats 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  *                  this is equal to the number of stacks on the system.
00086  */
00087 size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count);
00088 
00089 /**
00090  * struct mbed_stats_cpu_t definition
00091  */
00092 typedef struct {
00093     us_timestamp_t uptime;            /**< Time since system is up and running */
00094     us_timestamp_t idle_time;         /**< Time spent in idle thread since system is up and running */
00095     us_timestamp_t sleep_time;        /**< Time spent in sleep since system is up and running */
00096     us_timestamp_t deep_sleep_time;   /**< Time spent in deep sleep since system is up and running */
00097 } mbed_stats_cpu_t;
00098 
00099 /**
00100  *  Fill the passed in CPU stat structure with CPU statistics.
00101  *
00102  *  @param stats    A pointer to the mbed_stats_cpu_t structure to fill
00103  */
00104 void mbed_stats_cpu_get(mbed_stats_cpu_t *stats);
00105 
00106 /**
00107  * struct mbed_stats_thread_t definition
00108  */
00109 typedef struct {
00110     uint32_t id;                /**< Thread Object Identifier */
00111     uint32_t state;             /**< Thread Object State */
00112     uint32_t priority;          /**< Thread Priority */
00113     uint32_t stack_size;        /**< Thread Stack Size */
00114     uint32_t stack_space;       /**< Thread remaining stack size */
00115     const char   *name;         /**< Thread Object name */
00116 } mbed_stats_thread_t;
00117 
00118 /**
00119  *  Fill the passed array of stat structures with the thread stats for each available thread.
00120  *
00121  *  @param stats    A pointer to an array of mbed_stats_thread_t structures to fill
00122  *  @param count    The number of mbed_stats_thread_t structures in the provided array
00123  *  @return         The number of mbed_stats_thread_t structures that have been filled,
00124  *                  this is equal to the number of threads on the system.
00125  */
00126 size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count);
00127 
00128 /**
00129  * enum mbed_compiler_id_t definition
00130  */
00131 typedef enum {
00132     ARM = 1,                    /**< ARM */
00133     GCC_ARM,                    /**< GNU ARM */
00134     IAR                         /**< IAR */
00135 } mbed_compiler_id_t;
00136 
00137 /**
00138  * struct mbed_stats_sys_t definition
00139  */
00140 typedef struct {
00141     uint32_t os_version;                /**< Mbed OS Version (Release only) */
00142     uint32_t cpu_id;                    /**< CPUID Register data (Cortex-M only supported) */
00143     mbed_compiler_id_t compiler_id;     /**< Compiler ID \ref mbed_compiler_id_t */
00144     uint32_t compiler_version;          /**< Compiler version */
00145 } mbed_stats_sys_t;
00146 
00147 /**
00148  *  Fill the passed in sys stat structure with system stats.
00149  *
00150  *  @param stats    A pointer to the mbed_stats_sys_t structure to fill
00151  */
00152 void mbed_stats_sys_get(mbed_stats_sys_t *stats);
00153 
00154 #ifdef __cplusplus
00155 }
00156 #endif
00157 
00158 #endif
00159 
00160 /** @}*/
00161 
00162 /** @}*/