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
pull/14610/head
jeromecoutant 2021-06-07 18:14:26 +02:00 committed by Jerome Coutant
parent c41145c6d8
commit 658e9ae972
2 changed files with 39 additions and 10 deletions

View File

@ -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
},

View File

@ -28,6 +28,9 @@
#include "platform/mbed_wait_api.h"
#include <stdio.h>
#ifdef MBED_SLEEP_TRACING_ENABLED
#include <string.h>
#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_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;
}
if (sleep_stats[i].identifier[0] == '\0') {
return;
}
mbed_error_printf("[id: %s, count: %u]\r\n", sleep_stats[i].identifier,
sleep_stats[i].count);
mbed_error_printf(" [%s x %u]", 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