1 // Copyright 2021 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15
16 #include <stddef.h>
17 #include <stdint.h>
18
19 #include "pw_preprocessor/compiler.h"
20 #include "pw_preprocessor/util.h"
21
22 // Enable traces
23 #define PW_TRACE_TYPE_INSTANT 1
24 #define PW_TRACE_TYPE_INSTANT_GROUP 1
25 #define PW_TRACE_TYPE_DURATION_START 1
26 #define PW_TRACE_TYPE_DURATION_END 1
27 #define PW_TRACE_TYPE_DURATION_GROUP_START 1
28 #define PW_TRACE_TYPE_DURATION_GROUP_END 1
29 #define PW_TRACE_TYPE_ASYNC_START 1
30 #define PW_TRACE_TYPE_ASYNC_INSTANT 1
31 #define PW_TRACE_TYPE_ASYNC_END 1
32
33 PW_EXTERN_C_START
34
35 // Empty function for compiling out trace statements. Since the function is
36 // empty and inline, it should be completely compiled out. This function
37 // accomplishes following:
38 //
39 // - Uses the arguments to PW_TRACE, which avoids "unused variable" warnings.
40 // - Executes expressions passed to PW_TRACE, so that the behavior is
41 // consistent between this null backend and an actual backend.
42 //
43 // These two functions are used in PW_TRACE and PW_TRACE_DATA.
44
_pw_trace_Ignored(int event_type,uint8_t flags,const char * label,const char * group,uint32_t trace_id)45 static inline void _pw_trace_Ignored(int event_type,
46 uint8_t flags,
47 const char* label,
48 const char* group,
49 uint32_t trace_id) {
50 (void)event_type;
51 (void)flags;
52 (void)label;
53 (void)group;
54 (void)trace_id;
55 }
56
_pw_trace_IgnoredData(int event_type,uint8_t flags,const char * label,const char * group,uint32_t trace_id,const char * type,const void * data,size_t size)57 static inline void _pw_trace_IgnoredData(int event_type,
58 uint8_t flags,
59 const char* label,
60 const char* group,
61 uint32_t trace_id,
62 const char* type,
63 const void* data,
64 size_t size) {
65 (void)event_type;
66 (void)flags;
67 (void)label;
68 (void)group;
69 (void)trace_id;
70 (void)type;
71 (void)data;
72 (void)size;
73 }
74
75 PW_EXTERN_C_END
76
77 #define PW_TRACE(event_type, flags, label, group, trace_id) \
78 _pw_trace_Ignored(event_type, flags, label, group, trace_id)
79
80 #define PW_TRACE_DATA( \
81 event_type, flags, label, group, trace_id, type, data, size) \
82 _pw_trace_IgnoredData( \
83 event_type, flags, label, group, trace_id, type, data, size)
84