esp_heap_task_info.h 4.3 KB

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