Skip to content

Commit bbc6f37

Browse files
author
Arto Kinnunen
committed
Squashed 'features/frameworks/mbed-trace/' changes from 642a459a39..6ced9711c4
6ced9711c4 Merge branch 'master' into release_for_mbed_os 81e95acee7 README.md / filtering examples (#97) 2a1d4f8933 Include inttypes.h for PRIx<N> formatting macros (#96) e7a828ea7e Remove dependency to Nanomesh headers (#92) git-subtree-dir: features/frameworks/mbed-trace git-subtree-split: 6ced9711c4442857a72add74680caf8fc57699c3
1 parent 12a2437 commit bbc6f37

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

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

@@ -74,7 +74,7 @@ To do so, add the following to your mbed_app.json:
7474
}
7575
```
7676

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

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

@@ -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:

mbed-trace/mbed_trace.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,11 @@
4848
extern "C" {
4949
#endif
5050

51-
#ifdef YOTTA_CFG
5251
#include <stdint.h>
5352
#include <stddef.h>
5453
#include <stdbool.h>
55-
#else
56-
#include "ns_types.h"
57-
#endif
58-
5954
#include <stdarg.h>
55+
#include <inttypes.h>
6056

6157
#ifndef YOTTA_CFG_MBED_TRACE
6258
#define YOTTA_CFG_MBED_TRACE 0

0 commit comments

Comments
 (0)