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
18 #define PW_TRACE_TYPE_INSTANT trace_fake_backend::Instantaneous
19 #define PW_TRACE_TYPE_INSTANT_GROUP trace_fake_backend::InstantaneousGroup
20 #define PW_TRACE_TYPE_DURATION_START trace_fake_backend::DurationStart
21 #define PW_TRACE_TYPE_DURATION_END trace_fake_backend::DurationEnd
23 #define PW_TRACE_TYPE_DURATION_GROUP_START \
24 trace_fake_backend::DurationGroupStart
25 #define PW_TRACE_TYPE_DURATION_GROUP_END trace_fake_backend::DurationGroupEnd
27 #define PW_TRACE_TYPE_ASYNC_START trace_fake_backend::AsyncStart
28 #define PW_TRACE_TYPE_ASYNC_INSTANT trace_fake_backend::AsyncStep
29 #define PW_TRACE_TYPE_ASYNC_END trace_fake_backend::AsyncEnd
31 namespace trace_fake_backend {
46 // Define a helper class for holding events and checking equality.
50 : event_type_(Invalid),
56 data_format_string_(nullptr),
59 Event(pw_trace_EventType event_type,
64 : event_type_(event_type),
70 data_format_string_(nullptr),
73 Event(pw_trace_EventType event_type,
78 const char* data_type,
81 : event_type_(event_type),
87 data_format_string_(data_type),
90 bool operator==(const Event& rhs) const {
91 return event_type_ == rhs.event_type_ && //
92 flags_ == rhs.flags_ && //
93 label_ == rhs.label_ && //
94 group_ == rhs.group_ && trace_id_ == rhs.trace_id_ && //
95 has_data_ == rhs.has_data_ && //
96 data_format_string_ == rhs.data_format_string_ && //
97 data_size_ == rhs.data_size_ && //
98 (memcmp(data_, rhs.data_, data_size_) == 0);
101 bool IsEqualIgnoreLabel(const Event& rhs) const {
102 return event_type_ == rhs.event_type_ && //
103 flags_ == rhs.flags_ && //
104 group_ == rhs.group_ && trace_id_ == rhs.trace_id_ && //
105 has_data_ == rhs.has_data_ && //
106 data_format_string_ == rhs.data_format_string_ && //
107 data_size_ == rhs.data_size_ && //
108 (memcmp(data_, rhs.data_, data_size_) == 0);
112 pw_trace_EventType event_type_;
119 const char* data_format_string_;
126 static LastEvent& Instance() { return instance_; }
127 Event& Get() { return last_event_; }
128 void Set(const Event& event) { last_event_ = event; }
132 static LastEvent instance_;
135 #define PW_TRACE(event_type, flags, label, group, trace_id) \
136 LastEvent::Instance().Set(Event(event_type, flags, label, group, trace_id));
138 #define PW_TRACE_DATA( \
139 event_type, flags, label, group, trace_id, type, data, size) \
140 LastEvent::Instance().Set( \
141 Event(event_type, flags, label, group, trace_id, type, data, size));
143 } // namespace trace_fake_backend