Skip to content

Commit 3ad5270

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Remove TimelineLoader.loadFromFile
Bug: none Change-Id: Ifa3b7f8b099454f6642466820db55dd2a21fd13d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6912404 Auto-Submit: Connor Clark <cjamcl@chromium.org> Commit-Queue: Connor Clark <cjamcl@chromium.org> Reviewed-by: Paul Irish <paulirish@chromium.org>
1 parent 843d516 commit 3ad5270

2 files changed

Lines changed: 20 additions & 92 deletions

File tree

front_end/panels/timeline/TimelineLoader.test.ts

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,24 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import * as Platform from '../../core/platform/platform.js';
56
import type * as Protocol from '../../generated/protocol.js';
67
import * as Trace from '../../models/trace/trace.js';
78
import {describeWithEnvironment} from '../../testing/EnvironmentHelpers.js';
89
import {makeInstantEvent} from '../../testing/TraceHelpers.js';
910

1011
import * as Timeline from './timeline.js';
1112

12-
async function loadWebDevTraceAsFile(): Promise<File> {
13-
const file = new URL('./fixtures/traces/web-dev.json.gz', import.meta.url);
14-
const response = await fetch(file);
15-
const asBlob = await response.blob();
16-
const asFile = new File([asBlob], 'web-dev.json.gz', {
17-
type: 'application/gzip',
18-
});
19-
return asFile;
13+
const {urlString} = Platform.DevToolsPath;
14+
15+
function getWebDevTraceUrl(): Platform.DevToolsPath.UrlString {
16+
const href = new URL('./fixtures/traces/web-dev.json.gz', import.meta.url).href;
17+
return urlString`${href}`;
2018
}
2119

22-
async function loadBasicCpuProfileAsFile(): Promise<File> {
23-
const file = new URL('./fixtures/traces/node-fibonacci-website.cpuprofile.gz', import.meta.url);
24-
const response = await fetch(file);
25-
const asBlob = await response.blob();
26-
const asFile = new File([asBlob], 'node-fibonacci-website.cpuprofile.gz', {
27-
type: 'application/gzip',
28-
});
29-
return asFile;
20+
function getBasicCpuProfileUrl(): Platform.DevToolsPath.UrlString {
21+
const href = new URL('./fixtures/traces/node-fibonacci-website.cpuprofile.gz', import.meta.url).href;
22+
return urlString`${href}`;
3023
}
3124

3225
describeWithEnvironment('TimelineLoader', () => {
@@ -72,14 +65,12 @@ describeWithEnvironment('TimelineLoader', () => {
7265
});
7366

7467
it('can load a saved trace file', async () => {
75-
const file = await loadWebDevTraceAsFile();
76-
const loader = await Timeline.TimelineLoader.TimelineLoader.loadFromFile(file, client);
68+
const url = getWebDevTraceUrl();
69+
const loader = await Timeline.TimelineLoader.TimelineLoader.loadFromURL(url, client);
7770
await loader.traceFinalizedForTest();
7871
sinon.assert.calledOnce(loadingStartedSpy);
79-
// Exact number is deterministic so we can assert, but the fact it was 29
80-
// calls doesn't really matter. We just want to check it got called "a
81-
// bunch of times".
82-
sinon.assert.callCount(loadingProgressSpy, 29);
72+
// Not called for loadFromURL. Maybe it should be.
73+
sinon.assert.callCount(loadingProgressSpy, 0);
8374
sinon.assert.calledOnce(processingStartedSpy);
8475
sinon.assert.calledOnce(loadingCompleteSpy);
8576

@@ -96,13 +87,12 @@ describeWithEnvironment('TimelineLoader', () => {
9687
});
9788

9889
it('can load a saved CPUProfile file', async () => {
99-
const file = await loadBasicCpuProfileAsFile();
100-
const loader = await Timeline.TimelineLoader.TimelineLoader.loadFromFile(file, client);
90+
const url = getBasicCpuProfileUrl();
91+
const loader = await Timeline.TimelineLoader.TimelineLoader.loadFromURL(url, client);
10192
await loader.traceFinalizedForTest();
10293
sinon.assert.calledOnce(loadingStartedSpy);
103-
// For the CPU Profile we are testing, loadingProgress will be called three times, because the
104-
// file is not that big.
105-
sinon.assert.callCount(loadingProgressSpy, 3);
94+
// Not called for loadFromURL. Maybe it should be.
95+
sinon.assert.callCount(loadingProgressSpy, 0);
10696
sinon.assert.calledOnce(processingStartedSpy);
10797
sinon.assert.calledOnce(loadingCompleteSpy);
10898

front_end/panels/timeline/TimelineLoader.ts

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as i18n from '../../core/i18n/i18n.js';
88
import type * as Platform from '../../core/platform/platform.js';
99
import * as SDK from '../../core/sdk/sdk.js';
1010
import type * as Protocol from '../../generated/protocol.js';
11-
import * as Bindings from '../../models/bindings/bindings.js';
1211
import * as Trace from '../../models/trace/trace.js';
1312

1413
import * as RecordingMetadata from './RecordingMetadata.js';
@@ -25,18 +24,12 @@ const str_ = i18n.i18n.registerUIStrings('panels/timeline/TimelineLoader.ts', UI
2524
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
2625

2726
/**
28-
* This class handles loading traces from file and URL, and from the Lighthouse panel
29-
* It also handles loading cpuprofiles from file, url and console.profileEnd()
30-
*
31-
* Meanwhile, the normal trace recording flow bypasses TimelineLoader entirely,
32-
* as it's handled from TracingManager => TimelineController.
27+
* This class handles loading traces from URL, and from the Lighthouse panel
28+
* It also handles loading cpuprofiles from url and console.profileEnd()
3329
*/
34-
export class TimelineLoader implements Common.StringOutputStream.OutputStream {
30+
export class TimelineLoader {
3531
private client: Client|null;
3632
private canceledCallback: (() => void)|null;
37-
private buffer: string;
38-
private firstRawChunk: boolean;
39-
private totalSize!: number;
4033
private filter: Trace.Extras.TraceFilter.TraceFilter|null;
4134
#traceIsCPUProfile: boolean;
4235
#collectedEvents: Trace.Types.Events.Event[] = [];
@@ -48,8 +41,6 @@ export class TimelineLoader implements Common.StringOutputStream.OutputStream {
4841
constructor(client: Client) {
4942
this.client = client;
5043
this.canceledCallback = null;
51-
this.buffer = '';
52-
this.firstRawChunk = true;
5344
this.filter = null;
5445
this.#traceIsCPUProfile = false;
5546
this.#metadata = null;
@@ -59,23 +50,6 @@ export class TimelineLoader implements Common.StringOutputStream.OutputStream {
5950
});
6051
}
6152

62-
static async loadFromFile(file: File, client: Client): Promise<TimelineLoader> {
63-
const loader = new TimelineLoader(client);
64-
const fileReader = new Bindings.FileUtils.ChunkedFileReader(file);
65-
loader.canceledCallback = fileReader.cancel.bind(fileReader);
66-
loader.totalSize = file.size;
67-
// We'll resolve and return the loader instance before finalizing the trace.
68-
setTimeout(async () => {
69-
const success = await fileReader.read(loader);
70-
if (!success && fileReader.error()) {
71-
// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
72-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
73-
loader.reportErrorAndCancelLoading((fileReader.error() as any).message);
74-
}
75-
});
76-
return loader;
77-
}
78-
7953
static loadFromParsedJsonFile(contents: ParsedJSONFile, client: Client): TimelineLoader {
8054
const loader = new TimelineLoader(client);
8155

@@ -224,42 +198,6 @@ export class TimelineLoader implements Common.StringOutputStream.OutputStream {
224198
}
225199
}
226200

227-
/**
228-
* As TimelineLoader implements `Common.StringOutputStream.OutputStream`, `write()` is called when a
229-
* Common.StringOutputStream.StringOutputStream instance has decoded a chunk. This path is only used
230-
* by `loadFromFile()`; it's NOT used by `loadFromEvents` or `loadFromURL`.
231-
*/
232-
async write(chunk: string, endOfFile: boolean): Promise<void> {
233-
if (!this.client) {
234-
return await Promise.resolve();
235-
}
236-
this.buffer += chunk;
237-
if (this.firstRawChunk) {
238-
this.client.loadingStarted();
239-
// Ensure we paint the loading dialog before continuing
240-
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
241-
this.firstRawChunk = false;
242-
} else {
243-
let progress = undefined;
244-
progress = this.buffer.length / this.totalSize;
245-
// For compressed traces, we can't provide a definite progress percentage. So, just keep it moving.
246-
// For other traces, calculate a loaded part.
247-
progress = progress > 1 ? progress - Math.floor(progress) : progress;
248-
this.client.loadingProgress(progress);
249-
}
250-
251-
if (endOfFile) {
252-
let trace;
253-
try {
254-
trace = JSON.parse(this.buffer) as ParsedJSONFile;
255-
this.#processParsedFile(trace);
256-
} catch (e) {
257-
this.reportErrorAndCancelLoading(i18nString(UIStrings.malformedTimelineDataS, {PH1: e.toString()}));
258-
}
259-
return;
260-
}
261-
}
262-
263201
private reportErrorAndCancelLoading(message?: string): void {
264202
if (message) {
265203
Common.Console.Console.instance().error(message);

0 commit comments

Comments
 (0)