Skip to content

Commit 3caef05

Browse files
author
Amanda Butler
authored
Merge pull request #427 from bulislaw/sleep_tracing
Sleep tracing
2 parents f842eca + 0431d68 commit 3caef05

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/reference/api/platform/PowerManagement.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,39 @@ These Mbed OS drivers can lock the deep sleep:
4040
- `CAN`.
4141
- `SerialBase`.
4242

43+
#### Sleep tracing
44+
45+
Mbed OS can help you to understand the sleep patterns of your device, specifically who is holding a sleep locks preventing your board to enter the deep sleep. To enable the tracing, all you need to do is to define `MBED_SLEEP_TRACING_ENABLED` macro. You can do it by modifying your `mbed_app.json` config file or appending `-DMBED_SLEEP_TRACING_ENABLED` to `mbed compile` command.
46+
47+
Mbed OS will print sleep traces on the standard output, which by default is UART. Some of the events that we track:
48+
49+
* Locking deep sleep: `LOCK: <file name>, ln: <line in file>, lock count: <number of locks held>`
50+
* Unlocking deep sleep: `UNLOCK: <file name>, ln: <line in file>, lock count: <number of locks held>`
51+
* Entering sleep: Mbed OS will print a list of locks preventing the board from entering a deep sleep:
52+
53+
```
54+
Sleep locks held:
55+
[id: <file name 1>, count: <number of locks>]
56+
[id: <file name 2>, count: <number of locks>]
57+
```
58+
59+
Example trace can look like:
60+
61+
```
62+
LOCK: mbed_rtx_idle.cpp, ln: 129, lock count: 2
63+
Sleep locks held:
64+
[id: mbed_wait_api_, count: 1]
65+
[id: mbed_rtx_idle., count: 1]
66+
UNLOCK: mbed_rtx_idle.cpp, ln: 131, lock count: 1
67+
LOCK: mbed_rtx_idle.cpp, ln: 129, lock count: 2
68+
Sleep locks held:
69+
[id: mbed_wait_api_, count: 1]
70+
[id: mbed_rtx_idle., count: 1]
71+
UNLOCK: mbed_rtx_idle.cpp, ln: 131, lock count: 1
72+
```
73+
74+
<span class="notes">**Note:** Sleep tracing is a debug feature and should only be enabled during development cycle. Its heavy use of UART can affect the device performance.</span>
75+
4376
#### Example
4477

4578
[![View code](https://www.mbed.com/embed/?url=https://os.mbed.com/teams/mbed_example/code/SleepManager_Example_1/)](https://os.mbed.com/teams/mbed_example/code/SleepManager_Example_1/file/e85412b4147e/main.cpp)

0 commit comments

Comments
 (0)