From 62a2f127b4ffa62bf2e3ff57f91e752b61e4bd95 Mon Sep 17 00:00:00 2001 From: Slider0007 <115730895+Slider0007@users.noreply.github.com> Date: Tue, 3 Jan 2023 08:10:08 +0100 Subject: [PATCH] Modify stack sizes + max open files (SD) , add REST handler for heap/(stack) infos (#1751) * Modify stack sizes+max open files,add rest handler * Update --- .../jomjol_controlGPIO/server_GPIO.cpp | 2 +- .../jomjol_tfliteclass/server_tflite.cpp | 51 +++++++++++++++++-- code/components/jomjol_wlan/connect_wlan.cpp | 2 +- code/include/defines.h | 12 +++++ code/main/main.cpp | 2 +- code/main/server_main.cpp | 8 +-- code/sdkconfig.defaults | 5 ++ 7 files changed, 70 insertions(+), 12 deletions(-) diff --git a/code/components/jomjol_controlGPIO/server_GPIO.cpp b/code/components/jomjol_controlGPIO/server_GPIO.cpp index ba5dd92e..13d287f4 100644 --- a/code/components/jomjol_controlGPIO/server_GPIO.cpp +++ b/code/components/jomjol_controlGPIO/server_GPIO.cpp @@ -250,7 +250,7 @@ void GpioHandler::init() if (xHandleTaskGpio == NULL) { gpio_queue_handle = xQueueCreate(10,sizeof(GpioResult)); - BaseType_t xReturned = xTaskCreate(&gpioHandlerTask, "gpio_int", configMINIMAL_STACK_SIZE * 8, (void *)this, tskIDLE_PRIORITY + 2, &xHandleTaskGpio); + BaseType_t xReturned = xTaskCreate(&gpioHandlerTask, "gpio_int", 3 * 1024, (void *)this, tskIDLE_PRIORITY + 4, &xHandleTaskGpio); if(xReturned == pdPASS ) { ESP_LOGD(TAG, "xHandletaskGpioHandler started"); } else { diff --git a/code/components/jomjol_tfliteclass/server_tflite.cpp b/code/components/jomjol_tfliteclass/server_tflite.cpp index 20a6bb7d..ebca7b63 100644 --- a/code/components/jomjol_tfliteclass/server_tflite.cpp +++ b/code/components/jomjol_tfliteclass/server_tflite.cpp @@ -134,6 +134,45 @@ bool doflow(void) } +esp_err_t handler_get_heap(httpd_req_t *req) +{ + #ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_get_heap - Start"); + ESP_LOGD(TAG, "handler_get_heap uri: %s", req->uri); + #endif + + std::string zw = "Heap info:
" + getESPHeapInfo(); + + #ifdef TASK_ANALYSIS_ON + char* pcTaskList = (char*) heap_caps_calloc(1, sizeof(char) * 768, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + if (pcTaskList) { + vTaskList(pcTaskList); + zw = zw + "

Task info:
Name | State | Prio | Lowest stacksize | Creation order | CPU (-1=NoAffinity)
" + + std::string(pcTaskList) + "
"; + heap_caps_free(pcTaskList); + } + else { + zw = zw + "

Task info:
ERROR - Allocation of TaskList buffer in PSRAM failed"; + } + #endif + + if (zw.length() > 0) + { + httpd_resp_send(req, zw.c_str(), zw.length()); + } + else + { + httpd_resp_send(req, NULL, 0); + } + + #ifdef DEBUG_DETAIL_ON + LogFile.WriteHeapInfo("handler_get_heap - Done"); + #endif + + return ESP_OK; +} + + esp_err_t handler_init(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON @@ -875,15 +914,12 @@ void TFliteDoAutoStart() { BaseType_t xReturned; - int _i = configMINIMAL_STACK_SIZE; - - ESP_LOGD(TAG, "task_autodoFlow configMINIMAL_STACK_SIZE: %d", _i); ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str()); - xReturned = xTaskCreate(&task_autodoFlow, "task_autodoFlow", configMINIMAL_STACK_SIZE * 35, NULL, tskIDLE_PRIORITY+1, &xHandletask_autodoFlow); + xReturned = xTaskCreatePinnedToCore(&task_autodoFlow, "task_autodoFlow", 16 * 1024, NULL, tskIDLE_PRIORITY+2, &xHandletask_autodoFlow, 0); + //xReturned = xTaskCreate(&task_autodoFlow, "task_autodoFlow", 16 * 1024, NULL, tskIDLE_PRIORITY+2, &xHandletask_autodoFlow); if( xReturned != pdPASS ) { - //Memory: 64 --> 48 --> 35 --> 25 ESP_LOGD(TAG, "ERROR task_autodoFlow konnte nicht erzeugt werden!"); } ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str()); @@ -989,4 +1025,9 @@ void register_server_tflite_uri(httpd_handle_t server) camuri.handler = handler_json; camuri.user_ctx = (void*) "JSON"; httpd_register_uri_handler(server, &camuri); + + camuri.uri = "/heap"; + camuri.handler = handler_get_heap; + camuri.user_ctx = (void*) "Heap"; + httpd_register_uri_handler(server, &camuri); } diff --git a/code/components/jomjol_wlan/connect_wlan.cpp b/code/components/jomjol_wlan/connect_wlan.cpp index 3e4a9324..59c42976 100644 --- a/code/components/jomjol_wlan/connect_wlan.cpp +++ b/code/components/jomjol_wlan/connect_wlan.cpp @@ -354,7 +354,7 @@ void LEDBlinkTask(int _dauer, int _anz, bool _off) BlinkAnzahl = _anz; BlinkOff = _off; - xTaskCreate(&task_doBlink, "task_doBlink", configMINIMAL_STACK_SIZE * 8, NULL, tskIDLE_PRIORITY+1, NULL); + xTaskCreate(&task_doBlink, "task_doBlink", 4 * 1024, NULL, tskIDLE_PRIORITY+1, NULL); } ///////////////////////////////////////////////////////// diff --git a/code/include/defines.h b/code/include/defines.h index c73dabdd..36fe93ef 100644 --- a/code/include/defines.h +++ b/code/include/defines.h @@ -6,6 +6,18 @@ //// Global definitions //// ///////////////////////////////////////////// + /* Uncomment this to generate task list with stack sizes using the /heap handler + PLEASE BE AWARE: The following CONFIG parameters have to to be set in + sdkconfig.defaults before use of this function is possible!! + + CONFIG_FREERTOS_USE_TRACE_FACILITY=1 + CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y + CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y + */ + // server_tflite.cpp + //#define TASK_ANALYSIS_ON + + /* Uncomment this to keep the logfile open for appending. * If commented out, the logfile gets opened/closed for each log measage (old behaviour) */ // ClassLogFile diff --git a/code/main/main.cpp b/code/main/main.cpp index c37512a8..ebcf799c 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -92,7 +92,7 @@ bool Init_NVS_SDCard() // formatted in case when mounting fails. esp_vfs_fat_sdmmc_mount_config_t mount_config = { .format_if_mount_failed = false, - .max_files = 7, // anstatt 5 (2022-09-21) + .max_files = 12, // previously -> 2022-09-21: 5, 2023-01-02: 7 .allocation_unit_size = 16 * 1024 }; diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 56863f2f..17556050 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -451,13 +451,13 @@ httpd_handle_t start_webserver(void) httpd_handle_t server = NULL; httpd_config_t config = { }; - config.task_priority = tskIDLE_PRIORITY+3; //20221211: before: tskIDLE_PRIORITY+1; // 20210924 --> before +5 - config.stack_size = 32768; //20210921 --> before 32768 // at 32k the programme crashes when taking pictures - config.core_id = 0; //20221211 --> force all not flow related tasks to CPU0, before: tskNO_AFFINITY; + config.task_priority = tskIDLE_PRIORITY+3; // previously -> 2022-12-11: tskIDLE_PRIORITY+1; 2021-09-24: tskIDLE_PRIORITY+5 + config.stack_size = 12288; // previously -> 2023-01-02: 32768 + config.core_id = 1; // previously -> 2023-01-02: 0, 2022-12-11: tskNO_AFFINITY; config.server_port = 80; config.ctrl_port = 32768; config.max_open_sockets = 5; //20210921 --> previously 7 - config.max_uri_handlers = 38; // previously 24, 20220511: 35, 20221220: 37 + config.max_uri_handlers = 38; // previously 24, 20220511: 35, 20221220: 37, 2023-01-02:38 config.max_resp_headers = 8; config.backlog_conn = 5; config.lru_purge_enable = true; // this cuts old connections if new ones are needed. diff --git a/code/sdkconfig.defaults b/code/sdkconfig.defaults index 5c72a824..a34d322b 100644 --- a/code/sdkconfig.defaults +++ b/code/sdkconfig.defaults @@ -132,3 +132,8 @@ CONFIG_GC2145_SUPPORT=n CONFIG_GC032A_SUPPORT=n CONFIG_GC0308_SUPPORT=n CONFIG_BF3005_SUPPORT=n + +#only necessary for task analysis (include/defines -> TASK_ANALYSIS_ON) +#CONFIG_FREERTOS_USE_TRACE_FACILITY=1 +#CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y +#CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y