Skip to content

Commit 4a20472

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored andcommitted
Migrate CPU Profile to screenshot test
R=paulirish@chromium.org Bug: 413413595 Change-Id: I5ce2ab2ecea1eb98234af6c67b4eb5b7915fba59 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6596918 Commit-Queue: Jack Franklin <jacktfranklin@chromium.org> Auto-Submit: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Paul Irish <paulirish@chromium.org> Reviewed-by: Paul Irish <paulirish@chromium.org>
1 parent a252a43 commit 4a20472

File tree

7 files changed

+37
-15
lines changed

7 files changed

+37
-15
lines changed

front_end/panels/timeline/TimelineFlameChartDataProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,9 @@ export class TimelineFlameChartDataProvider extends Common.ObjectWrapper.ObjectW
590590

591591
if (this.parsedTrace) {
592592
this.compatibilityTracksAppender = this.compatibilityTracksAppenderInstance();
593+
// Note for readers: NodeJS CpuProfiles are purposefully NOT generic.
594+
// We wrap them in a `TracingStartedInPage` event, which causes them to
595+
// be treated like "real" Chrome traces. This is by design!
593596
if (this.parsedTrace.Meta.traceIsGeneric) {
594597
this.#processGenericTrace();
595598
} else {

front_end/testing/TraceHelpers.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ export async function getMainFlameChartWithTracks(
7777
export interface RenderFlameChartOptions {
7878
/**
7979
* The trace file to import. You must include `.json.gz` at the end of the file name.
80+
* Alternatively, you can provide the actual file. This is useful only if you
81+
* are providing a mocked file; generally you should prefer to pass the file
82+
* name so that the TraceLoader can take care of loading and caching the
83+
* trace.
8084
*/
81-
traceFile: string;
85+
traceFile: string|Trace.Handlers.Types.ParsedTrace;
8286
/**
8387
* Filter the tracks that will be rendered by their name. The name here is
8488
* the user visible name that is drawn onto the flame chart.
@@ -131,7 +135,14 @@ export async function renderFlameChartIntoDOM(context: Mocha.Context|null, optio
131135
debuggerWorkspaceBinding,
132136
});
133137

134-
const {parsedTrace} = await TraceLoader.traceEngine(context, options.traceFile);
138+
let parsedTrace: Trace.Handlers.Types.ParsedTrace|null = null;
139+
140+
if (typeof options.traceFile === 'string') {
141+
parsedTrace = (await TraceLoader.traceEngine(context, options.traceFile)).parsedTrace;
142+
} else {
143+
parsedTrace = options.traceFile;
144+
}
145+
135146
if (options.preloadScreenshots) {
136147
await Timeline.Utils.ImageCache.preload(parsedTrace.Screenshots.screenshots ?? []);
137148
}

front_end/ui/legacy/components/perf_ui/FlameChart.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
renderFlameChartIntoDOM,
1515
renderFlameChartWithFakeProvider,
1616
} from '../../../../testing/TraceHelpers.js';
17+
import {TraceLoader} from '../../../../testing/TraceLoader.js';
1718

1819
import * as PerfUI from './perf_ui.js';
1920

@@ -1007,6 +1008,26 @@ describeWithEnvironment('FlameChart', () => {
10071008
});
10081009

10091010
describe('rendering tracks', () => {
1011+
it('can render a Node CPU Profile', async function() {
1012+
// We have to do some work to render this trace, as we take the raw CPU
1013+
// Profile and wrap it in our code that maps it to a "real" trace. This is what happens for real if a user imports a CPU Profile.
1014+
const rawCPUProfile = await TraceLoader.rawCPUProfile(this, 'node-fibonacci-website.cpuprofile.gz');
1015+
const rawTrace = Trace.Helpers.SamplesIntegrator.SamplesIntegrator.createFakeTraceFromCpuProfile(
1016+
rawCPUProfile, Trace.Types.Events.ThreadID(1));
1017+
const {parsedTrace} = await TraceLoader.executeTraceEngineOnFileContents(rawTrace);
1018+
1019+
await renderFlameChartIntoDOM(this, {
1020+
traceFile: parsedTrace,
1021+
filterTracks(trackName) {
1022+
return trackName.startsWith('Main');
1023+
},
1024+
expandTracks() {
1025+
return true;
1026+
},
1027+
});
1028+
await assertScreenshot('timeline/main_thread_node_cpu_profile.png');
1029+
});
1030+
10101031
it('renders the main thread correctly', async function() {
10111032
await renderFlameChartIntoDOM(this, {
10121033
traceFile: 'one-second-interaction.json.gz',
-86.4 KB
Binary file not shown.
-86.3 KB
Binary file not shown.
10.9 KB
Loading

test/interactions/panels/performance/timeline/timeline_test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@ describe('Performance panel', function() {
1616
this.timeout(20_000);
1717
}
1818

19-
itScreenshot('loads a cpuprofile and renders it in non-node mode', async () => {
20-
await loadTimelineDocExample('performance_panel/basic.html?cpuprofile=node-fibonacci-website');
21-
const panel = await waitFor('body');
22-
await assertElementScreenshotUnchanged(panel, 'performance/cpu-profile.png');
23-
});
24-
25-
itScreenshot(
26-
'loads a cpuprofile and renders it in node mode with default track source set to new engine', async () => {
27-
await loadTimelineDocExample('performance_panel/basic.html?cpuprofile=node-fibonacci-website&isNode=true');
28-
const panel = await waitFor('body');
29-
await assertElementScreenshotUnchanged(panel, 'performance/cpu-profile-node.png');
30-
});
31-
3219
// Flaking.
3320
itScreenshot.skip(
3421
'[crbug.com/373792008]: supports the network track being expanded and then clicked', async function() {

0 commit comments

Comments
 (0)