esp_heap_task_info.h 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2018 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. #ifdef CONFIG_HEAP_TASK_TRACKING
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. // This macro controls how much space is provided for partitioning the per-task
  19. // heap allocation info according to one or more sets of heap capabilities.
  20. #define NUM_HEAP_TASK_CAPS 4
  21. /** @brief Structure to collect per-task heap allocation totals partitioned by selected caps */
  22. typedef struct {
  23. TaskHandle_t task; ///< Task to which these totals belong
  24. size_t size[NUM_HEAP_TASK_CAPS]; ///< Total allocations partitioned by selected caps
  25. size_t count[NUM_HEAP_TASK_CAPS]; ///< Number of blocks partitioned by selected caps
  26. } heap_task_totals_t;
  27. /** @brief Structure providing details about a block allocated by a task */
  28. typedef struct {
  29. TaskHandle_t task; ///< Task that allocated the block
  30. void *address; ///< User address of allocated block
  31. uint32_t size; ///< Size of the allocated block
  32. } heap_task_block_t;
  33. /** @brief Structure to provide parameters to heap_caps_get_per_task_info
  34. *
  35. * The 'caps' and 'mask' arrays allow partitioning the per-task heap allocation
  36. * totals by selected sets of heap region capabilities so that totals for
  37. * multiple regions can be accumulated in one scan. The capabilities flags for
  38. * each region ANDed with mask[i] are compared to caps[i] in order; the
  39. * allocations in that region are added to totals->size[i] and totals->count[i]
  40. * for the first i that matches. To collect the totals without any
  41. * partitioning, set mask[0] and caps[0] both to zero. The allocation totals
  42. * are returned in the 'totals' array of heap_task_totals_t structs. To allow
  43. * easily comparing the totals array between consecutive calls, that array can
  44. * be left populated from one call to the next so the order of tasks is the
  45. * same even if some tasks have freed their blocks or have been deleted. The
  46. * number of blocks prepopulated is given by num_totals, which is updated upon
  47. * return. If there are more tasks with allocations than the capacity of the
  48. * totals array (given by max_totals), information for the excess tasks will be
  49. * not be collected. The totals array pointer can be NULL if the totals are
  50. * not desired.
  51. *
  52. * The 'tasks' array holds a list of handles for tasks whose block details are
  53. * to be returned in the 'blocks' array of heap_task_block_t structs. If the
  54. * tasks array pointer is NULL, block details for all tasks will be returned up
  55. * to the capacity of the buffer array, given by max_blocks. The function
  56. * return value tells the number of blocks filled into the array. The blocks
  57. * array pointer can be NULL if block details are not desired, or max_blocks
  58. * can be set to zero.
  59. */
  60. typedef struct {
  61. int32_t caps[NUM_HEAP_TASK_CAPS]; ///< Array of caps for partitioning task totals
  62. int32_t mask[NUM_HEAP_TASK_CAPS]; ///< Array of masks under which caps must match
  63. TaskHandle_t *tasks; ///< Array of tasks whose block info is returned
  64. size_t num_tasks; ///< Length of tasks array
  65. heap_task_totals_t *totals; ///< Array of structs to collect task totals
  66. size_t *num_totals; ///< Number of task structs currently in array
  67. size_t max_totals; ///< Capacity of array of task totals structs
  68. heap_task_block_t *blocks; ///< Array of task block details structs
  69. size_t max_blocks; ///< Capacity of array of task block info structs
  70. } heap_task_info_params_t;
  71. /**
  72. * @brief Return per-task heap allocation totals and lists of blocks.
  73. *
  74. * For each task that has allocated memory from the heap, return totals for
  75. * allocations within regions matching one or more sets of capabilities.
  76. *
  77. * Optionally also return an array of structs providing details about each
  78. * block allocated by one or more requested tasks, or by all tasks.
  79. *
  80. * @param params Structure to hold all the parameters for the function
  81. * (@see heap_task_info_params_t).
  82. * @return Number of block detail structs returned (@see heap_task_block_t).
  83. */
  84. extern size_t heap_caps_get_per_task_info(heap_task_info_params_t *params);
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif // CONFIG_HEAP_TASK_TRACKING