mbed_stats.h 5.5 KB

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