TrackEvent: Rename track event context for readability
This patch renames TrackEventContext and its track event accessor to
just EventContext to make trace points a little more readable.
Bug: 132678367
Change-Id: I198617c2c8ac4e4b11f7d76b01d841f328eafd50
diff --git a/Android.bp b/Android.bp
index c1be406..e305328 100644
--- a/Android.bp
+++ b/Android.bp
@@ -5042,6 +5042,7 @@
name: "perfetto_src_tracing_client_api",
srcs: [
"src/tracing/data_source.cc",
+ "src/tracing/event_context.cc",
"src/tracing/internal/in_process_tracing_backend.cc",
"src/tracing/internal/system_tracing_backend.cc",
"src/tracing/internal/tracing_muxer_impl.cc",
@@ -5049,7 +5050,6 @@
"src/tracing/platform.cc",
"src/tracing/tracing.cc",
"src/tracing/track_event_category_registry.cc",
- "src/tracing/track_event_context.cc",
"src/tracing/virtual_destructors.cc",
],
}
diff --git a/BUILD b/BUILD
index 2f67f25..05b06ed 100644
--- a/BUILD
+++ b/BUILD
@@ -410,6 +410,7 @@
srcs = [
"include/perfetto/tracing/buffer_exhausted_policy.h",
"include/perfetto/tracing/data_source.h",
+ "include/perfetto/tracing/event_context.h",
"include/perfetto/tracing/internal/basic_types.h",
"include/perfetto/tracing/internal/data_source_internal.h",
"include/perfetto/tracing/internal/tracing_muxer.h",
@@ -424,7 +425,6 @@
"include/perfetto/tracing/tracing_backend.h",
"include/perfetto/tracing/track_event.h",
"include/perfetto/tracing/track_event_category_registry.h",
- "include/perfetto/tracing/track_event_context.h",
"include/perfetto/tracing/track_event_interned_data_index.h",
],
)
@@ -1001,6 +1001,7 @@
name = "src_tracing_client_api",
srcs = [
"src/tracing/data_source.cc",
+ "src/tracing/event_context.cc",
"src/tracing/internal/in_process_tracing_backend.cc",
"src/tracing/internal/in_process_tracing_backend.h",
"src/tracing/internal/system_tracing_backend.cc",
@@ -1011,7 +1012,6 @@
"src/tracing/platform.cc",
"src/tracing/tracing.cc",
"src/tracing/track_event_category_registry.cc",
- "src/tracing/track_event_context.cc",
"src/tracing/virtual_destructors.cc",
],
)
diff --git a/include/perfetto/tracing/BUILD.gn b/include/perfetto/tracing/BUILD.gn
index e40d43f..57d8619 100644
--- a/include/perfetto/tracing/BUILD.gn
+++ b/include/perfetto/tracing/BUILD.gn
@@ -26,6 +26,7 @@
sources = [
"buffer_exhausted_policy.h",
"data_source.h",
+ "event_context.h",
"internal/basic_types.h",
"internal/data_source_internal.h",
"internal/tracing_muxer.h",
@@ -40,7 +41,6 @@
"tracing_backend.h",
"track_event.h",
"track_event_category_registry.h",
- "track_event_context.h",
"track_event_interned_data_index.h",
]
}
diff --git a/include/perfetto/tracing/track_event_context.h b/include/perfetto/tracing/event_context.h
similarity index 68%
rename from include/perfetto/tracing/track_event_context.h
rename to include/perfetto/tracing/event_context.h
index 5cf657a..da1607b 100644
--- a/include/perfetto/tracing/track_event_context.h
+++ b/include/perfetto/tracing/event_context.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef INCLUDE_PERFETTO_TRACING_TRACK_EVENT_CONTEXT_H_
-#define INCLUDE_PERFETTO_TRACING_TRACK_EVENT_CONTEXT_H_
+#ifndef INCLUDE_PERFETTO_TRACING_EVENT_CONTEXT_H_
+#define INCLUDE_PERFETTO_TRACING_EVENT_CONTEXT_H_
#include "perfetto/protozero/message_handle.h"
#include "perfetto/tracing/internal/track_event_internal.h"
@@ -29,18 +29,18 @@
// Allows adding custom arguments into track events. Example:
//
// TRACE_EVENT_BEGIN("category", "Title",
-// [](perfetto::TrackEventContext ctx) {
-// auto* dbg = ctx.track_event()->add_debug_annotations();
+// [](perfetto::EventContext ctx) {
+// auto* dbg = ctx.event()->add_debug_annotations();
// dbg->set_name("name");
// dbg->set_int_value(1234);
// });
//
-class TrackEventContext {
+class EventContext {
public:
- TrackEventContext(TrackEventContext&&) = default;
- ~TrackEventContext();
+ EventContext(EventContext&&) = default;
+ ~EventContext();
- protos::pbzero::TrackEvent* track_event() const { return track_event_; }
+ protos::pbzero::TrackEvent* event() const { return event_; }
private:
template <typename, size_t, typename, typename>
@@ -50,14 +50,14 @@
using TracePacketHandle =
::protozero::MessageHandle<protos::pbzero::TracePacket>;
- TrackEventContext(TracePacketHandle, internal::TrackEventIncrementalState*);
- TrackEventContext(const TrackEventContext&) = delete;
+ EventContext(TracePacketHandle, internal::TrackEventIncrementalState*);
+ EventContext(const EventContext&) = delete;
TracePacketHandle trace_packet_;
- protos::pbzero::TrackEvent* track_event_;
+ protos::pbzero::TrackEvent* event_;
internal::TrackEventIncrementalState* incremental_state_;
};
} // namespace perfetto
-#endif // INCLUDE_PERFETTO_TRACING_TRACK_EVENT_CONTEXT_H_
+#endif // INCLUDE_PERFETTO_TRACING_EVENT_CONTEXT_H_
diff --git a/include/perfetto/tracing/internal/track_event_data_source.h b/include/perfetto/tracing/internal/track_event_data_source.h
index ec5e632..6a2ae69 100644
--- a/include/perfetto/tracing/internal/track_event_data_source.h
+++ b/include/perfetto/tracing/internal/track_event_data_source.h
@@ -20,9 +20,9 @@
#include "perfetto/base/compiler.h"
#include "perfetto/protozero/message_handle.h"
#include "perfetto/tracing/data_source.h"
+#include "perfetto/tracing/event_context.h"
#include "perfetto/tracing/internal/track_event_internal.h"
#include "perfetto/tracing/track_event_category_registry.h"
-#include "perfetto/tracing/track_event_context.h"
#include "protos/perfetto/trace/track_event/track_event.pbzero.h"
#include <unordered_map>
@@ -81,13 +81,12 @@
// TODO(skyostil): Investigate whether this should be fully outlined to reduce
// binary size.
template <size_t CategoryIndex,
- typename ArgumentFunction = void (*)(TrackEventContext)>
+ typename ArgumentFunction = void (*)(EventContext)>
static void TraceForCategory(
uint32_t instances,
const char* event_name,
perfetto::protos::pbzero::TrackEvent::Type type,
- ArgumentFunction arg_function = [](TrackEventContext) {
- }) PERFETTO_NO_INLINE {
+ ArgumentFunction arg_function = [](EventContext) {}) PERFETTO_NO_INLINE {
Base::template TraceWithInstances<CategoryTracePointTraits<CategoryIndex>>(
instances, [&](typename Base::TraceContext ctx) {
// TODO(skyostil): Intern categories at compile time.
diff --git a/include/perfetto/tracing/internal/track_event_internal.h b/include/perfetto/tracing/internal/track_event_internal.h
index c303938..a1465e5 100644
--- a/include/perfetto/tracing/internal/track_event_internal.h
+++ b/include/perfetto/tracing/internal/track_event_internal.h
@@ -25,9 +25,9 @@
#include <unordered_map>
namespace perfetto {
+class EventContext;
class DataSourceConfig;
class DataSourceDescriptor;
-class TrackEventContext;
namespace internal {
class TrackEventCategoryRegistry;
@@ -49,10 +49,10 @@
// A heap-allocated message for storing newly seen interned data while we are
// in the middle of writing a track event. When a track event wants to write
// new interned data into the trace, it is first serialized into this message
- // and then flushed to the real trace in TrackEventContext when the packet
- // ends. The message is cached here as a part of incremental state so that we
- // can reuse the underlying buffer allocation for subsequently written
- // interned data.
+ // and then flushed to the real trace in EventContext when the packet ends.
+ // The message is cached here as a part of incremental state so that we can
+ // reuse the underlying buffer allocation for subsequently written interned
+ // data.
protozero::HeapBuffered<protos::pbzero::InternedData>
serialized_interned_data;
@@ -81,7 +81,7 @@
static void DisableTracing(const TrackEventCategoryRegistry& registry,
uint32_t instance_index);
- static perfetto::TrackEventContext WriteEvent(
+ static perfetto::EventContext WriteEvent(
TraceWriterBase*,
TrackEventIncrementalState*,
const char* category,
diff --git a/include/perfetto/tracing/track_event.h b/include/perfetto/tracing/track_event.h
index 5b909be..2b7d1dd 100644
--- a/include/perfetto/tracing/track_event.h
+++ b/include/perfetto/tracing/track_event.h
@@ -71,7 +71,7 @@
// event | '--------------------------------' | arguments
// V V
// .----------------------------------. .-----------------------------.
-// | TrackEvent | | TrackEventContext |
+// | TrackEvent | | EventContext |
// | - Registry of event categories | | - One track event instance |
// '----------------------------------' '-----------------------------'
// | |
diff --git a/include/perfetto/tracing/track_event_interned_data_index.h b/include/perfetto/tracing/track_event_interned_data_index.h
index e1ef7ee..9d8935a 100644
--- a/include/perfetto/tracing/track_event_interned_data_index.h
+++ b/include/perfetto/tracing/track_event_interned_data_index.h
@@ -55,8 +55,8 @@
// string will only be emitted the first time the trace point is hit.
//
// TRACE_EVENT_BEGIN(
-// "category", "Event", [&](perfetto::TrackEventContext ctx) {
-// auto my_message = ctx.track_event()->set_my_message();
+// "category", "Event", [&](perfetto::EventContext ctx) {
+// auto my_message = ctx.event()->set_my_message();
// size_t iid = MyInternedData::Get(&ctx, "Some data");
// my_message->set_iid(iid);
// });
@@ -170,7 +170,7 @@
public:
// Return an interning id for |value|. The returned id can be immediately
// written to the trace.
- static size_t Get(TrackEventContext* ctx, const ValueType& value) {
+ static size_t Get(EventContext* ctx, const ValueType& value) {
// First check if the value exists in the dictionary.
auto index_for_field = GetOrCreateIndexForField(ctx->incremental_state_);
size_t iid;
diff --git a/src/tracing/BUILD.gn b/src/tracing/BUILD.gn
index 7a8ef42..e0984c8 100644
--- a/src/tracing/BUILD.gn
+++ b/src/tracing/BUILD.gn
@@ -261,6 +261,7 @@
]
sources = [
"data_source.cc",
+ "event_context.cc",
"internal/in_process_tracing_backend.cc",
"internal/in_process_tracing_backend.h",
"internal/tracing_muxer_impl.cc",
@@ -269,7 +270,6 @@
"platform.cc",
"tracing.cc",
"track_event_category_registry.cc",
- "track_event_context.cc",
"virtual_destructors.cc",
]
diff --git a/src/tracing/api_integrationtest.cc b/src/tracing/api_integrationtest.cc
index 44fa477..9022be2 100644
--- a/src/tracing/api_integrationtest.cc
+++ b/src/tracing/api_integrationtest.cc
@@ -777,11 +777,11 @@
auto random_value = random();
TRACE_EVENT_BEGIN("foo", "EventWithTypedArg",
- [random_value](perfetto::TrackEventContext ctx) {
- auto* log = ctx.track_event()->set_log_message();
+ [random_value](perfetto::EventContext ctx) {
+ auto* log = ctx.event()->set_log_message();
log->set_source_location_iid(1);
log->set_body_iid(2);
- auto* dbg = ctx.track_event()->add_debug_annotations();
+ auto* dbg = ctx.event()->add_debug_annotations();
dbg->set_name("random");
dbg->set_int_value(random_value);
});
@@ -855,45 +855,38 @@
size_t body_iid;
InternedLogMessageBody::commit_count = 0;
- TRACE_EVENT_BEGIN(
- "foo", "EventWithState", [&](perfetto::TrackEventContext ctx) {
- EXPECT_EQ(0, InternedLogMessageBody::commit_count);
- body_iid = InternedLogMessageBody::Get(&ctx, "Alas, poor Yorick!");
- auto log = ctx.track_event()->set_log_message();
- log->set_body_iid(body_iid);
- EXPECT_EQ(1, InternedLogMessageBody::commit_count);
+ TRACE_EVENT_BEGIN("foo", "EventWithState", [&](perfetto::EventContext ctx) {
+ EXPECT_EQ(0, InternedLogMessageBody::commit_count);
+ body_iid = InternedLogMessageBody::Get(&ctx, "Alas, poor Yorick!");
+ auto log = ctx.event()->set_log_message();
+ log->set_body_iid(body_iid);
+ EXPECT_EQ(1, InternedLogMessageBody::commit_count);
- auto body_iid2 =
- InternedLogMessageBody::Get(&ctx, "Alas, poor Yorick!");
- EXPECT_EQ(body_iid, body_iid2);
- EXPECT_EQ(1, InternedLogMessageBody::commit_count);
- });
+ auto body_iid2 = InternedLogMessageBody::Get(&ctx, "Alas, poor Yorick!");
+ EXPECT_EQ(body_iid, body_iid2);
+ EXPECT_EQ(1, InternedLogMessageBody::commit_count);
+ });
TRACE_EVENT_END("foo");
- TRACE_EVENT_BEGIN(
- "foo", "EventWithState", [&](perfetto::TrackEventContext ctx) {
- // Check that very large amounts of interned data works.
- auto log = ctx.track_event()->set_log_message();
- log->set_body_iid(
- InternedLogMessageBody::Get(&ctx, large_message.str()));
- EXPECT_EQ(2, InternedLogMessageBody::commit_count);
- });
+ TRACE_EVENT_BEGIN("foo", "EventWithState", [&](perfetto::EventContext ctx) {
+ // Check that very large amounts of interned data works.
+ auto log = ctx.event()->set_log_message();
+ log->set_body_iid(InternedLogMessageBody::Get(&ctx, large_message.str()));
+ EXPECT_EQ(2, InternedLogMessageBody::commit_count);
+ });
TRACE_EVENT_END("foo");
// Make sure interned data persists across trace points.
- TRACE_EVENT_BEGIN(
- "foo", "EventWithState", [&](perfetto::TrackEventContext ctx) {
- auto body_iid2 =
- InternedLogMessageBody::Get(&ctx, "Alas, poor Yorick!");
- EXPECT_EQ(body_iid, body_iid2);
+ TRACE_EVENT_BEGIN("foo", "EventWithState", [&](perfetto::EventContext ctx) {
+ auto body_iid2 = InternedLogMessageBody::Get(&ctx, "Alas, poor Yorick!");
+ EXPECT_EQ(body_iid, body_iid2);
- auto body_iid3 =
- InternedLogMessageBody::Get(&ctx, "I knew him, Horatio");
- EXPECT_NE(body_iid, body_iid3);
- auto log = ctx.track_event()->set_log_message();
- log->set_body_iid(body_iid3);
- EXPECT_EQ(3, InternedLogMessageBody::commit_count);
- });
+ auto body_iid3 = InternedLogMessageBody::Get(&ctx, "I knew him, Horatio");
+ EXPECT_NE(body_iid, body_iid3);
+ auto log = ctx.event()->set_log_message();
+ log->set_body_iid(body_iid3);
+ EXPECT_EQ(3, InternedLogMessageBody::commit_count);
+ });
TRACE_EVENT_END("foo");
tracing_session->get()->StopBlocking();
@@ -932,20 +925,18 @@
tracing_session->get()->StartBlocking();
size_t body_iid;
- TRACE_EVENT_BEGIN(
- "foo", "EventWithState", [&](perfetto::TrackEventContext ctx) {
- body_iid = InternedLogMessageBodySmall::Get(&ctx, "This above all:");
- auto log = ctx.track_event()->set_log_message();
- log->set_body_iid(body_iid);
+ TRACE_EVENT_BEGIN("foo", "EventWithState", [&](perfetto::EventContext ctx) {
+ body_iid = InternedLogMessageBodySmall::Get(&ctx, "This above all:");
+ auto log = ctx.event()->set_log_message();
+ log->set_body_iid(body_iid);
- auto body_iid2 =
- InternedLogMessageBodySmall::Get(&ctx, "This above all:");
- EXPECT_EQ(body_iid, body_iid2);
+ auto body_iid2 = InternedLogMessageBodySmall::Get(&ctx, "This above all:");
+ EXPECT_EQ(body_iid, body_iid2);
- auto body_iid3 =
- InternedLogMessageBodySmall::Get(&ctx, "to thine own self be true");
- EXPECT_NE(body_iid, body_iid3);
- });
+ auto body_iid3 =
+ InternedLogMessageBodySmall::Get(&ctx, "to thine own self be true");
+ EXPECT_NE(body_iid, body_iid3);
+ });
TRACE_EVENT_END("foo");
tracing_session->get()->StopBlocking();
@@ -983,11 +974,11 @@
size_t body_iid;
TRACE_EVENT_BEGIN(
- "foo", "EventWithState", [&](perfetto::TrackEventContext ctx) {
+ "foo", "EventWithState", [&](perfetto::EventContext ctx) {
// Test using a dynamically created interned value.
body_iid = InternedLogMessageBodyHashed::Get(
&ctx, std::string("Though this ") + "be madness,");
- auto log = ctx.track_event()->set_log_message();
+ auto log = ctx.event()->set_log_message();
log->set_body_iid(body_iid);
auto body_iid2 =
@@ -1037,23 +1028,21 @@
auto* tracing_session = NewTrace(cfg);
tracing_session->get()->StartBlocking();
- TRACE_EVENT_BEGIN(
- "foo", "EventWithState", [&](perfetto::TrackEventContext ctx) {
- const SourceLocation location{"file.cc", "SomeFunction", 123};
- auto location_iid = InternedSourceLocation::Get(&ctx, location);
- auto body_iid =
- InternedLogMessageBody::Get(&ctx, "To be, or not to be");
- auto log = ctx.track_event()->set_log_message();
- log->set_source_location_iid(location_iid);
- log->set_body_iid(body_iid);
+ TRACE_EVENT_BEGIN("foo", "EventWithState", [&](perfetto::EventContext ctx) {
+ const SourceLocation location{"file.cc", "SomeFunction", 123};
+ auto location_iid = InternedSourceLocation::Get(&ctx, location);
+ auto body_iid = InternedLogMessageBody::Get(&ctx, "To be, or not to be");
+ auto log = ctx.event()->set_log_message();
+ log->set_source_location_iid(location_iid);
+ log->set_body_iid(body_iid);
- auto location_iid2 = InternedSourceLocation::Get(&ctx, location);
- EXPECT_EQ(location_iid, location_iid2);
+ auto location_iid2 = InternedSourceLocation::Get(&ctx, location);
+ EXPECT_EQ(location_iid, location_iid2);
- const SourceLocation location2{"file.cc", "SomeFunction", 456};
- auto location_iid3 = InternedSourceLocation::Get(&ctx, location2);
- EXPECT_NE(location_iid, location_iid3);
- });
+ const SourceLocation location2{"file.cc", "SomeFunction", 456};
+ auto location_iid3 = InternedSourceLocation::Get(&ctx, location2);
+ EXPECT_NE(location_iid, location_iid3);
+ });
TRACE_EVENT_END("foo");
tracing_session->get()->StopBlocking();
@@ -1077,10 +1066,9 @@
{
uint64_t arg = 123;
- TRACE_EVENT("test", "TestEventWithArgs",
- [&](perfetto::TrackEventContext ctx) {
- ctx.track_event()->set_log_message()->set_body_iid(arg);
- });
+ TRACE_EVENT("test", "TestEventWithArgs", [&](perfetto::EventContext ctx) {
+ ctx.event()->set_log_message()->set_body_iid(arg);
+ });
}
{
diff --git a/src/tracing/track_event_context.cc b/src/tracing/event_context.cc
similarity index 87%
rename from src/tracing/track_event_context.cc
rename to src/tracing/event_context.cc
index 93f45cb..2126e2c 100644
--- a/src/tracing/track_event_context.cc
+++ b/src/tracing/event_context.cc
@@ -14,21 +14,21 @@
* limitations under the License.
*/
-#include "perfetto/tracing/track_event_context.h"
+#include "perfetto/tracing/event_context.h"
#include "protos/perfetto/trace/interned_data/interned_data.pbzero.h"
#include "protos/perfetto/trace/track_event/track_event.pbzero.h"
namespace perfetto {
-TrackEventContext::TrackEventContext(
- TrackEventContext::TracePacketHandle trace_packet,
+EventContext::EventContext(
+ EventContext::TracePacketHandle trace_packet,
internal::TrackEventIncrementalState* incremental_state)
: trace_packet_(std::move(trace_packet)),
- track_event_(trace_packet_->set_track_event()),
+ event_(trace_packet_->set_track_event()),
incremental_state_(incremental_state) {}
-TrackEventContext::~TrackEventContext() {
+EventContext::~EventContext() {
// When the track event is finalized (i.e., the context is destroyed), we
// should flush any newly seen interned data to the trace. The data has
// earlier been written to a heap allocated protobuf message
diff --git a/src/tracing/internal/track_event_internal.cc b/src/tracing/internal/track_event_internal.cc
index 2e65517..198586a 100644
--- a/src/tracing/internal/track_event_internal.cc
+++ b/src/tracing/internal/track_event_internal.cc
@@ -131,7 +131,7 @@
}
// static
-TrackEventContext TrackEventInternal::WriteEvent(
+EventContext TrackEventInternal::WriteEvent(
TraceWriterBase* trace_writer,
TrackEventIncrementalState* incr_state,
const char* category,
@@ -150,10 +150,10 @@
// We assume that |category| and |name| point to strings with static lifetime.
// This means we can use their addresses as interning keys.
- TrackEventContext ctx(std::move(packet), incr_state);
+ EventContext ctx(std::move(packet), incr_state);
size_t category_iid = InternedEventCategory::Get(&ctx, category);
- auto track_event = ctx.track_event();
+ auto track_event = ctx.event();
track_event->set_type(type);
// TODO(skyostil): Handle multiple categories.
track_event->add_category_iids(category_iid);
diff --git a/src/tracing/test/tracing_module.cc b/src/tracing/test/tracing_module.cc
index 4b0283e..2df377f0 100644
--- a/src/tracing/test/tracing_module.cc
+++ b/src/tracing/test/tracing_module.cc
@@ -59,11 +59,10 @@
}
void FunctionWithOneTrackEventWithTypedArgument() {
- TRACE_EVENT_BEGIN("cat1", "EventWithArg",
- [](perfetto::TrackEventContext ctx) {
- auto log = ctx.track_event()->set_log_message();
- log->set_body_iid(0x42);
- });
+ TRACE_EVENT_BEGIN("cat1", "EventWithArg", [](perfetto::EventContext ctx) {
+ auto log = ctx.event()->set_log_message();
+ log->set_body_iid(0x42);
+ });
// Simulates the non-tracing work of this function, which should take priority
// over the above trace event in terms of instruction scheduling.
puts("Hello");