Skip to content

Commit

Permalink
Memory monitor thresholds updated and considering additional the curr…
Browse files Browse the repository at this point in the history
…ent available heap memory.

#153
  • Loading branch information
BlueAndi committed Dec 18, 2023
1 parent 0b713d0 commit be56295
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
18 changes: 12 additions & 6 deletions src/Common/MemMon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,23 @@ void MemMon::process()

if (true == isProcessingTime)
{
uint32_t minFreeHeap = ESP.getMinFreeHeap();
uint32_t minFreeHeapBlock = ESP.getMaxAllocHeap();
uint32_t availableHeap = ESP.getFreeHeap(); /* Current available heap memory. */
uint32_t lowestAvailableHeap = ESP.getMinFreeHeap(); /* Lowest level of available heap since boot. */
uint32_t largestHeapBlock = ESP.getMaxAllocHeap(); /* Largest block of heap that can be allocated at once. */

if (MIN_HEAP_MEMORY >= minFreeHeap)
if (MIN_HEAP_MEMORY >= availableHeap)
{
LOG_WARNING("Min. free heap is %u byte.", minFreeHeap);
LOG_WARNING("Current available heap: %u byte.", availableHeap);
}

if (MIN_HEAP_BLOCK_MEMORY > minFreeHeapBlock)
if (LOWEST_HEAP_MEMORY >= lowestAvailableHeap)
{
LOG_WARNING("Largest heap block which can be allocated is %u byte.", minFreeHeapBlock);
LOG_WARNING("Lowest available heap: %u byte.", lowestAvailableHeap);
}

if (LARGEST_HEAP_BLOCK_MEMORY > largestHeapBlock)
{
LOG_WARNING("Largest heap block which can be allocated: %u byte.", largestHeapBlock);
}

/* Any heap corrupt? */
Expand Down
21 changes: 16 additions & 5 deletions src/Common/MemMon.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,24 @@ class MemMon
void process();

/** Processing cycle in ms. */
static const uint32_t PROCESSING_CYCLE = 60U * 1000U;
static const uint32_t PROCESSING_CYCLE = 60U * 1000U;

/** Minimum size of heap memory in bytes, the monitor starts to warn. */
static const size_t MIN_HEAP_MEMORY = 61440U;
/**
* Minimum size of current heap memory in bytes, the monitor starts to warn.
* See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/mbedtls.html#performance-and-memory-tweaks
*/
static const size_t MIN_HEAP_MEMORY = (60U * 1024U);

/** Minimum size of largest block of heap that can be allocated at once in bytes, the monitor starts to warn. */
static const size_t MIN_HEAP_BLOCK_MEMORY = 4096U;
/**
* Lowest size of heap memory in bytes, the monitor starts to warn.
* See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/mbedtls.html#performance-and-memory-tweaks
*/
static const size_t LOWEST_HEAP_MEMORY = (50U * 1024U);

/**
* Minimum size of largest block of heap that can be allocated at once in bytes, the monitor starts to warn.
*/
static const size_t LARGEST_HEAP_BLOCK_MEMORY = CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN;

private:

Expand Down

0 comments on commit be56295

Please sign in to comment.