1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef INCLUDE_PERFETTO_TRACING_EVENT_CONTEXT_H_ 18 #define INCLUDE_PERFETTO_TRACING_EVENT_CONTEXT_H_ 19 20 #include "perfetto/protozero/message_handle.h" 21 #include "perfetto/tracing/internal/track_event_internal.h" 22 #include "protos/perfetto/trace/trace_packet.pbzero.h" 23 24 namespace perfetto { 25 namespace internal { 26 class TrackEventInternal; 27 } 28 29 // Allows adding custom arguments into track events. Example: 30 // 31 // TRACE_EVENT_BEGIN("category", "Title", 32 // [](perfetto::EventContext ctx) { 33 // auto* dbg = ctx.event()->add_debug_annotations(); 34 // dbg->set_name("name"); 35 // dbg->set_int_value(1234); 36 // }); 37 // 38 class PERFETTO_EXPORT EventContext { 39 public: 40 EventContext(EventContext&&) = default; 41 42 // For Chromium during the transition phase to the client library. 43 // TODO(eseckler): Remove once Chromium has switched to client lib entirely. EventContext(protos::pbzero::TrackEvent * event)44 explicit EventContext(protos::pbzero::TrackEvent* event) 45 : event_(event), incremental_state_(nullptr) {} 46 47 ~EventContext(); 48 event()49 protos::pbzero::TrackEvent* event() const { return event_; } 50 51 private: 52 template <typename, size_t, typename, typename> 53 friend class TrackEventInternedDataIndex; 54 friend class internal::TrackEventInternal; 55 56 using TracePacketHandle = 57 ::protozero::MessageHandle<protos::pbzero::TracePacket>; 58 59 EventContext(TracePacketHandle, internal::TrackEventIncrementalState*); 60 EventContext(const EventContext&) = delete; 61 62 TracePacketHandle trace_packet_; 63 protos::pbzero::TrackEvent* event_; 64 internal::TrackEventIncrementalState* incremental_state_; 65 }; 66 67 } // namespace perfetto 68 69 #endif // INCLUDE_PERFETTO_TRACING_EVENT_CONTEXT_H_ 70