Skip to content

Commit d7e2bd3

Browse files
author
Arto Kinnunen
committed
Merge commit '7fab5abace6aa9d6fc6c335fa6fcab15a108d646' into mbedos511
* commit '7fab5abace6aa9d6fc6c335fa6fcab15a108d646': Squashed 'features/frameworks/mbed-trace/' changes from 6df2572..9eaf0d1
2 parents 66620a2 + 7fab5ab commit d7e2bd3

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

features/frameworks/mbed-trace/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,43 @@ Set the output function, `printf` by default:
107107
mbed_trace_print_function_set(printf)
108108
```
109109
110+
### Tracing level
111+
112+
Run time tracing level is set using `mbed_trace_set_config()` function. Possible levels and examples how to set them is presented below.
113+
114+
```c
115+
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
116+
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG); // (same as ALL)
117+
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO);
118+
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_WARN);
119+
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ERROR);
120+
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_CMD);
121+
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_NONE);
122+
```
123+
124+
Build time optimization can be done with `MBED_TRACE_MAX_LEVEL` definition. Setting max level to `TRACE_LEVEL_DEBUG` includes all traces to the build. Setting max level to `TRACE_LEVEL_INFO` includes all but `tr_debug()` traces to the build. Other maximum tracing levels follow the same behavior and no messages above the selected level are included in the build.
125+
126+
```c
127+
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_DEBUG
128+
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_INFO
129+
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_WARN
130+
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_ERROR
131+
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_CMD
132+
```
133+
134+
In Mbed OS, the build time maximum tracing level can be set through `mbed_app.json` as shown below.
135+
136+
```
137+
{
138+
"target_overrides":{
139+
"*":{
140+
"mbed-trace.enable": true,
141+
"mbed-trace.max-level": "TRACE_LEVEL_INFO"
142+
}
143+
}
144+
}
145+
```
146+
110147
### Helping functions
111148

112149
The purpose of the helping functions is to provide simple conversions, for example from an array to C string, so that you can print everything to single trace line. They must be called inside the actual trace calls, for example:

features/frameworks/mbed-trace/mbed_lib.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
"help": "Used to globally enable traces.",
66
"value": null
77
},
8+
"max-level": {
9+
"help": "This flag is used to optimize the code size. For example, setting trace optimization level to TRACE_LEVEL_INFO will define all tr_debug() macros empty, which reduces the binary size. The possible optimization levels are TRACE_LEVEL_DEBUG, TRACE_LEVEL_INFO, TRACE_LEVEL_WARN, TRACE_LEVEL_ERROR and TRACE_LEVEL_CMD. To set the output tracing level, please use mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO). The possible tracing levels for mbed_trace_config_set() are TRACE_ACTIVE_LEVEL_ALL, TRACE_ACTIVE_LEVEL_DEBUG (same as ALL), TRACE_ACTIVE_LEVEL_INFO, TRACE_ACTIVE_LEVEL_WARN, TRACE_ACTIVE_LEVEL_ERROR, TRACE_ACTIVE_LEVEL_CMD and TRACE_LEVEL_NONE.",
10+
"value": null,
11+
"macro_name": "MBED_TRACE_MAX_LEVEL"
12+
13+
},
814
"fea-ipv6": {
915
"help": "Used to globally disable ipv6 tracing features.",
1016
"value": null

features/frameworks/mbed-trace/test/Test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ TEST(trace, config_change)
239239
TEST(trace, active_level_all_color)
240240
{
241241
mbed_trace_config_set(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_ALL);
242+
// unknown debug level
243+
mbed_tracef(TRACE_LEVEL_DEBUG+1, "mygr", "hep");
244+
STRCMP_EQUAL(" hep", buf);
242245
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello");
243246
STRCMP_EQUAL("\x1b[90m[DBG ][mygr]: hello\x1b[0m", buf);
244247
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "to one");
@@ -268,6 +271,10 @@ TEST(trace, change_levels)
268271
TEST(trace, active_level_debug)
269272
{
270273
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG);
274+
275+
// unknown debug level
276+
mbed_tracef(TRACE_LEVEL_DEBUG+1, "mygr", "hep");
277+
STRCMP_EQUAL(" hep", buf);
271278

272279
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
273280
STRCMP_EQUAL("[DBG ][mygr]: hep", buf);

0 commit comments

Comments
 (0)