show mem in console for EMSESP_DEBUG

This commit is contained in:
proddy
2020-08-07 14:14:17 +02:00
parent b1024faa6f
commit 7ff482e53e
2 changed files with 15 additions and 9 deletions

View File

@@ -194,12 +194,18 @@ void System::loop() {
#if defined(ESP8266) #if defined(ESP8266)
#if defined(EMSESP_DEBUG) #if defined(EMSESP_DEBUG)
static uint32_t last_memcheck_ = 0; static uint32_t last_memcheck_ = 0;
if (currentMillis - last_memcheck_ > 8000) { if (currentMillis - last_memcheck_ > 5000) { // 5 seconds
last_memcheck_ = currentMillis; last_memcheck_ = currentMillis;
LOG_INFO(F("Free heap: %d%% (%lu), frag:%u%%"), free_mem(), (unsigned long)ESP.getFreeHeap(), ESP.getHeapFragmentation()); show_mem("core");
}
#endif
#endif
} }
#elif defined(ESP32)
void System::show_mem(const char * note) {
#if defined(ESP8266)
#if defined(EMSESP_DEBUG)
LOG_INFO(F("(%s) Free heap: %d%% (%lu), frag:%u%%"), note, free_mem(), (unsigned long)ESP.getFreeHeap(), ESP.getHeapFragmentation());
#endif #endif
#endif #endif
} }
@@ -320,6 +326,7 @@ void System::show_users(uuid::console::Shell & shell) {
void System::show_system(uuid::console::Shell & shell) { void System::show_system(uuid::console::Shell & shell) {
shell.printfln(F("Uptime: %s"), uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3).c_str()); shell.printfln(F("Uptime: %s"), uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3).c_str());
#ifndef EMSESP_STANDALONE
#if defined(ESP8266) #if defined(ESP8266)
shell.printfln(F("Chip ID: 0x%08x"), ESP.getChipId()); shell.printfln(F("Chip ID: 0x%08x"), ESP.getChipId());
shell.printfln(F("SDK version: %s"), ESP.getSdkVersion()); shell.printfln(F("SDK version: %s"), ESP.getSdkVersion());
@@ -329,10 +336,8 @@ void System::show_system(uuid::console::Shell & shell) {
shell.printfln(F("Boot mode: %u"), ESP.getBootMode()); shell.printfln(F("Boot mode: %u"), ESP.getBootMode());
shell.printfln(F("CPU frequency: %u MHz"), ESP.getCpuFreqMHz()); shell.printfln(F("CPU frequency: %u MHz"), ESP.getCpuFreqMHz());
shell.printfln(F("Flash chip: 0x%08X (%u bytes)"), ESP.getFlashChipId(), ESP.getFlashChipRealSize()); shell.printfln(F("Flash chip: 0x%08X (%u bytes)"), ESP.getFlashChipId(), ESP.getFlashChipRealSize());
shell.printfln(F("Sketch size: %u bytes (%u bytes free)"), ESP.getSketchSize(), ESP.getFreeSketchSpace());
shell.printfln(F("Reset reason: %s"), ESP.getResetReason().c_str()); shell.printfln(F("Reset reason: %s"), ESP.getResetReason().c_str());
shell.printfln(F("Reset info: %s"), ESP.getResetInfo().c_str()); shell.printfln(F("Reset info: %s"), ESP.getResetInfo().c_str());
shell.println();
shell.printfln(F("Free heap: %lu bytes"), (unsigned long)ESP.getFreeHeap()); shell.printfln(F("Free heap: %lu bytes"), (unsigned long)ESP.getFreeHeap());
shell.printfln(F("Free mem: %d %%"), free_mem()); shell.printfln(F("Free mem: %d %%"), free_mem());
shell.printfln(F("Maximum free block size: %lu bytes"), (unsigned long)ESP.getMaxFreeBlockSize()); shell.printfln(F("Maximum free block size: %lu bytes"), (unsigned long)ESP.getMaxFreeBlockSize());
@@ -341,14 +346,12 @@ void System::show_system(uuid::console::Shell & shell) {
#elif defined(ESP32) #elif defined(ESP32)
shell.printfln(F("SDK version: %s"), ESP.getSdkVersion()); shell.printfln(F("SDK version: %s"), ESP.getSdkVersion());
shell.printfln(F("CPU frequency: %u MHz"), ESP.getCpuFreqMHz()); shell.printfln(F("CPU frequency: %u MHz"), ESP.getCpuFreqMHz());
#endif
shell.printfln(F("Sketch size: %u bytes (%u bytes free)"), ESP.getSketchSize(), ESP.getFreeSketchSpace()); shell.printfln(F("Sketch size: %u bytes (%u bytes free)"), ESP.getSketchSize(), ESP.getFreeSketchSpace());
shell.printfln(F("Free heap: %lu bytes"), (unsigned long)ESP.getFreeHeap()); shell.printfln(F("Free heap: %lu bytes"), (unsigned long)ESP.getFreeHeap());
shell.printfln(F("Free mem: %d %%"), free_mem()); shell.printfln(F("Free mem: %d %%"), free_mem());
#endif
shell.println(); shell.println();
#ifndef EMSESP_STANDALONE
switch (WiFi.status()) { switch (WiFi.status()) {
case WL_IDLE_STATUS: case WL_IDLE_STATUS:
shell.printfln(F("WiFi: Idle")); shell.printfln(F("WiFi: Idle"));
@@ -368,6 +371,7 @@ void System::show_system(uuid::console::Shell & shell) {
shell.printfln(F("BSSID: %s"), WiFi.BSSIDstr().c_str()); shell.printfln(F("BSSID: %s"), WiFi.BSSIDstr().c_str());
shell.printfln(F("RSSI: %d dBm (%d %%)"), WiFi.RSSI(), wifi_quality()); shell.printfln(F("RSSI: %d dBm (%d %%)"), WiFi.RSSI(), wifi_quality());
shell.printfln(F("MAC address: %s"), WiFi.macAddress().c_str()); shell.printfln(F("MAC address: %s"), WiFi.macAddress().c_str());
#if defined(ESP8266) #if defined(ESP8266)
shell.printfln(F("Hostname: %s"), WiFi.hostname().c_str()); shell.printfln(F("Hostname: %s"), WiFi.hostname().c_str());
#elif defined(ESP32) #elif defined(ESP32)

View File

@@ -63,6 +63,8 @@ class System {
void set_heartbeat(bool system_heartbeat); void set_heartbeat(bool system_heartbeat);
void send_heartbeat(); void send_heartbeat();
static void show_mem(const char * note);
void check_upgrade(); void check_upgrade();
private: private:
@@ -72,7 +74,7 @@ class System {
static uuid::syslog::SyslogService syslog_; static uuid::syslog::SyslogService syslog_;
#endif #endif
static constexpr uint32_t SYSTEM_CHECK_FREQUENCY = 10000; // check every 10 seconds static constexpr uint32_t SYSTEM_CHECK_FREQUENCY = 5000; // check every 5 seconds
static constexpr uint32_t LED_WARNING_BLINK = 1000; // pulse to show no connection, 1 sec static constexpr uint32_t LED_WARNING_BLINK = 1000; // pulse to show no connection, 1 sec
static constexpr uint32_t LED_WARNING_BLINK_FAST = 100; // flash quickly for boot up sequence static constexpr uint32_t LED_WARNING_BLINK_FAST = 100; // flash quickly for boot up sequence
static constexpr uint32_t SYSTEM_HEARTBEAT_INTERVAL = 60000; // in milliseconds, how often the MQTT heartbeat is sent (1 min) static constexpr uint32_t SYSTEM_HEARTBEAT_INTERVAL = 60000; // in milliseconds, how often the MQTT heartbeat is sent (1 min)