Show PSRAM usage (#2206)

* centralize PSRAM usage (application code only)

* update logging

* update logging

* fix use after free

* initialize buffer

* free rgb_image before ussing it for new allocation

* use wrapper function

* switch log level to debug

* .

* undo adding free() calls

* .

* add names to all CImage instances

* .

* .

* .

* revert changes of stbi_image_free() with free_psram_heap() on the places where is is not in PSRAM

* .

* typos

* typo

* Added MQTT Outbox explanation/warning

* added CONFIG_SPIRAM_USE_MEMMAP explanation

---------

Co-authored-by: CaCO3 <caco@ruinelli.ch>
This commit is contained in:
CaCO3
2023-03-19 23:28:06 +01:00
committed by GitHub
parent d93c5daf14
commit 58185a0569
20 changed files with 151 additions and 76 deletions

View File

@@ -1,6 +1,7 @@
#include "CTfLiteClass.h"
#include "ClassLogFile.h"
#include "Helper.h"
#include "psram.h"
#include "esp_log.h"
#include "../../include/defines.h"
@@ -250,7 +251,7 @@ bool CTfLiteClass::ReadFileToModel(std::string _fn)
LogFile.WriteHeapInfo("CTLiteClass::Alloc modelfile start");
#endif
modelfile = (unsigned char*)GET_MEMORY(size);
modelfile = (unsigned char*)malloc_psram_heap(std::string(TAG) + "->modelfile", size, MALLOC_CAP_SPIRAM);
if(modelfile != NULL)
{
@@ -305,17 +306,17 @@ CTfLiteClass::CTfLiteClass()
this->input = nullptr;
this->output = nullptr;
this->kTensorArenaSize = 800 * 1024; /// according to testfile: 108000 - so far 600;; 2021-09-11: 200 * 1024
this->tensor_arena = (uint8_t*)GET_MEMORY(kTensorArenaSize);
this->tensor_arena = (uint8_t*)malloc_psram_heap(std::string(TAG) + "->tensor_arena", kTensorArenaSize, MALLOC_CAP_SPIRAM);
}
CTfLiteClass::~CTfLiteClass()
{
free(modelfile);
free(this->tensor_arena);
delete this->interpreter;
delete this->error_reporter;
free_psram_heap(std::string(TAG) + "->modelfile", modelfile);
free_psram_heap(std::string(TAG) + "->tensor_arena", this->tensor_arena);
}

View File

@@ -25,6 +25,7 @@
#include "read_wlanini.h"
#include "connect_wlan.h"
#include "psram.h"
ClassFlowControll tfliteflow;
@@ -151,12 +152,12 @@ esp_err_t handler_get_heap(httpd_req_t *req)
std::string zw = "Heap info:<br>" + getESPHeapInfo();
#ifdef TASK_ANALYSIS_ON
char* pcTaskList = (char*) heap_caps_calloc(1, sizeof(char) * 768, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
char* pcTaskList = (char*) calloc_psram_heap(std::string(TAG) + "->pcTaskList", 1, sizeof(char) * 768, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
if (pcTaskList) {
vTaskList(pcTaskList);
zw = zw + "<br><br>Task info:<br><pre>Name | State | Prio | Lowest stacksize | Creation order | CPU (-1=NoAffinity)<br>"
+ std::string(pcTaskList) + "</pre>";
heap_caps_free(pcTaskList);
free_psram_heap(std::string(TAG) + "->pcTaskList", pcTaskList);
}
else {
zw = zw + "<br><br>Task info:<br>ERROR - Allocation of TaskList buffer in PSRAM failed";
@@ -617,11 +618,11 @@ esp_err_t handler_editflow(httpd_req_t *req)
string out2 = out.substr(0, out.length() - 4) + "_org.jpg";
CAlignAndCutImage *caic = new CAlignAndCutImage(in);
CAlignAndCutImage *caic = new CAlignAndCutImage("cutref", in);
caic->CutAndSave(out2, x, y, dx, dy);
delete caic;
CImageBasis *cim = new CImageBasis(out2);
CImageBasis *cim = new CImageBasis("cutref", out2);
if (enhance)
{
cim->Contrast(90);