From 658e9ae9723127b70f1c1cb8c1b8dad6bc65ee0b Mon Sep 17 00:00:00 2001 From: jeromecoutant Date: Mon, 7 Jun 2021 18:14:26 +0200 Subject: [PATCH 1/2] Power management stat : add verbosity level for MBED_SLEEP_TRACING_ENABLED Full verbosity is adding a console line for each lock/unlock API call - stats can be enabled with json config - default configuration is full verbosity and add a console line for each lock/unlock command - for STM32 targets, verbosity is reduced by default --- platform/mbed_lib.json | 14 ++++++++++++ platform/source/mbed_power_mgmt.c | 37 ++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/platform/mbed_lib.json b/platform/mbed_lib.json index 6b03c00075f..fce62ea2554 100644 --- a/platform/mbed_lib.json +++ b/platform/mbed_lib.json @@ -114,6 +114,17 @@ "value": null }, + "deepsleep-stats-enabled": { + "macro_name": "MBED_SLEEP_TRACING_ENABLED", + "help": "Set to 1 to enable deepsleep lock stats", + "value": null + }, + + "deepsleep-stats-verbose": { + "help": "Stats are logged at each step (need deepsleep-stats-enable)", + "value": true + }, + "cthunk_count_max": { "help": "The maximum CThunk objects used at the same time. This must be greater than 0 and less 256", "value": 8 @@ -156,6 +167,9 @@ } }, "target_overrides": { + "STM": { + "deepsleep-stats-verbose": false + }, "EFM32": { "stdio-baud-rate": 115200 }, diff --git a/platform/source/mbed_power_mgmt.c b/platform/source/mbed_power_mgmt.c index 9d7724aea3f..8da2c347d8e 100644 --- a/platform/source/mbed_power_mgmt.c +++ b/platform/source/mbed_power_mgmt.c @@ -28,6 +28,9 @@ #include "platform/mbed_wait_api.h" #include +#ifdef MBED_SLEEP_TRACING_ENABLED +#include +#endif #if DEVICE_SLEEP @@ -138,19 +141,27 @@ static sleep_statistic_t *sleep_tracker_add(const char *const filename) static void sleep_tracker_print_stats(void) { - mbed_error_printf("Sleep locks held:\r\n"); - for (int i = 0; i < STATISTIC_COUNT; ++i) { - if (sleep_stats[i].count == 0) { - continue; - } - - if (sleep_stats[i].identifier[0] == '\0') { - return; + if (sleep_manager_can_deep_sleep()) { + mbed_error_printf("deepsleep unlocked"); +#ifdef MBED_DEBUG + mbed_error_printf(" but disabled with MBED_DEBUG"); +#endif + } else { + mbed_error_printf("deepsleep locked by:"); + for (int i = 0; i < STATISTIC_COUNT; ++i) { + if (sleep_stats[i].count == 0) { + continue; + } + + if (sleep_stats[i].identifier[0] == '\0') { + return; + } + + mbed_error_printf(" [%s x %u]", sleep_stats[i].identifier, + sleep_stats[i].count); } - - mbed_error_printf("[id: %s, count: %u]\r\n", sleep_stats[i].identifier, - sleep_stats[i].count); } + mbed_error_printf("\r\n"); } void sleep_tracker_lock(const char *const filename, int line) @@ -164,7 +175,9 @@ void sleep_tracker_lock(const char *const filename, int line) core_util_atomic_incr_u8(&stat->count, 1); +#if MBED_CONF_PLATFORM_DEEPSLEEP_STATS_VERBOSE mbed_error_printf("LOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock); +#endif } void sleep_tracker_unlock(const char *const filename, int line) @@ -179,7 +192,9 @@ void sleep_tracker_unlock(const char *const filename, int line) core_util_atomic_decr_u8(&stat->count, 1); +#if MBED_CONF_PLATFORM_DEEPSLEEP_STATS_VERBOSE mbed_error_printf("UNLOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock); +#endif } #endif // MBED_SLEEP_TRACING_ENABLED From 8e26a05f5083e2434435c5dd32ff19e406a3d241 Mon Sep 17 00:00:00 2001 From: Jerome Coutant Date: Fri, 1 Oct 2021 16:49:46 +0200 Subject: [PATCH 2/2] STM32: readme update for MBED_SLEEP_TRACING_ENABLED --- targets/TARGET_STM/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/targets/TARGET_STM/README.md b/targets/TARGET_STM/README.md index 533d7ad1e08..11c63ad37b7 100644 --- a/targets/TARGET_STM/README.md +++ b/targets/TARGET_STM/README.md @@ -474,6 +474,14 @@ Detailed sleep Mbed OS description : https://os.mbed.com/docs/mbed-os/latest/api - debug profile is disabling deepsleep - deepsleep can also be disabled by application or drivers using sleep_manager_lock_deep_sleep() - deep-sleep-latency value is configured to 4 by default for STM32 +- trace with MBED_SLEEP_TRACING_ENABLED macro is set by default with low verbosity +``` + "target_overrides": { + "*": { + "platform.deepsleep-stats-enabled": true, + "platform.deepsleep-stats-verbose": false + }, +``` ### WiFi configuration