Skip to content

Commit 2386f3a

Browse files
paulirishDevtools-frontend LUCI CQ
authored andcommitted
RPP: Remove handlerState from handlers
This removes the unused and inconsistent `handlerState` mechanism. It's provided limited value and adopted inconsistently. Change-Id: I799a4d42998d9ee3a8b7121a4d7fbbd67ca19974 Bug: none Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5988671 Commit-Queue: Paul Irish <[email protected]> Reviewed-by: Jack Franklin <[email protected]> Auto-Submit: Paul Irish <[email protected]> Commit-Queue: Jack Franklin <[email protected]>
1 parent 628aa89 commit 2386f3a

40 files changed

+35
-418
lines changed

front_end/models/trace/Processor.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ describeWithEnvironment('TraceProcessor', function() {
139139
const baseHandler = {
140140
data() {},
141141
handleEvent() {},
142+
async finalize() {},
142143
reset() {},
143144
};
144145

front_end/models/trace/Processor.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ declare global {
5252
export interface ParseOptions {
5353
/**
5454
* If the trace was just recorded on the current page, rather than an imported file.
55+
* TODO(paulirish): Maybe remove. This is currently unused by the Processor and Handlers
5556
* @default false
5657
*/
5758
isFreshRecording?: boolean;
@@ -170,7 +171,7 @@ export class TraceProcessor extends EventTarget {
170171
}
171172
try {
172173
this.#status = Status.PARSING;
173-
await this.#computeParsedTrace(traceEvents, Boolean(options.isFreshRecording));
174+
await this.#computeParsedTrace(traceEvents);
174175
if (this.#data && !options.isCPUProfile) { // We do not calculate insights for CPU Profiles.
175176
this.#computeInsights(this.#data, traceEvents);
176177
}
@@ -184,7 +185,7 @@ export class TraceProcessor extends EventTarget {
184185
/**
185186
* Run all the handlers and set the result to `#data`.
186187
*/
187-
async #computeParsedTrace(traceEvents: readonly Types.Events.Event[], freshRecording: boolean): Promise<void> {
188+
async #computeParsedTrace(traceEvents: readonly Types.Events.Event[]): Promise<void> {
188189
/**
189190
* We want to yield regularly to maintain responsiveness. If we yield too often, we're wasting idle time.
190191
* We could do this by checking `performance.now()` regularly, but it's an expensive call in such a hot loop.
@@ -202,11 +203,6 @@ export class TraceProcessor extends EventTarget {
202203
handler.reset();
203204
}
204205

205-
// Initialize.
206-
for (const handler of sortedHandlers) {
207-
handler.initialize?.(freshRecording);
208-
}
209-
210206
// Handle each event.
211207
for (let i = 0; i < traceEvents.length; ++i) {
212208
// Every so often we take a break just to render.

front_end/models/trace/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ This folder contains the new trace engine that was first implemented for the Per
2121
│NetworkRequestHandler│ │...many more handlers │
2222
│ │ │ │
2323
│ reset() │ │ │
24-
│ initialize() │ │ │
2524
│ │ │ │
2625
│ handleEvent() │ │ │
2726
│ │ │ │

front_end/models/trace/handlers/AnimationHandler.ts

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

8-
import {HandlerState} from './types.js';
9-
108
const animations: Types.Events.Animation[] = [];
119
const animationsSyntheticEvents: Types.Events.SyntheticAnimationPair[] = [];
1210

1311
export interface AnimationData {
1412
animations: readonly Types.Events.SyntheticAnimationPair[];
1513
}
16-
let handlerState = HandlerState.UNINITIALIZED;
1714

1815
export function reset(): void {
1916
animations.length = 0;
@@ -30,14 +27,9 @@ export function handleEvent(event: Types.Events.Event): void {
3027
export async function finalize(): Promise<void> {
3128
const syntheticEvents = Helpers.Trace.createMatchedSortedSyntheticEvents(animations);
3229
animationsSyntheticEvents.push(...syntheticEvents);
33-
handlerState = HandlerState.FINALIZED;
3430
}
3531

3632
export function data(): AnimationData {
37-
if (handlerState !== HandlerState.FINALIZED) {
38-
throw new Error('Animation handler is not finalized');
39-
}
40-
4133
return {
4234
animations: animationsSyntheticEvents,
4335
};

front_end/models/trace/handlers/ExtensionTraceDataHandler.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import * as Helpers from '../helpers/helpers.js';
66
import * as Types from '../types/types.js';
77

8-
import {type HandlerName, HandlerState} from './types.js';
8+
import type {HandlerName} from './types.js';
99
import {data as userTimingsData} from './UserTimingsHandler.js';
1010

1111
const extensionFlameChartEntries: Types.Extensions.SyntheticExtensionTrackEntry[] = [];
@@ -18,26 +18,20 @@ export interface ExtensionTraceData {
1818
extensionMarkers: readonly Types.Extensions.SyntheticExtensionMarker[];
1919
entryToNode: Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>;
2020
}
21-
let handlerState = HandlerState.UNINITIALIZED;
2221

2322
export function handleEvent(_event: Types.Events.Event): void {
2423
// Implementation not needed because data is sourced from UserTimingsHandler
2524
}
2625

2726
export function reset(): void {
28-
handlerState = HandlerState.INITIALIZED;
2927
extensionFlameChartEntries.length = 0;
3028
extensionTrackData.length = 0;
3129
extensionMarkers.length = 0;
3230
entryToNode.clear();
3331
}
3432

3533
export async function finalize(): Promise<void> {
36-
if (handlerState !== HandlerState.INITIALIZED) {
37-
throw new Error('ExtensionTraceData handler is not initialized');
38-
}
3934
createExtensionFlameChartEntries();
40-
handlerState = HandlerState.FINALIZED;
4135
}
4236

4337
function createExtensionFlameChartEntries(): void {
@@ -120,10 +114,6 @@ export function extensionDataInTiming(timing: Types.Events.SyntheticUserTimingPa
120114
}
121115

122116
export function data(): ExtensionTraceData {
123-
if (handlerState !== HandlerState.FINALIZED) {
124-
throw new Error('ExtensionTraceData handler is not finalized');
125-
}
126-
127117
return {
128118
entryToNode,
129119
extensionTrackData: [...extensionTrackData],

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ async function processTrace(events: readonly Trace.Types.Events.Event[]): Promis
1919
for (const handlerName of handlersInOrder) {
2020
const handler = Trace.Handlers.ModelHandlers[handlerName];
2121
handler.reset();
22-
if ('initialize' in handler) {
23-
handler.initialize();
24-
}
2522
}
2623
for (const event of events) {
2724
for (const handlerName of handlersInOrder) {
@@ -30,9 +27,7 @@ async function processTrace(events: readonly Trace.Types.Events.Event[]): Promis
3027
}
3128
for (const handlerName of handlersInOrder) {
3229
const handler = Trace.Handlers.ModelHandlers[handlerName];
33-
if ('finalize' in handler) {
34-
await handler.finalize();
35-
}
30+
await handler.finalize();
3631
}
3732
}
3833

front_end/models/trace/handlers/FramesHandler.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {data as layerTreeHandlerData, type LayerTreeData} from './LayerTreeHandl
1111
import {data as metaHandlerData, type MetaHandlerData} from './MetaHandler.js';
1212
import {data as rendererHandlerData, type RendererHandlerData} from './RendererHandler.js';
1313
import * as Threads from './Threads.js';
14-
import {type HandlerName, HandlerState} from './types.js';
14+
import type {HandlerName} from './types.js';
1515

1616
/**
1717
* IMPORTANT: this handler is slightly different to the rest. This is because
@@ -23,32 +23,19 @@ import {type HandlerName, HandlerState} from './types.js';
2323
*
2424
* In time we expect to migrate this code to a more "typical" handler.
2525
*/
26-
let handlerState = HandlerState.UNINITIALIZED;
2726

2827
const allEvents: Types.Events.Event[] = [];
2928
let model: TimelineFrameModel|null = null;
3029

3130
export function reset(): void {
32-
handlerState = HandlerState.UNINITIALIZED;
3331
allEvents.length = 0;
3432
}
35-
export function initialize(): void {
36-
if (handlerState !== HandlerState.UNINITIALIZED) {
37-
throw new Error('FramesHandler was not reset before being initialized');
38-
}
39-
40-
handlerState = HandlerState.INITIALIZED;
41-
}
4233

4334
export function handleEvent(event: Types.Events.Event): void {
4435
allEvents.push(event);
4536
}
4637

4738
export async function finalize(): Promise<void> {
48-
if (handlerState !== HandlerState.INITIALIZED) {
49-
throw new Error('FramesHandler is not initialized');
50-
}
51-
5239
// Snapshot events can be emitted out of order, so we need to sort before
5340
// building the frames model.
5441
Helpers.Trace.sortTraceEventsInPlace(allEvents);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import * as Trace from '../trace.js';
88
describe('GPUHandler', function() {
99
beforeEach(() => {
1010
Trace.Handlers.ModelHandlers.Meta.reset();
11-
Trace.Handlers.ModelHandlers.Meta.initialize();
12-
Trace.Handlers.ModelHandlers.GPU.initialize();
1311
});
1412

1513
it('finds all the GPU Tasks for the main GPU Thread', async function() {

front_end/models/trace/handlers/GPUHandler.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import * as Helpers from '../helpers/helpers.js';
66
import * as Types from '../types/types.js';
77

88
import {data as metaHandlerData} from './MetaHandler.js';
9-
import {type HandlerName, HandlerState} from './types.js';
10-
11-
let handlerState = HandlerState.UNINITIALIZED;
9+
import type {HandlerName} from './types.js';
1210

1311
// Each thread contains events. Events indicate the thread and process IDs, which are
1412
// used to store the event in the correct process thread entry below.
@@ -19,23 +17,9 @@ let mainGPUThreadTasks: Types.Events.GPUTask[] = [];
1917
export function reset(): void {
2018
eventsInProcessThread.clear();
2119
mainGPUThreadTasks = [];
22-
23-
handlerState = HandlerState.UNINITIALIZED;
24-
}
25-
26-
export function initialize(): void {
27-
if (handlerState !== HandlerState.UNINITIALIZED) {
28-
throw new Error('GPU Handler was not reset before being initialized');
29-
}
30-
31-
handlerState = HandlerState.INITIALIZED;
3220
}
3321

3422
export function handleEvent(event: Types.Events.Event): void {
35-
if (handlerState !== HandlerState.INITIALIZED) {
36-
throw new Error('GPU Handler is not initialized');
37-
}
38-
3923
if (!Types.Events.isGPUTask(event)) {
4024
return;
4125
}
@@ -44,26 +28,18 @@ export function handleEvent(event: Types.Events.Event): void {
4428
}
4529

4630
export async function finalize(): Promise<void> {
47-
if (handlerState !== HandlerState.INITIALIZED) {
48-
throw new Error('GPU Handler is not initialized');
49-
}
50-
5131
const {gpuProcessId, gpuThreadId} = metaHandlerData();
5232
const gpuThreadsForProcess = eventsInProcessThread.get(gpuProcessId);
5333
if (gpuThreadsForProcess && gpuThreadId) {
5434
mainGPUThreadTasks = gpuThreadsForProcess.get(gpuThreadId) || [];
5535
}
56-
handlerState = HandlerState.FINALIZED;
5736
}
5837

5938
export interface GPUHandlerReturnData {
6039
mainGPUThreadTasks: readonly Types.Events.GPUTask[];
6140
}
6241

6342
export function data(): GPUHandlerReturnData {
64-
if (handlerState !== HandlerState.FINALIZED) {
65-
throw new Error('GPU Handler is not finalized');
66-
}
6743
return {
6844
mainGPUThreadTasks,
6945
};

front_end/models/trace/handlers/ImagePaintingHandler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ export function handleEvent(event: Types.Events.Event): void {
112112
}
113113
}
114114

115+
export async function finalize(): Promise<void> {
116+
}
117+
115118
export interface ImagePaintData {
116119
paintImageByDrawLazyPixelRef: Map<number, Types.Events.PaintImage>;
117120
paintImageForEvent: Map<Types.Events.Event, Types.Events.PaintImage>;

0 commit comments

Comments
 (0)