1 // Copyright 2020 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
14 //==============================================================================
22 #include "pw_preprocessor/arguments.h"
24 // Because __FUNCTION__ is not a string literal to the preprocessor it can't be
25 // tokenized. So this backend redefines the implementation to instead use the
26 // file name and line number.
27 // TODO(rgoliver): A build step could be added which checks the token dictionary
28 // for these and uses add2line to replace the database with the function names.
29 #define PW_TRACE_FUNCTION_LABEL_FILE_LINE(file, line) \
30 "[" PW_STRINGIFY(file) ":" PW_STRINGIFY(line) "]"
31 #define PW_TRACE_FUNCTION_LABEL \
32 PW_TRACE_FUNCTION_LABEL_FILE_LINE(__FILE__, __LINE__)
34 // Enable these trace types
35 #define PW_TRACE_TYPE_INSTANT PW_TRACE_EVENT_TYPE_INSTANT
36 #define PW_TRACE_TYPE_INSTANT_GROUP PW_TRACE_EVENT_TYPE_INSTANT_GROUP
38 #define PW_TRACE_TYPE_DURATION_START PW_TRACE_EVENT_TYPE_DURATION_START
39 #define PW_TRACE_TYPE_DURATION_END PW_TRACE_EVENT_TYPE_DURATION_END
41 #define PW_TRACE_TYPE_DURATION_GROUP_START \
42 PW_TRACE_EVENT_TYPE_DURATION_GROUP_START
43 #define PW_TRACE_TYPE_DURATION_GROUP_END PW_TRACE_EVENT_TYPE_DURATION_GROUP_END
45 #define PW_TRACE_TYPE_ASYNC_START PW_TRACE_EVENT_TYPE_ASYNC_START
46 #define PW_TRACE_TYPE_ASYNC_INSTANT PW_TRACE_EVENT_TYPE_ASYNC_STEP
47 #define PW_TRACE_TYPE_ASYNC_END PW_TRACE_EVENT_TYPE_ASYNC_END
51 PW_TRACE_EVENT_TYPE_INVALID = 0,
52 PW_TRACE_EVENT_TYPE_INSTANT = 1,
53 PW_TRACE_EVENT_TYPE_INSTANT_GROUP = 2,
54 PW_TRACE_EVENT_TYPE_ASYNC_START = 3,
55 PW_TRACE_EVENT_TYPE_ASYNC_STEP = 4,
56 PW_TRACE_EVENT_TYPE_ASYNC_END = 5,
57 PW_TRACE_EVENT_TYPE_DURATION_START = 6,
58 PW_TRACE_EVENT_TYPE_DURATION_END = 7,
59 PW_TRACE_EVENT_TYPE_DURATION_GROUP_START = 8,
60 PW_TRACE_EVENT_TYPE_DURATION_GROUP_END = 9,
63 // This should not be called directly, instead use the PW_TRACE_* macros.
64 void pw_trace_TraceEvent(uint32_t trace_token,
65 pw_trace_EventType event_type,
69 const void* data_buffer,
72 // This should not be called directly, insted: PW_TRACE_SET_ENABLED
73 void pw_trace_Enable(bool enabled);
75 // Returns true if tracing is currently enabled.
76 bool pw_trace_IsEnabled();
80 // These are what the facade actually calls.
81 #define PW_TRACE(event_type, flags, label, group, trace_id) \
83 static const uint32_t kLabelToken = \
84 PW_TRACE_REF(event_type, PW_TRACE_MODULE_NAME, label, flags, group); \
85 pw_trace_TraceEvent(kLabelToken, \
87 PW_TRACE_MODULE_NAME, \
94 #define PW_TRACE_DATA( \
95 event_type, flags, label, group, trace_id, type, data, size) \
97 static const uint32_t kLabelToken = PW_TRACE_REF_DATA( \
98 event_type, PW_TRACE_MODULE_NAME, label, flags, group, type); \
99 pw_trace_TraceEvent(kLabelToken, \
101 PW_TRACE_MODULE_NAME, \