Skip to content

Commit af76ebc

Browse files
author
Arto Kinnunen
committed
Merge commit 'bbc6f377f5e58e1798c41e8c670c714b9c3e35de' into nanostack-as_subtree
* commit 'bbc6f377f5e58e1798c41e8c670c714b9c3e35de': Squashed 'features/frameworks/mbed-trace/' changes from 642a459a39..6ced9711c4
2 parents 9aac23d + bbc6f37 commit af76ebc

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

features/frameworks/mbed-trace/README.md

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The purpose of the library is to provide a light, simple and general tracing sol
2626
* The trace function uses `stdout` as the default output target because it goes directly to serial port in mbed-os.
2727
* 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_).
2828
* 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.)
3030
* 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.
3131

3232
## Examples of traces
@@ -43,7 +43,7 @@ The purpose of the library is to provide a light, simple and general tracing sol
4343
### Prerequisites
4444

4545
* 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).
4747
* To enable the tracing API:
4848
* With yotta: set `YOTTA_CFG_MBED_TRACE` to 1 or true. Setting the flag to 0 or false disables tracing.
4949
* [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
5454
* 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.
5555
* If [helping functions](#helping-functions) are used the mutex must be **recursive** (counting) so it can be acquired from a single thread repeatedly.
5656
* 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.
5858

5959
### Enabling the tracing API in mbed OS 5
6060

@@ -72,7 +72,7 @@ To do so, add the following to your mbed_app.json:
7272
}
7373
```
7474

75-
Don't forget to fulfill the other [prerequisites](#prerequisites)!
75+
Do not forget to fulfill the other [prerequisites](#prerequisites)!
7676

7777
([Click here for more information on the configuration system](https://docs.mbed.com/docs/mbed-os-api/en/latest/config_system/))
7878

@@ -206,6 +206,52 @@ int main(void){
206206
}
207207
```
208208
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.
212+
213+
| Function | Explanation |
214+
|-----------------------------------|--------------------------------------------------------------|
215+
|`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.
253+
254+
209255
## Unit tests
210256
211257
To run unit tests:

0 commit comments

Comments
 (0)