Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Power management stat : add verbosity level for MBED_SLEEP_TRACING_ENABLED #14610

Merged
merged 2 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions platform/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -156,6 +167,9 @@
}
},
"target_overrides": {
"STM": {
"deepsleep-stats-verbose": false
},
"EFM32": {
"stdio-baud-rate": 115200
},
Expand Down
37 changes: 26 additions & 11 deletions platform/source/mbed_power_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions targets/TARGET_STM/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down