You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: features/frameworks/mbed-trace/README.md
+50-4Lines changed: 50 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ The purpose of the library is to provide a light, simple and general tracing sol
26
26
* The trace function uses `stdout` as the default output target because it goes directly to serial port in mbed-os.
27
27
* The trace function produces traces like: `[<levl>][grp ]: msg`. This provides an easy way to detect trace prints and separate traces from normal prints (for example with _regex_).
28
28
* This approach requires a `sprintf` implementation (`stdio.h`). The memory consumption is pretty high, but it allows an efficient way to format traces.
29
-
* The solution is not Interrupt safe. (PRs are more than welcome.)
29
+
* The solution is not Interrupt safe. ([PRs](https://github.com/ARMmbed/mbed-trace/pulls) are more than welcome.)
30
30
* The solution is not thread safe by default. Thread safety for the actual trace calls can be enabled by providing wait and release callback functions that use mutexes defined by the application.
31
31
32
32
## Examples of traces
@@ -43,7 +43,7 @@ The purpose of the library is to provide a light, simple and general tracing sol
43
43
### Prerequisites
44
44
45
45
* Initialize the serial port so that `stdout` works. You can verify that the serial port works using the `printf()` function.
46
-
*if you want to redirect the traces somewhere else, see the [trace API](https://github.com/ARMmbed/mbed-trace/blob/master/mbed-trace/mbed_trace.h#L245).
46
+
*If you want to redirect the traces somewhere else, see the [trace API](https://github.com/ARMmbed/mbed-trace/blob/master/mbed-trace/mbed_trace.h#L245).
47
47
* To enable the tracing API:
48
48
* With yotta: set `YOTTA_CFG_MBED_TRACE` to 1 or true. Setting the flag to 0 or false disables tracing.
49
49
*[With mbed OS 5](#enabling-the-tracing-api-in-mbed-os-5)
@@ -54,7 +54,7 @@ The purpose of the library is to provide a light, simple and general tracing sol
54
54
* If thread safety is needed, configure the wait and release callback functions before initialization to enable the protection. Usually, this needs to be done only once in the application's lifetime.
55
55
* If [helping functions](#helping-functions) are used the mutex must be **recursive** (counting) so it can be acquired from a single thread repeatedly.
56
56
* Call the trace initialization (`mbed_trace_init`) once before using any other APIs. It allocates the trace buffer and initializes the internal variables.
57
-
* Define `TRACE_GROUP` in your source code (not in the header!) to use traces. It is a 1-4 characters long char-array (for example `#define TRACE_GROUP "APPL"`). This will be printed on every trace line.
57
+
* Define `TRACE_GROUP` in your **source code (not in the header)** to use traces. It is a 1-4 characters long char-array (for example `#define TRACE_GROUP "APPL"`). This will be printed on every trace line.
58
58
59
59
### Enabling the tracing API in mbed OS 5
60
60
@@ -72,7 +72,7 @@ To do so, add the following to your mbed_app.json:
72
72
}
73
73
```
74
74
75
-
Don't forget to fulfill the other [prerequisites](#prerequisites)!
75
+
Do not forget to fulfill the other [prerequisites](#prerequisites)!
76
76
77
77
([Click here for more information on the configuration system](https://docs.mbed.com/docs/mbed-os-api/en/latest/config_system/))
78
78
@@ -206,6 +206,52 @@ int main(void){
206
206
}
207
207
```
208
208
209
+
## Run-time trace group filtering
210
+
211
+
The trace groups you have defined using the `TRACE_GROUP` macro in your .c/.cpp files can be used to control tracing at run-time.
|`mbed_trace_include_filters_get()` | Get the exclusion filter list string. |
216
+
|`mbed_trace_include_filters_set()` | Set trace list to include only the traces matching the list. |
217
+
|`mbed_trace_exclude_filters_get()` | Get the inclusion filter list string. |
218
+
|`mbed_trace_exclude_filters_set()` | Set trace list to exclude the traces matching the list. |
219
+
220
+
The filter list is a null terminated string of comma (`,`) separated trace group names. The default maximum length of the string is 24 characters, including the terminating null. Length can be changed by defining the macro `DEFAULT_TRACE_FILTER_LENGTH`. Exclude and include filters can be combined freely as they both have their own filtering list.
221
+
222
+
The matching is done simply using `strstr()` from C standard libraries.
223
+
224
+
### Examples of trace group filtering
225
+
226
+
Assuming we have 4 modules called "MAIN", "HELP", "CALC" and "PRNT" we could use the filters in the following ways.
227
+
228
+
#### Inclusion filter
229
+
230
+
To include only "MAIN" and "CALC" traces to the trace prints, we can do:
231
+
232
+
```
233
+
mbed_trace_include_filters_set("MAIN,CALC");
234
+
```
235
+
236
+
This would print out only the traces from "MAIN" and "CALC", since they are the trace groups matching the filter list. Trace groups "HELP" and "PRNT" would not be printed out at all.
237
+
238
+
## Exclusion filter
239
+
240
+
```
241
+
mbed_trace_exclude_filters_set("HELP,PRNT");
242
+
```
243
+
244
+
This would exclue trace groups "HELP" and "PRNT" out of trace printing, thus leaving only prints from "MAIN" and "CALC" visible in the tracing.
245
+
246
+
### Reset filter
247
+
248
+
```
249
+
mbed_trace_include_filters_set(NULL);
250
+
```
251
+
252
+
This would reset the inclusion filters back to nothing and assuming no exclusion filter is in place either, all trace groups prints would get printed.
0 commit comments