Add Memory Pressure Diagnostics to ESPHome Configuration
This commit is contained in:
@@ -16,6 +16,9 @@ esphome:
|
|||||||
# ESPHome emits angle-bracket includes before globals; the local entry copies the header.
|
# ESPHome emits angle-bracket includes before globals; the local entry copies the header.
|
||||||
- <energy_day_history.h>
|
- <energy_day_history.h>
|
||||||
- energy_day_history.h
|
- energy_day_history.h
|
||||||
|
- <esp_heap_caps.h>
|
||||||
|
- <esp_system.h>
|
||||||
|
- <esp_timer.h>
|
||||||
on_boot:
|
on_boot:
|
||||||
then:
|
then:
|
||||||
- light.turn_on: display_backlight
|
- light.turn_on: display_backlight
|
||||||
@@ -155,6 +158,14 @@ light:
|
|||||||
restore_mode: ALWAYS_ON
|
restore_mode: ALWAYS_ON
|
||||||
|
|
||||||
switch:
|
switch:
|
||||||
|
- platform: template
|
||||||
|
id: memory_debug_enabled
|
||||||
|
name: "Memory Pressure Debug Logging"
|
||||||
|
entity_category: config
|
||||||
|
optimistic: true
|
||||||
|
restore_mode: RESTORE_DEFAULT_OFF
|
||||||
|
on_turn_on:
|
||||||
|
- script.execute: log_memory_pressure
|
||||||
- platform: template
|
- platform: template
|
||||||
id: slideshow_enabled
|
id: slideshow_enabled
|
||||||
name: "Diashow"
|
name: "Diashow"
|
||||||
@@ -342,6 +353,10 @@ globals:
|
|||||||
initial_value: '0'
|
initial_value: '0'
|
||||||
|
|
||||||
sensor:
|
sensor:
|
||||||
|
- platform: uptime
|
||||||
|
name: "Uptime"
|
||||||
|
entity_category: diagnostic
|
||||||
|
update_interval: 60s
|
||||||
- platform: scd30
|
- platform: scd30
|
||||||
id: room_climate
|
id: room_climate
|
||||||
i2c_id: grove_i2c
|
i2c_id: grove_i2c
|
||||||
@@ -540,6 +555,13 @@ sensor:
|
|||||||
name: 'WireGuard Latest Handshake'
|
name: 'WireGuard Latest Handshake'
|
||||||
|
|
||||||
interval:
|
interval:
|
||||||
|
- interval: 60s
|
||||||
|
then:
|
||||||
|
- if:
|
||||||
|
condition:
|
||||||
|
switch.is_on: memory_debug_enabled
|
||||||
|
then:
|
||||||
|
- script.execute: log_memory_pressure
|
||||||
- interval: 1s
|
- interval: 1s
|
||||||
then:
|
then:
|
||||||
- script.execute: refresh_display
|
- script.execute: refresh_display
|
||||||
@@ -587,6 +609,28 @@ interval:
|
|||||||
}
|
}
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
- id: log_memory_pressure
|
||||||
|
then:
|
||||||
|
- lambda: |-
|
||||||
|
multi_heap_info_t heap{};
|
||||||
|
heap_caps_get_info(&heap, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||||
|
const auto reason = esp_reset_reason();
|
||||||
|
const char *label;
|
||||||
|
switch (reason) {
|
||||||
|
case ESP_RST_POWERON: label = "power-on"; break;
|
||||||
|
case ESP_RST_EXT: label = "external"; break;
|
||||||
|
case ESP_RST_SW: label = "software"; break;
|
||||||
|
case ESP_RST_PANIC: label = "panic"; break;
|
||||||
|
case ESP_RST_INT_WDT: label = "interrupt watchdog"; break;
|
||||||
|
case ESP_RST_TASK_WDT: label = "task watchdog"; break;
|
||||||
|
case ESP_RST_WDT: label = "watchdog"; break;
|
||||||
|
case ESP_RST_BROWNOUT: label = "brownout"; break;
|
||||||
|
default: label = "other"; break;
|
||||||
|
}
|
||||||
|
ESP_LOGD("memory_pressure", "uptime=%lld s reset=%s (%d) internal 8-bit heap [bytes]: free=%u min_free=%u largest_block=%u; free_blocks=%u",
|
||||||
|
static_cast<long long>(esp_timer_get_time() / 1000000), label, static_cast<int>(reason),
|
||||||
|
static_cast<unsigned>(heap.total_free_bytes), static_cast<unsigned>(heap.minimum_free_bytes),
|
||||||
|
static_cast<unsigned>(heap.largest_free_block), static_cast<unsigned>(heap.free_blocks));
|
||||||
- id: slideshow_worker
|
- id: slideshow_worker
|
||||||
mode: restart
|
mode: restart
|
||||||
then:
|
then:
|
||||||
|
|||||||
Reference in New Issue
Block a user