processor: Fix handling of legacy chrome async event IDs
Catapult associates legacy async events always with a process, even if
their IDs are globally scoped. It also treats events of different
categories with the same ID as different tracks. Unscoped IDs can be
process-local or global depending on the phase of the event.
This patch updates TP to behave similarly.
Bug: 130786981, 130786269
Change-Id: Ie0231dc233233cc10daf8338a1b09c3c09ec4749
diff --git a/src/trace_processor/proto_trace_parser_unittest.cc b/src/trace_processor/proto_trace_parser_unittest.cc
index f17de27..dc03fe3 100644
--- a/src/trace_processor/proto_trace_parser_unittest.cc
+++ b/src/trace_processor/proto_trace_parser_unittest.cc
@@ -1110,21 +1110,35 @@
packet->set_trusted_packet_sequence_id(1);
auto* event = packet->set_track_event();
event->set_timestamp_absolute_us(1015);
- event->add_category_iids(2);
+ event->add_category_iids(1);
auto* legacy_event = event->set_legacy_event();
legacy_event->set_name_iid(2);
legacy_event->set_phase('n');
legacy_event->set_global_id(10);
auto* interned_data = packet->set_interned_data();
- auto cat2 = interned_data->add_event_categories();
- cat2->set_iid(2);
- cat2->set_name("cat2");
auto ev2 = interned_data->add_event_names();
ev2->set_iid(2);
ev2->set_name("ev2");
}
{
+ // Different category but same global_id -> separate track.
+ auto* packet = trace_.add_packet();
+ packet->set_trusted_packet_sequence_id(1);
+ auto* event = packet->set_track_event();
+ event->set_timestamp_absolute_us(1018);
+ event->add_category_iids(2);
+ auto* legacy_event = event->set_legacy_event();
+ legacy_event->set_name_iid(2);
+ legacy_event->set_phase('n');
+ legacy_event->set_global_id(15);
+
+ auto* interned_data = packet->set_interned_data();
+ auto cat2 = interned_data->add_event_categories();
+ cat2->set_iid(2);
+ cat2->set_name("cat2");
+ }
+ {
auto* packet = trace_.add_packet();
packet->set_trusted_packet_sequence_id(1);
auto* event = packet->set_track_event();
@@ -1140,47 +1154,52 @@
Tokenize();
EXPECT_CALL(*process_, UpdateThread(16, 15))
- .Times(4)
.WillRepeatedly(Return(1));
TraceStorage::Thread thread(16);
thread.upid = 1u;
EXPECT_CALL(*storage_, GetThread(1))
- .Times(4)
.WillRepeatedly(testing::ReturnRef(thread));
EXPECT_CALL(*storage_, InternString(base::StringView("cat1")))
.WillRepeatedly(Return(1));
EXPECT_CALL(*storage_, InternString(base::StringView("ev1")))
.WillRepeatedly(Return(2));
- EXPECT_CALL(*storage_, InternString(base::StringView("cat2")))
- .WillRepeatedly(Return(3));
EXPECT_CALL(*storage_, InternString(base::StringView("ev2")))
.WillRepeatedly(Return(4));
- EXPECT_CALL(*storage_, InternString(base::StringView("scope1")))
+ EXPECT_CALL(*storage_, InternString(base::StringView("cat2")))
+ .WillRepeatedly(Return(3));
+ EXPECT_CALL(*storage_, InternString(base::StringView("cat2:scope1")))
.WillOnce(Return(5));
+ EXPECT_CALL(*storage_, GetString(StringId(1))).WillRepeatedly(Return("cat1"));
+ EXPECT_CALL(*storage_, GetString(StringId(3))).WillRepeatedly(Return("cat2"));
InSequence in_sequence; // Below slices should be sorted by timestamp.
EXPECT_CALL(*slice_, Begin(1010000, 1, 1, RefType::kRefTrack, StringId(1),
StringId(2), _))
.WillOnce(Return(0u));
- EXPECT_CALL(*slice_, Scoped(1015000, 1, 1, RefType::kRefTrack, StringId(3),
+ EXPECT_CALL(*slice_, Scoped(1015000, 1, 1, RefType::kRefTrack, StringId(1),
+ StringId(4), 0, _));
+ EXPECT_CALL(*slice_, Scoped(1018000, 2, 2, RefType::kRefTrack, StringId(3),
StringId(4), 0, _));
EXPECT_CALL(*slice_, End(1020000, 1, StringId(1), StringId(2), _))
.WillOnce(Return(0u));
- EXPECT_CALL(*slice_, Scoped(1030000, 2, 2, RefType::kRefTrack, StringId(3),
+ EXPECT_CALL(*slice_, Scoped(1030000, 3, 3, RefType::kRefTrack, StringId(3),
StringId(4), 0, _));
context_.sorter->ExtractEventsForced();
- // First track is for the thread; second and third are the async event tracks.
- EXPECT_EQ(storage_->track_table().size(), 3u);
+ // First track is for the thread; others are the async event tracks.
+ EXPECT_EQ(storage_->track_table().size(), 4u);
EXPECT_EQ(storage_->track_table().name()[1], 2u);
EXPECT_EQ(storage_->track_table().name()[2], 4u);
+ EXPECT_EQ(storage_->track_table().name()[3], 4u);
- EXPECT_EQ(storage_->process_track_table().size(), 1u);
+ EXPECT_EQ(storage_->process_track_table().size(), 3u);
EXPECT_EQ(storage_->process_track_table().upid()[0], 1u);
+ EXPECT_EQ(storage_->process_track_table().upid()[1], 1u);
+ EXPECT_EQ(storage_->process_track_table().upid()[2], 1u);
EXPECT_EQ(storage_->virtual_track_slices().slice_count(), 1u);
EXPECT_EQ(storage_->virtual_track_slices().slice_ids()[0], 0u);