mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-07-15 08:32:42 +08:00
feat(heap): add option to enable/disable heap trace function
This commit is contained in:
@ -1,10 +1,16 @@
|
|||||||
|
|
||||||
menu "Heap memory"
|
menu "Heap memory"
|
||||||
|
|
||||||
config HEAP_DISABLE_IRAM
|
config HEAP_DISABLE_IRAM
|
||||||
bool "Disable IRAM as heap memory"
|
bool "Disable IRAM as heap memory"
|
||||||
default n
|
default n
|
||||||
help
|
help
|
||||||
Disable IRAM as heap memory, and heap memory only use DRAM.
|
Disable IRAM as heap memory, and heap memory only use DRAM.
|
||||||
|
|
||||||
|
config HEAP_TRACING
|
||||||
|
bool "Enables heap tracing API"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
Enables heap tracing API.
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
@ -51,6 +51,7 @@ typedef struct mem_blk {
|
|||||||
/**
|
/**
|
||||||
* Second type memory block.
|
* Second type memory block.
|
||||||
*/
|
*/
|
||||||
|
#ifdef CONFIG_HEAP_TRACING
|
||||||
typedef struct mem_blk2 {
|
typedef struct mem_blk2 {
|
||||||
struct mem_blk2 *prev; ///< Point to previous memory block
|
struct mem_blk2 *prev; ///< Point to previous memory block
|
||||||
struct mem_blk2 *next; ///< Point to next memory block
|
struct mem_blk2 *next; ///< Point to next memory block
|
||||||
@ -58,6 +59,9 @@ typedef struct mem_blk2 {
|
|||||||
const char *file; ///< Which "file" allocate the memory block
|
const char *file; ///< Which "file" allocate the memory block
|
||||||
size_t line; ///< Which "line" allocate the memory block
|
size_t line; ///< Which "line" allocate the memory block
|
||||||
} mem2_blk_t;
|
} mem2_blk_t;
|
||||||
|
#else
|
||||||
|
typedef mem_blk_t mem2_blk_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User region information.
|
* User region information.
|
||||||
|
@ -14,12 +14,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "sdkconfig.h"
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_HEAP_TRACING
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HEAP_TRACE_NONE = 0,
|
HEAP_TRACE_NONE = 0,
|
||||||
|
|
||||||
@ -80,6 +83,8 @@ esp_err_t heap_trace_resume(void);
|
|||||||
*/
|
*/
|
||||||
void heap_trace_dump(void);
|
void heap_trace_dump(void);
|
||||||
|
|
||||||
|
#endif /* CONFIG_HEAP_TRACING */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "sdkconfig.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -21,7 +22,12 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MEM_BLK_TAG 0x80000000 ///< Mark the memory block used
|
#define MEM_BLK_TAG 0x80000000 ///< Mark the memory block used
|
||||||
|
|
||||||
|
#ifdef CONFIG_HEAP_TRACING
|
||||||
#define MEM_BLK_TRACE 0x80000000 ///< Mark the memory block traced
|
#define MEM_BLK_TRACE 0x80000000 ///< Mark the memory block traced
|
||||||
|
#else
|
||||||
|
#define MEM_BLK_TRACE 0x00000000 ///< Mark the memory block traced
|
||||||
|
#endif
|
||||||
|
|
||||||
#define _mem_blk_get_ptr(_mem_blk, _offset, _mask) \
|
#define _mem_blk_get_ptr(_mem_blk, _offset, _mask) \
|
||||||
((mem_blk_t *)((((uint32_t *)(_mem_blk))[_offset]) & (~_mask)))
|
((mem_blk_t *)((((uint32_t *)(_mem_blk))[_offset]) & (~_mask)))
|
||||||
@ -47,12 +53,14 @@ static inline size_t mem_blk_head_size(bool trace)
|
|||||||
|
|
||||||
static inline void mem_blk_set_traced(mem2_blk_t *mem_blk, const char *file, size_t line)
|
static inline void mem_blk_set_traced(mem2_blk_t *mem_blk, const char *file, size_t line)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_HEAP_TRACING
|
||||||
uint32_t *val = (uint32_t *)mem_blk + 1;
|
uint32_t *val = (uint32_t *)mem_blk + 1;
|
||||||
|
|
||||||
*val |= MEM_BLK_TRACE;
|
*val |= MEM_BLK_TRACE;
|
||||||
|
|
||||||
mem_blk->file = file;
|
mem_blk->file = file;
|
||||||
mem_blk->line = line | MEM_BLK_TRACE;
|
mem_blk->line = line | MEM_BLK_TRACE;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void mem_blk_set_untraced(mem2_blk_t *mem_blk)
|
static inline void mem_blk_set_untraced(mem2_blk_t *mem_blk)
|
||||||
@ -154,10 +162,12 @@ static inline size_t ptr_size(void *ptr)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_HEAP_TRACING
|
||||||
static inline size_t mem2_blk_line(mem2_blk_t *mem2_blk)
|
static inline size_t mem2_blk_line(mem2_blk_t *mem2_blk)
|
||||||
{
|
{
|
||||||
return mem2_blk->line & ~MEM_BLK_TRACE;
|
return mem2_blk->line & ~MEM_BLK_TRACE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,9 @@ extern heap_region_t g_heap_region[];
|
|||||||
|
|
||||||
static const char *TAG = "heap_init";
|
static const char *TAG = "heap_init";
|
||||||
size_t g_heap_region_num;
|
size_t g_heap_region_num;
|
||||||
|
#ifdef CONFIG_HEAP_TRACING
|
||||||
int __g_heap_trace_mode = HEAP_TRACE_NONE;
|
int __g_heap_trace_mode = HEAP_TRACE_NONE;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize regions of memory to the collection of heaps at runtime.
|
* @brief Initialize regions of memory to the collection of heaps at runtime.
|
||||||
@ -116,7 +118,9 @@ void IRAM_ATTR *_heap_caps_malloc(size_t size, uint32_t caps, const char *file,
|
|||||||
|
|
||||||
_heap_caps_lock(num);
|
_heap_caps_lock(num);
|
||||||
|
|
||||||
|
#ifdef CONFIG_HEAP_TRACING
|
||||||
trace = __g_heap_trace_mode == HEAP_TRACE_LEAKS;
|
trace = __g_heap_trace_mode == HEAP_TRACE_LEAKS;
|
||||||
|
#endif
|
||||||
|
|
||||||
mem_blk_size = ptr2memblk_size(size, trace);
|
mem_blk_size = ptr2memblk_size(size, trace);
|
||||||
|
|
||||||
|
@ -12,6 +12,10 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_HEAP_TRACING
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "esp_heap_caps.h"
|
#include "esp_heap_caps.h"
|
||||||
@ -146,3 +150,5 @@ void heap_trace_dump(void)
|
|||||||
_heap_caps_unlock(num);
|
_heap_caps_unlock(num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_HEAP_TRACING */
|
||||||
|
Reference in New Issue
Block a user