heap: Add trace hash map config

- and place all added functions and vairables related to the hashmap in RAM
when the config is enabled only.

- add number of hash map entry as a Kconfig value and remove the hash map init function.
This prevents the user from allocating the hash map in flash and pass the pointer to the
init function (as the heap trace manipulate the hash map from functions placed in IRAM).

- add max linear value to the KConfig to make it configurable by the users.

- protect access to static variable "tracing"

- remove unecessary field in heap_trace_hashmap_entry_t
This commit is contained in:
Guillaume Souchere
2023-03-01 12:42:14 +01:00
parent b699033ab3
commit bdfc348ab3
3 changed files with 152 additions and 149 deletions

View File

@@ -41,11 +41,6 @@ typedef struct heap_trace_record_t {
#endif // CONFIG_HEAP_TRACING_STANDALONE
} heap_trace_record_t;
typedef struct heap_trace_hashmap_entry_t {
void* address; ///< ptr returned by malloc/calloc/realloc
heap_trace_record_t* record; ///< associated record
} heap_trace_hashmap_entry_t;
/**
* @brief Stores information about the result of a heap trace.
*/
@@ -57,8 +52,10 @@ typedef struct {
size_t capacity; ///< The capacity of the internal buffer
size_t high_water_mark; ///< The maximum value that 'count' got to
size_t has_overflowed; ///< True if the internal buffer overflowed at some point
#if CONFIG_HEAP_TRACE_HASH_MAP
size_t total_hashmap_hits; ///< If hashmap is used, the total number of hits
size_t total_hashmap_miss; ///< If hashmap is used, the total number of misses (possibly due to overflow)
#endif
} heap_trace_summary_t;
/**
@@ -78,22 +75,6 @@ typedef struct {
*/
esp_err_t heap_trace_init_standalone(heap_trace_record_t *record_buffer, size_t num_records);
/**
* @brief Provide a hashmap to greatly improve the performance of standalone heap trace leaks mode.
*
* This function must be called before heap_trace_start.
*
* @param entries_buffer Provide a buffer to use for heap trace hashmap.
* Note: External RAM is allowed, but it prevents recording allocations made from ISR's.
* @param num_entries Size of the entries_buffer. Should be greater than num_records, preferably 2-4x as large.
* @return
* - ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig.
* - ESP_ERR_INVALID_STATE Heap tracing is currently in progress.
* - ESP_OK Heap tracing initialised successfully.
*/
esp_err_t heap_trace_set_hashmap(heap_trace_hashmap_entry_t *entries_buffer, size_t num_entries);
/**
* @brief Initialise heap tracing in host-based mode.
*