mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 12:36:52 +03:00
Heap tracing (#1861)
* Update sdkconfig.esp32cam-dev-task-analysis.defaults * Update defines.h * Update platformio.ini * Update main.cpp * Update defines.h * Update ClassFlowCNNGeneral.cpp * Update platformio.ini
This commit is contained in:
@@ -12,7 +12,12 @@
|
||||
|
||||
static const char* TAG = "CNN";
|
||||
|
||||
//#define DEBUG_DETAIL_ON
|
||||
//#ifdef CONFIG_HEAP_TRACING_STANDALONE
|
||||
#ifdef HEAP_TRACING_CLASS_FLOW_CNN_GENERAL_DO_ALING_AND_CUT
|
||||
#include <esp_heap_trace.h>
|
||||
#define NUM_RECORDS 300
|
||||
static heap_trace_record_t trace_record[NUM_RECORDS]; // This buffer must be in internal RAM
|
||||
#endif
|
||||
|
||||
|
||||
ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNType _cnntype) : ClassFlowImage(NULL, TAG)
|
||||
@@ -462,6 +467,14 @@ string ClassFlowCNNGeneral::getHTMLSingleStep(string host)
|
||||
|
||||
bool ClassFlowCNNGeneral::doFlow(string time)
|
||||
{
|
||||
|
||||
#ifdef HEAP_TRACING_CLASS_FLOW_CNN_GENERAL_DO_ALING_AND_CUT
|
||||
//register a buffer to record the memory trace
|
||||
ESP_ERROR_CHECK( heap_trace_init_standalone(trace_record, NUM_RECORDS) );
|
||||
// start tracing
|
||||
ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
|
||||
#endif
|
||||
|
||||
if (disabled)
|
||||
return true;
|
||||
|
||||
@@ -474,6 +487,12 @@ bool ClassFlowCNNGeneral::doFlow(string time)
|
||||
doNeuralNetwork(time);
|
||||
|
||||
RemoveOldLogs();
|
||||
|
||||
#ifdef HEAP_TRACING_CLASS_FLOW_CNN_GENERAL_DO_ALING_AND_CUT
|
||||
ESP_ERROR_CHECK( heap_trace_stop() );
|
||||
heap_trace_dump();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,17 @@
|
||||
// server_tflite.cpp
|
||||
//#define TASK_ANALYSIS_ON
|
||||
|
||||
|
||||
//Memory leak tracing
|
||||
//https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/heap_debug.html#heap-information
|
||||
//need CONFIG_HEAP_TRACING_STANDALONE=y or #define CONFIG_HEAP_TRACING_STANDALONE
|
||||
//all setup is predifined in [env:esp32cam-dev-task-analysis]
|
||||
//#define HEAP_TRACING_MAIN_WIFI || HEAP_TRACING_MAIN_START //enable heap tracing per function in main.cpp
|
||||
//all defines in [env:esp32cam-dev-task-analysis]
|
||||
//#define HEAP_TRACING_MAIN_WIFI
|
||||
//#define HEAP_TRACING_MAIN_START
|
||||
//#define HEAP_TRACING_CLASS_FLOW_CNN_GENERAL_DO_ALING_AND_CUT
|
||||
|
||||
/* Uncomment this to keep the logfile open for appending.
|
||||
* If commented out, the logfile gets opened/closed for each log measage (old behaviour) */
|
||||
// ClassLogFile
|
||||
|
||||
@@ -62,6 +62,13 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//#ifdef CONFIG_HEAP_TRACING_STANDALONE
|
||||
#if defined HEAP_TRACING_MAIN_WIFI || defined HEAP_TRACING_MAIN_START
|
||||
#include <esp_heap_trace.h>
|
||||
#define NUM_RECORDS 300
|
||||
static heap_trace_record_t trace_record[NUM_RECORDS]; // This buffer must be in internal RAM
|
||||
#endif
|
||||
|
||||
extern const char* GIT_TAG;
|
||||
extern const char* GIT_REV;
|
||||
extern const char* GIT_BRANCH;
|
||||
@@ -162,6 +169,13 @@ void task_MainInitError_blink(void *pvParameter)
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
|
||||
//#ifdef CONFIG_HEAP_TRACING_STANDALONE
|
||||
#if defined HEAP_TRACING_MAIN_WIFI || defined HEAP_TRACING_MAIN_START
|
||||
//register a buffer to record the memory trace
|
||||
ESP_ERROR_CHECK( heap_trace_init_standalone(trace_record, NUM_RECORDS) );
|
||||
#endif
|
||||
|
||||
TickType_t xDelay;
|
||||
|
||||
#ifdef DISABLE_BROWNOUT_DETECTOR
|
||||
@@ -224,6 +238,10 @@ extern "C" void app_main(void)
|
||||
CheckStartAPMode(); // if no wlan.ini and/or config.ini --> AP ist startet and this function does not exit anymore until reboot
|
||||
#endif
|
||||
|
||||
#ifdef HEAP_TRACING_MAIN_WIFI
|
||||
ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
|
||||
#endif
|
||||
|
||||
char *ssid = NULL, *passwd = NULL, *hostname = NULL, *ip = NULL, *gateway = NULL, *netmask = NULL, *dns = NULL; int rssithreashold = 0;
|
||||
LoadWlanFromFile(WLAN_CONFIG_FILE, ssid, passwd, hostname, ip, gateway, netmask, dns, rssithreashold);
|
||||
|
||||
@@ -257,6 +275,15 @@ extern "C" void app_main(void)
|
||||
ESP_LOGD(TAG, "main: sleep for: %ldms", (long) xDelay);
|
||||
vTaskDelay( xDelay );
|
||||
|
||||
#ifdef HEAP_TRACING_MAIN_WIFI
|
||||
ESP_ERROR_CHECK( heap_trace_stop() );
|
||||
heap_trace_dump();
|
||||
#endif
|
||||
|
||||
#ifdef HEAP_TRACING_MAIN_START
|
||||
ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
|
||||
#endif
|
||||
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "=================================================");
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "================== Main Started =================");
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "=================================================");
|
||||
@@ -269,6 +296,11 @@ extern "C" void app_main(void)
|
||||
std::string zw = getCurrentTimeString("%Y%m%d-%H%M%S");
|
||||
ESP_LOGD(TAG, "time %s", zw.c_str());
|
||||
|
||||
#ifdef HEAP_TRACING_MAIN_START
|
||||
ESP_ERROR_CHECK( heap_trace_stop() );
|
||||
heap_trace_dump();
|
||||
#endif
|
||||
|
||||
/* Check if PSRAM can be initalized */
|
||||
esp_err_t ret;
|
||||
ret = esp_spiram_init();
|
||||
|
||||
@@ -193,6 +193,10 @@ extends = env:esp32cam-dev, esp32cam-debug
|
||||
build_flags =
|
||||
;-D DEBUG_DETAIL_ON ; if esp32cam-debug not in extends
|
||||
-D TASK_ANALYSIS_ON
|
||||
;please use only one HEAP tracing at time.
|
||||
-D HEAP_TRACING_MAIN_WIFI
|
||||
;-D HEAP_TRACING_MAIN_START
|
||||
;-D HEAP_TRACING_CLASS_FLOW_CNN_GENERAL_DO_ALING_AND_CUT
|
||||
|
||||
|
||||
; Overwrite espcam build_flags to not include ENABLE_SOFTAP
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
CONFIG_FREERTOS_USE_TRACE_FACILITY=1
|
||||
CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
|
||||
CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y
|
||||
|
||||
CONFIG_HEAP_TRACING_STANDALONE=y
|
||||
CONFIG_HEAP_POISONING_LIGHT=y
|
||||
CONFIG_HEAP_TASK_TRACKING=y
|
||||
|
||||
|
||||
# General options for additional checks
|
||||
CONFIG_HEAP_POISONING_COMPREHENSIVE=y
|
||||
CONFIG_COMPILER_WARN_WRITE_STRINGS=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
|
||||
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y
|
||||
CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y
|
||||
CONFIG_COMPILER_STACK_CHECK=y
|
||||
|
||||
CONFIG_ESP_TASK_WDT=n
|
||||
|
||||
Reference in New Issue
Block a user