Skip to content

Commit 7ec2129

Browse files
and-oliDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Use FlowsHandler data in initiators handler
Use it to automatically compute initiator relationships of flow events (in this case only SchedulePostMessage-HandlePostMessage pairs, since that's the only trace event pair using the perfetto's flow API atm). Bug: 381033695 Change-Id: Ic517df29c78c3f2537417d1653827d10d67fc107 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6048879 Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Andres Olivares <andoli@chromium.org>
1 parent a317783 commit 7ec2129

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

front_end/models/trace/handlers/InitiatorsHandler.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ describe('InitiatorsHandler', () => {
194194
it('for a PostMessage Handler event the initiator is the PostMessage Dispatch event', async function() {
195195
const traceEvents = await TraceLoader.rawEvents(this, 'postmessage-initiators.json.gz');
196196
for (const event of traceEvents) {
197+
Trace.Handlers.ModelHandlers.FlowsHandler.handleEvent(event);
197198
Trace.Handlers.ModelHandlers.Initiators.handleEvent(event);
198199
}
200+
await Trace.Handlers.ModelHandlers.FlowsHandler.finalize();
199201
await Trace.Handlers.ModelHandlers.Initiators.finalize();
200202
const data = Trace.Handlers.ModelHandlers.Initiators.data();
201203

front_end/models/trace/handlers/InitiatorsHandler.ts

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import * as Helpers from '../helpers/helpers.js';
66
import * as Types from '../types/types.js';
77

8+
import {data as flowsHandlerData} from './FlowsHandler.js';
9+
810
const lastScheduleStyleRecalcByFrame = new Map<string, Types.Events.ScheduleStyleRecalculation>();
911

1012
// This tracks the last event that is considered to have invalidated the layout
@@ -20,10 +22,6 @@ const lastInvalidationEventForFrame = new Map<string, Types.Events.Event>();
2022
// is called.
2123
const lastUpdateLayoutTreeByFrame = new Map<string, Types.Events.UpdateLayoutTree>();
2224

23-
// This tracks postmessage dispatch and handler events for creating initiator association
24-
const postMessageHandlerEvents: Types.Events.HandlePostMessage[] = [];
25-
const schedulePostMessageEventByTraceId: Map<string, Types.Events.SchedulePostMessage> = new Map();
26-
2725
// These two maps store the same data but in different directions.
2826
// For a given event, tell me what its initiator was. An event can only have one initiator.
2927
const eventToInitiatorMap = new Map<Types.Events.Event, Types.Events.Event>();
@@ -48,8 +46,6 @@ export function reset(): void {
4846
requestIdleCallbackEventsById.clear();
4947
webSocketCreateEventsById.clear();
5048
schedulePostTaskCallbackEventsById.clear();
51-
schedulePostMessageEventByTraceId.clear();
52-
postMessageHandlerEvents.length = 0;
5349
}
5450

5551
function storeInitiator(data: {initiator: Types.Events.Event, event: Types.Events.Event}): void {
@@ -164,34 +160,20 @@ export function handleEvent(event: Types.Events.Event): void {
164160
storeInitiator({event, initiator: matchingSchedule});
165161
}
166162
}
167-
// Store schedulePostMessage Events by their traceIds.
168-
// so they can be reconciled later with matching handlePostMessage events with same traceIds.
169-
else if (Types.Events.isHandlePostMessage(event)) {
170-
postMessageHandlerEvents.push(event);
171-
} else if (Types.Events.isSchedulePostMessage(event)) {
172-
const traceId = event.args.data?.traceId;
173-
if (traceId) {
174-
schedulePostMessageEventByTraceId.set(traceId, event);
175-
}
176-
}
177163
}
178164

179-
function finalizeInitiatorRelationship(): void {
180-
for (const handlerEvent of postMessageHandlerEvents) {
181-
const traceId = handlerEvent.args.data?.traceId;
182-
const matchingSchedulePostMesssageEvent = schedulePostMessageEventByTraceId.get(traceId);
183-
if (matchingSchedulePostMesssageEvent) {
184-
// Set schedulePostMesssage events as initiators for handler events.
185-
storeInitiator({event: handlerEvent, initiator: matchingSchedulePostMesssageEvent});
165+
function createRelationshipsFromFlows(): void {
166+
const flows = flowsHandlerData().flows;
167+
for (let i = 0; i < flows.length; i++) {
168+
const flow = flows[i];
169+
for (let j = 0; j < flow.length - 1; j++) {
170+
storeInitiator({event: flow[j + 1], initiator: flow[j]});
186171
}
187172
}
188173
}
189174

190175
export async function finalize(): Promise<void> {
191-
// During event processing, we may encounter initiators before the handler events themselves
192-
// (e.g dispatch events on worker and handler events on the main thread)
193-
// we don't want to miss out on events whose initiators haven't been processed yet
194-
finalizeInitiatorRelationship();
176+
createRelationshipsFromFlows();
195177
}
196178

197179
export interface InitiatorsData {
@@ -205,3 +187,7 @@ export function data(): InitiatorsData {
205187
initiatorToEvents: initiatorToEventsMap,
206188
};
207189
}
190+
191+
export function deps(): ['FlowsHandler'] {
192+
return ['FlowsHandler'];
193+
}

0 commit comments

Comments
 (0)