[go: nahoru, domu]

blob: e352c4e7fcae2f90c324830ce8770e977163d1fd [file] [log] [blame]
Jan Scheffler76e4ba92021-02-25 12:58:081// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Blink Reformat4c46d092018-04-07 15:32:375/*
6 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Jan Scheffler76e4ba92021-02-25 12:58:0830/* eslint-disable rulesdir/no_underscored_properties */
31
Tim van der Lippe76961572021-04-06 10:48:0732import * as Common from '../../core/common/common.js';
Tim van der Lippee0247312021-04-01 14:25:3033import * as Host from '../../core/host/host.js';
Tim van der Lippebb352e62021-04-01 17:57:2834import * as i18n from '../../core/i18n/i18n.js';
Tim van der Lippee00b92f2021-03-31 16:52:1735import * as SDK from '../../core/sdk/sdk.js';
Tim van der Lippe3167ffe2021-04-12 16:45:1436import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
Tim van der Lippe339ad262021-04-21 12:23:3637import * as Components from '../../ui/legacy/components/utils/utils.js';
Tim van der Lippeaa61faf2021-04-07 15:32:0738import * as UI from '../../ui/legacy/legacy.js';
Tim van der Lippe229a54f2021-05-14 16:59:0539import type * as Protocol from '../../generated/protocol.js';
Tim van der Lippee54f66e2020-02-03 18:20:3240
Paul Lewis0d43b802020-01-14 13:34:2341import {ProfileFlameChartDataProvider} from './CPUProfileFlameChart.js';
Tim van der Lippee00b92f2021-03-31 16:52:1742
Tim van der Lippebfbb58f2021-02-25 17:34:1943import type {Formatter, ProfileDataGridNode} from './ProfileDataGrid.js';
44import type {ProfileHeader} from './ProfileHeader.js';
45import {ProfileEvents, ProfileType} from './ProfileHeader.js';
Paul Lewis0d43b802020-01-14 13:34:2346import {ProfileView, WritableProfileHeader} from './ProfileView.js';
47
Simon Zünd34490692021-03-01 08:25:1848const UIStrings = {
vidorteg7c153a22021-01-21 20:57:0849 /**
50 *@description Time of a single activity, as opposed to the total time
51 */
52 selfTime: 'Self Time',
53 /**
54 *@description Text for the total time of something
55 */
56 totalTime: 'Total Time',
57 /**
vidorteg7c153a22021-01-21 20:57:0858 *@description Text in CPUProfile View of a profiler tool
59 */
60 recordJavascriptCpuProfile: 'Record JavaScript CPU Profile',
61 /**
62 *@description Text in CPUProfile View of a profiler tool
63 */
64 stopCpuProfiling: 'Stop CPU profiling',
65 /**
66 *@description Text in CPUProfile View of a profiler tool
67 */
68 startCpuProfiling: 'Start CPU profiling',
69 /**
70 *@description Text in CPUProfile View of a profiler tool
71 */
72 cpuProfiles: 'CPU PROFILES',
73 /**
74 *@description Text in CPUProfile View of a profiler tool, that show how much time a script spend executing a function.
75 */
76 cpuProfilesShow: 'CPU profiles show where the execution time is spent in your page\'s JavaScript functions.',
77 /**
78 *@description Text in CPUProfile View of a profiler tool
79 */
80 recording: 'Recording…',
81 /**
82 *@description Time in miliseconds
83 *@example {30.1} PH1
84 */
85 fms: '{PH1} ms',
86 /**
87 *@description Text in CPUProfile View of a profiler tool
88 *@example {21.33} PH1
89 */
90 formatPercent: '{PH1} %',
91 /**
92 *@description Text for the name of something
93 */
94 name: 'Name',
95 /**
96 *@description Text for web URLs
97 */
98 url: 'URL',
99 /**
100 *@description Text in CPUProfile View of a profiler tool
101 */
102 aggregatedSelfTime: 'Aggregated self time',
103 /**
104 *@description Text in CPUProfile View of a profiler tool
105 */
106 aggregatedTotalTime: 'Aggregated total time',
107 /**
Peter Marshall2bdcc642021-03-03 10:02:09108 *@description Text that indicates a JavaScript function in a CPU profile is not optimized.
vidorteg7c153a22021-01-21 20:57:08109 */
110 notOptimized: 'Not optimized',
111};
Tim van der Lippe251251d2021-03-31 13:37:59112const str_ = i18n.i18n.registerUIStrings('panels/profiler/CPUProfileView.ts', UIStrings);
vidorteg7c153a22021-01-21 20:57:08113const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Jan Scheffler76e4ba92021-02-25 12:58:08114export class CPUProfileView extends ProfileView implements UI.SearchableView.Searchable {
115 profileHeader: CPUProfileHeader;
116 adjustedTotal: number;
117 constructor(profileHeader: CPUProfileHeader) {
Blink Reformat4c46d092018-04-07 15:32:37118 super();
Simon Zünd2b1513d2020-11-04 10:15:28119 this.profileHeader = profileHeader;
Tim van der Lippe6288cf32020-01-07 16:58:40120 this.initialize(new NodeFormatter(this));
Alexei Filippov6d2eb592018-10-25 21:48:56121 const profile = profileHeader.profileModel();
122 this.adjustedTotal = profile.profileHead.total;
123 this.adjustedTotal -= profile.idleNode ? profile.idleNode.total : 0;
124 this.setProfile(profile);
Blink Reformat4c46d092018-04-07 15:32:37125 }
126
Jan Scheffler76e4ba92021-02-25 12:58:08127 wasShown(): void {
Blink Reformat4c46d092018-04-07 15:32:37128 super.wasShown();
Tim van der Lipped87271d2020-09-28 15:17:06129 PerfUI.LineLevelProfile.Performance.instance().reset();
Simon Zünd2b1513d2020-11-04 10:15:28130 PerfUI.LineLevelProfile.Performance.instance().appendCPUProfile(this.profileHeader.profileModel());
Blink Reformat4c46d092018-04-07 15:32:37131 }
132
Jan Scheffler76e4ba92021-02-25 12:58:08133 columnHeader(columnId: string): Common.UIString.LocalizedString {
Blink Reformat4c46d092018-04-07 15:32:37134 switch (columnId) {
135 case 'self':
vidorteg7c153a22021-01-21 20:57:08136 return i18nString(UIStrings.selfTime);
Blink Reformat4c46d092018-04-07 15:32:37137 case 'total':
vidorteg7c153a22021-01-21 20:57:08138 return i18nString(UIStrings.totalTime);
Blink Reformat4c46d092018-04-07 15:32:37139 }
Peter Marshall5093cce2021-01-22 12:19:03140 return Common.UIString.LocalizedEmptyString;
Blink Reformat4c46d092018-04-07 15:32:37141 }
142
Jan Scheffler76e4ba92021-02-25 12:58:08143 createFlameChartDataProvider(): ProfileFlameChartDataProvider {
Simon Zünd2b1513d2020-11-04 10:15:28144 return new CPUFlameChartDataProvider(this.profileHeader.profileModel(), this.profileHeader._cpuProfilerModel);
Blink Reformat4c46d092018-04-07 15:32:37145 }
Tim van der Lippe6288cf32020-01-07 16:58:40146}
Blink Reformat4c46d092018-04-07 15:32:37147
Paul Lewis0d43b802020-01-14 13:34:23148export class CPUProfileType extends ProfileType {
Jan Scheffler76e4ba92021-02-25 12:58:08149 _recording: boolean;
Blink Reformat4c46d092018-04-07 15:32:37150 constructor() {
vidorteg7c153a22021-01-21 20:57:08151 super(CPUProfileType.TypeId, i18nString(UIStrings.recordJavascriptCpuProfile));
Blink Reformat4c46d092018-04-07 15:32:37152 this._recording = false;
153
Sigurd Schneiderb9f6c792021-05-31 10:57:24154 SDK.TargetManager.TargetManager.instance().addModelListener(
Tim van der Lippee54f66e2020-02-03 18:20:32155 SDK.CPUProfilerModel.CPUProfilerModel, SDK.CPUProfilerModel.Events.ConsoleProfileFinished,
156 this._consoleProfileFinished, this);
Blink Reformat4c46d092018-04-07 15:32:37157 }
158
Jan Scheffler76e4ba92021-02-25 12:58:08159 profileBeingRecorded(): ProfileHeader|null {
160 return super.profileBeingRecorded() as ProfileHeader | null;
Blink Reformat4c46d092018-04-07 15:32:37161 }
162
Jan Scheffler76e4ba92021-02-25 12:58:08163 typeName(): string {
Blink Reformat4c46d092018-04-07 15:32:37164 return 'CPU';
165 }
166
Jan Scheffler76e4ba92021-02-25 12:58:08167 fileExtension(): string {
Blink Reformat4c46d092018-04-07 15:32:37168 return '.cpuprofile';
169 }
170
Jan Scheffler76e4ba92021-02-25 12:58:08171 get buttonTooltip(): Common.UIString.LocalizedString {
vidorteg7c153a22021-01-21 20:57:08172 return this._recording ? i18nString(UIStrings.stopCpuProfiling) : i18nString(UIStrings.startCpuProfiling);
Blink Reformat4c46d092018-04-07 15:32:37173 }
174
Jan Scheffler76e4ba92021-02-25 12:58:08175 buttonClicked(): boolean {
Blink Reformat4c46d092018-04-07 15:32:37176 if (this._recording) {
Alexei Filippov6d2eb592018-10-25 21:48:56177 this._stopRecordingProfile();
Blink Reformat4c46d092018-04-07 15:32:37178 return false;
Blink Reformat4c46d092018-04-07 15:32:37179 }
Mathias Bynensf06e8c02020-02-28 13:58:28180 this._startRecordingProfile();
181 return true;
Blink Reformat4c46d092018-04-07 15:32:37182 }
183
Jan Scheffler76e4ba92021-02-25 12:58:08184 get treeItemTitle(): Common.UIString.LocalizedString {
vidorteg7c153a22021-01-21 20:57:08185 return i18nString(UIStrings.cpuProfiles);
Blink Reformat4c46d092018-04-07 15:32:37186 }
187
Jan Scheffler76e4ba92021-02-25 12:58:08188 get description(): Common.UIString.LocalizedString {
vidorteg7c153a22021-01-21 20:57:08189 return i18nString(UIStrings.cpuProfilesShow);
Blink Reformat4c46d092018-04-07 15:32:37190 }
191
Jan Scheffler76e4ba92021-02-25 12:58:08192 _consoleProfileFinished(event: Common.EventTarget.EventTargetEvent): void {
193 const data = (event.data as SDK.CPUProfilerModel.EventData);
194 const cpuProfile = (data.cpuProfile as Protocol.Profiler.Profile);
Tim van der Lippe6288cf32020-01-07 16:58:40195 const profile = new CPUProfileHeader(data.cpuProfilerModel, this, data.title);
Blink Reformat4c46d092018-04-07 15:32:37196 profile.setProtocolProfile(cpuProfile);
197 this.addProfile(profile);
198 }
199
Jan Scheffler76e4ba92021-02-25 12:58:08200 _startRecordingProfile(): void {
Tim van der Lipped1a00aa2020-08-19 16:03:56201 const cpuProfilerModel = UI.Context.Context.instance().flavor(SDK.CPUProfilerModel.CPUProfilerModel);
Tim van der Lippe1d6e57a2019-09-30 11:55:34202 if (this.profileBeingRecorded() || !cpuProfilerModel) {
Blink Reformat4c46d092018-04-07 15:32:37203 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34204 }
Tim van der Lippe6288cf32020-01-07 16:58:40205 const profile = new CPUProfileHeader(cpuProfilerModel, this);
Jan Scheffler76e4ba92021-02-25 12:58:08206 this.setProfileBeingRecorded(profile as ProfileHeader);
Sigurd Schneiderb9f6c792021-05-31 10:57:24207 SDK.TargetManager.TargetManager.instance().suspendAllTargets();
Jan Scheffler76e4ba92021-02-25 12:58:08208 this.addProfile(profile as ProfileHeader);
vidorteg7c153a22021-01-21 20:57:08209 profile.updateStatus(i18nString(UIStrings.recording));
Blink Reformat4c46d092018-04-07 15:32:37210 this._recording = true;
211 cpuProfilerModel.startRecording();
212 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ProfilesCPUProfileTaken);
213 }
214
Jan Scheffler76e4ba92021-02-25 12:58:08215 async _stopRecordingProfile(): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:37216 this._recording = false;
Jan Scheffler76e4ba92021-02-25 12:58:08217 const profileBeingRecorded = this.profileBeingRecorded() as CPUProfileHeader;
Simon Zünd4413f332020-11-04 12:34:56218 if (!profileBeingRecorded || !profileBeingRecorded._cpuProfilerModel) {
Blink Reformat4c46d092018-04-07 15:32:37219 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34220 }
Blink Reformat4c46d092018-04-07 15:32:37221
Simon Zünd4413f332020-11-04 12:34:56222 const profile = await profileBeingRecorded._cpuProfilerModel.stopRecording();
Jan Scheffler76e4ba92021-02-25 12:58:08223 const recordedProfile = this.profileBeingRecorded() as CPUProfileHeader;
Blink Reformat4c46d092018-04-07 15:32:37224 if (recordedProfile) {
Simon Zünd4413f332020-11-04 12:34:56225 if (!profile) {
226 throw new Error('Expected profile to be non-null');
227 }
Blink Reformat4c46d092018-04-07 15:32:37228 recordedProfile.setProtocolProfile(profile);
229 recordedProfile.updateStatus('');
230 this.setProfileBeingRecorded(null);
231 }
232
Sigurd Schneiderb9f6c792021-05-31 10:57:24233 await SDK.TargetManager.TargetManager.instance().resumeAllTargets();
Paul Lewis0d43b802020-01-14 13:34:23234 this.dispatchEventToListeners(ProfileEvents.ProfileComplete, recordedProfile);
Blink Reformat4c46d092018-04-07 15:32:37235 }
236
Jan Scheffler76e4ba92021-02-25 12:58:08237 createProfileLoadedFromFile(title: string): ProfileHeader {
Tim van der Lippe6288cf32020-01-07 16:58:40238 return new CPUProfileHeader(null, this, title);
Blink Reformat4c46d092018-04-07 15:32:37239 }
240
Jan Scheffler76e4ba92021-02-25 12:58:08241 profileBeingRecordedRemoved(): void {
Alexei Filippov6d2eb592018-10-25 21:48:56242 this._stopRecordingProfile();
Blink Reformat4c46d092018-04-07 15:32:37243 }
Jan Scheffler76e4ba92021-02-25 12:58:08244
245 // eslint-disable-next-line @typescript-eslint/naming-convention
246 static readonly TypeId = 'CPU';
Tim van der Lippe6288cf32020-01-07 16:58:40247}
Blink Reformat4c46d092018-04-07 15:32:37248
Blink Reformat4c46d092018-04-07 15:32:37249
Paul Lewis0d43b802020-01-14 13:34:23250export class CPUProfileHeader extends WritableProfileHeader {
Jan Scheffler76e4ba92021-02-25 12:58:08251 _cpuProfilerModel: SDK.CPUProfilerModel.CPUProfilerModel|null;
252 _profileModel?: SDK.CPUProfileDataModel.CPUProfileDataModel;
253
254 constructor(cpuProfilerModel: SDK.CPUProfilerModel.CPUProfilerModel|null, type: CPUProfileType, title?: string) {
Blink Reformat4c46d092018-04-07 15:32:37255 super(cpuProfilerModel && cpuProfilerModel.debuggerModel(), type, title);
256 this._cpuProfilerModel = cpuProfilerModel;
257 }
258
Jan Scheffler76e4ba92021-02-25 12:58:08259 createView(): ProfileView {
Tim van der Lippe6288cf32020-01-07 16:58:40260 return new CPUProfileView(this);
Blink Reformat4c46d092018-04-07 15:32:37261 }
262
Jan Scheffler76e4ba92021-02-25 12:58:08263 protocolProfile(): Protocol.Profiler.Profile {
Simon Zünd4413f332020-11-04 12:34:56264 if (!this._protocolProfile) {
265 throw new Error('Expected _protocolProfile to be available');
266 }
Blink Reformat4c46d092018-04-07 15:32:37267 return this._protocolProfile;
268 }
269
Jan Scheffler76e4ba92021-02-25 12:58:08270 profileModel(): SDK.CPUProfileDataModel.CPUProfileDataModel {
Simon Zünd4413f332020-11-04 12:34:56271 if (!this._profileModel) {
272 throw new Error('Expected _profileModel to be available');
273 }
Blink Reformat4c46d092018-04-07 15:32:37274 return this._profileModel;
275 }
276
Jan Scheffler76e4ba92021-02-25 12:58:08277 setProfile(profile: Protocol.Profiler.Profile): void {
Alexei Filippove6056582019-03-05 22:47:47278 const target = this._cpuProfilerModel && this._cpuProfilerModel.target() || null;
Tim van der Lippee54f66e2020-02-03 18:20:32279 this._profileModel = new SDK.CPUProfileDataModel.CPUProfileDataModel(profile, target);
Blink Reformat4c46d092018-04-07 15:32:37280 }
Tim van der Lippe6288cf32020-01-07 16:58:40281}
Blink Reformat4c46d092018-04-07 15:32:37282
Jan Scheffler76e4ba92021-02-25 12:58:08283export class NodeFormatter implements Formatter {
284 _profileView: CPUProfileView;
285 constructor(profileView: CPUProfileView) {
Blink Reformat4c46d092018-04-07 15:32:37286 this._profileView = profileView;
287 }
288
Jan Scheffler76e4ba92021-02-25 12:58:08289 formatValue(value: number): string {
vidorteg7c153a22021-01-21 20:57:08290 return i18nString(UIStrings.fms, {PH1: value.toFixed(1)});
Blink Reformat4c46d092018-04-07 15:32:37291 }
292
Jan Scheffler76e4ba92021-02-25 12:58:08293 formatValueAccessibleText(value: number): string {
Brandon Goddard06186802019-10-11 17:38:45294 return this.formatValue(value);
295 }
296
Jan Scheffler76e4ba92021-02-25 12:58:08297 formatPercent(value: number, node: ProfileDataGridNode): string {
Simon Zünd4413f332020-11-04 12:34:56298 if (this._profileView) {
299 const profile = this._profileView.profile();
Jan Scheffler76e4ba92021-02-25 12:58:08300 if (profile && node.profileNode !== (profile as SDK.CPUProfileDataModel.CPUProfileDataModel).idleNode) {
vidorteg7c153a22021-01-21 20:57:08301 return i18nString(UIStrings.formatPercent, {PH1: value.toFixed(2)});
Simon Zünd4413f332020-11-04 12:34:56302 }
303 }
304 return '';
Blink Reformat4c46d092018-04-07 15:32:37305 }
306
Jan Scheffler76e4ba92021-02-25 12:58:08307 linkifyNode(node: ProfileDataGridNode): Element|null {
Simon Zünd2b1513d2020-11-04 10:15:28308 const cpuProfilerModel = this._profileView.profileHeader._cpuProfilerModel;
Jack Lynch236e1d22020-01-07 20:33:51309 const target = cpuProfilerModel ? cpuProfilerModel.target() : null;
Philip Pfaffe068b01d2021-03-22 09:46:26310 const options = {className: 'profile-node-file', columnNumber: undefined, inlineFrameIndex: 0, tabStop: undefined};
Jack Lynch236e1d22020-01-07 20:33:51311 return this._profileView.linkifier().maybeLinkifyConsoleCallFrame(target, node.profileNode.callFrame, options);
Blink Reformat4c46d092018-04-07 15:32:37312 }
Tim van der Lippe6288cf32020-01-07 16:58:40313}
Blink Reformat4c46d092018-04-07 15:32:37314
Paul Lewis0d43b802020-01-14 13:34:23315export class CPUFlameChartDataProvider extends ProfileFlameChartDataProvider {
Jan Scheffler76e4ba92021-02-25 12:58:08316 _cpuProfile: SDK.CPUProfileDataModel.CPUProfileDataModel;
317 _cpuProfilerModel: SDK.CPUProfilerModel.CPUProfilerModel|null;
318 _entrySelfTimes?: Float32Array;
319
320 constructor(
321 cpuProfile: SDK.CPUProfileDataModel.CPUProfileDataModel,
322 cpuProfilerModel: SDK.CPUProfilerModel.CPUProfilerModel|null) {
Blink Reformat4c46d092018-04-07 15:32:37323 super();
324 this._cpuProfile = cpuProfile;
325 this._cpuProfilerModel = cpuProfilerModel;
326 }
327
Jan Scheffler76e4ba92021-02-25 12:58:08328 minimumBoundary(): number {
Peter Marshall5b7d05c2020-11-19 10:22:06329 return this._cpuProfile.profileStartTime;
330 }
331
Jan Scheffler76e4ba92021-02-25 12:58:08332 totalTime(): number {
Peter Marshall5b7d05c2020-11-19 10:22:06333 return this._cpuProfile.profileHead.total;
334 }
335
Jan Scheffler76e4ba92021-02-25 12:58:08336 entryHasDeoptReason(entryIndex: number): boolean {
337 const node = (this.entryNodes[entryIndex] as SDK.CPUProfileDataModel.CPUProfileNode);
Tim van der Lipped7cfd142021-01-07 12:17:24338 return Boolean(node.deoptReason);
Peter Marshall5b7d05c2020-11-19 10:22:06339 }
340
Jan Scheffler76e4ba92021-02-25 12:58:08341 _calculateTimelineData(): PerfUI.FlameChart.TimelineData {
342 const entries: (CPUFlameChartDataProvider.ChartEntry|null)[] = [];
343 const stack: number[] = [];
Blink Reformat4c46d092018-04-07 15:32:37344 let maxDepth = 5;
345
Jan Scheffler76e4ba92021-02-25 12:58:08346 function onOpenFrame(): void {
Blink Reformat4c46d092018-04-07 15:32:37347 stack.push(entries.length);
348 // Reserve space for the entry, as they have to be ordered by startTime.
349 // The entry itself will be put there in onCloseFrame.
350 entries.push(null);
351 }
Jan Scheffler76e4ba92021-02-25 12:58:08352 function onCloseFrame(
353 depth: number, node: SDK.CPUProfileDataModel.CPUProfileNode, startTime: number, totalTime: number,
354 selfTime: number): void {
355 const index = (stack.pop() as number);
Tim van der Lippe6288cf32020-01-07 16:58:40356 entries[index] = new CPUFlameChartDataProvider.ChartEntry(depth, totalTime, startTime, selfTime, node);
Blink Reformat4c46d092018-04-07 15:32:37357 maxDepth = Math.max(maxDepth, depth);
358 }
359 this._cpuProfile.forEachFrame(onOpenFrame, onCloseFrame);
360
Jan Scheffler76e4ba92021-02-25 12:58:08361 const entryNodes: SDK.CPUProfileDataModel.CPUProfileNode[] = new Array(entries.length);
Blink Reformat4c46d092018-04-07 15:32:37362 const entryLevels = new Uint16Array(entries.length);
363 const entryTotalTimes = new Float32Array(entries.length);
364 const entrySelfTimes = new Float32Array(entries.length);
365 const entryStartTimes = new Float64Array(entries.length);
366
367 for (let i = 0; i < entries.length; ++i) {
368 const entry = entries[i];
Simon Zünd4413f332020-11-04 12:34:56369 if (!entry) {
370 continue;
371 }
Blink Reformat4c46d092018-04-07 15:32:37372 entryNodes[i] = entry.node;
373 entryLevels[i] = entry.depth;
374 entryTotalTimes[i] = entry.duration;
375 entryStartTimes[i] = entry.startTime;
376 entrySelfTimes[i] = entry.selfTime;
377 }
378
379 this._maxStackDepth = maxDepth + 1;
Peter Marshall5b7d05c2020-11-19 10:22:06380 this.entryNodes = entryNodes;
381 this.timelineData_ = new PerfUI.FlameChart.TimelineData(entryLevels, entryTotalTimes, entryStartTimes, null);
Blink Reformat4c46d092018-04-07 15:32:37382
Blink Reformat4c46d092018-04-07 15:32:37383 this._entrySelfTimes = entrySelfTimes;
384
Peter Marshall5b7d05c2020-11-19 10:22:06385 return this.timelineData_;
Blink Reformat4c46d092018-04-07 15:32:37386 }
387
Jan Scheffler76e4ba92021-02-25 12:58:08388 prepareHighlightedEntryInfo(entryIndex: number): Element|null {
Peter Marshall5b7d05c2020-11-19 10:22:06389 const timelineData = this.timelineData_;
390 const node = this.entryNodes[entryIndex];
Tim van der Lippe1d6e57a2019-09-30 11:55:34391 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37392 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34393 }
Blink Reformat4c46d092018-04-07 15:32:37394
Jan Scheffler76e4ba92021-02-25 12:58:08395 const entryInfo: {
396 title: string,
397 value: string,
398 }[] = [];
399 function pushEntryInfoRow(title: string, value: string): void {
Blink Reformat4c46d092018-04-07 15:32:37400 entryInfo.push({title: title, value: value});
401 }
Jan Scheffler76e4ba92021-02-25 12:58:08402 function millisecondsToString(ms: number): string {
Tim van der Lippe1d6e57a2019-09-30 11:55:34403 if (ms === 0) {
Blink Reformat4c46d092018-04-07 15:32:37404 return '0';
Tim van der Lippe1d6e57a2019-09-30 11:55:34405 }
406 if (ms < 1000) {
vidorteg7c153a22021-01-21 20:57:08407 return i18nString(UIStrings.fms, {PH1: ms.toFixed(1)});
Tim van der Lippe1d6e57a2019-09-30 11:55:34408 }
Kriti Sapra915aed72021-06-04 11:29:58409 return i18n.i18n.secondsToString(ms / 1000, true);
Blink Reformat4c46d092018-04-07 15:32:37410 }
Tim van der Lippee54f66e2020-02-03 18:20:32411 const name = UI.UIUtils.beautifyFunctionName(node.functionName);
vidorteg7c153a22021-01-21 20:57:08412 pushEntryInfoRow(i18nString(UIStrings.name), name);
Jan Scheffler76e4ba92021-02-25 12:58:08413 const selfTime = millisecondsToString((this._entrySelfTimes as Float32Array)[entryIndex]);
Simon Zünd4413f332020-11-04 12:34:56414 const totalTime =
Jan Scheffler76e4ba92021-02-25 12:58:08415 millisecondsToString((timelineData as PerfUI.FlameChart.TimelineData).entryTotalTimes[entryIndex]);
vidorteg7c153a22021-01-21 20:57:08416 pushEntryInfoRow(i18nString(UIStrings.selfTime), selfTime);
417 pushEntryInfoRow(i18nString(UIStrings.totalTime), totalTime);
Tim van der Lippee54f66e2020-02-03 18:20:32418 const linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37419 const link = linkifier.maybeLinkifyConsoleCallFrame(
420 this._cpuProfilerModel && this._cpuProfilerModel.target(), node.callFrame);
Tim van der Lippe1d6e57a2019-09-30 11:55:34421 if (link) {
vidorteg7c153a22021-01-21 20:57:08422 pushEntryInfoRow(i18nString(UIStrings.url), link.textContent || '');
Tim van der Lippe1d6e57a2019-09-30 11:55:34423 }
Blink Reformat4c46d092018-04-07 15:32:37424 linkifier.dispose();
Kriti Sapra915aed72021-06-04 11:29:58425 pushEntryInfoRow(i18nString(UIStrings.aggregatedSelfTime), i18n.i18n.secondsToString(node.self / 1000, true));
426 pushEntryInfoRow(i18nString(UIStrings.aggregatedTotalTime), i18n.i18n.secondsToString(node.total / 1000, true));
Jan Scheffler76e4ba92021-02-25 12:58:08427 const deoptReason = (node as SDK.CPUProfileDataModel.CPUProfileNode).deoptReason;
Peter Marshall5b7d05c2020-11-19 10:22:06428 if (deoptReason) {
vidorteg7c153a22021-01-21 20:57:08429 pushEntryInfoRow(i18nString(UIStrings.notOptimized), deoptReason);
Tim van der Lippe1d6e57a2019-09-30 11:55:34430 }
Blink Reformat4c46d092018-04-07 15:32:37431
Paul Lewis0d43b802020-01-14 13:34:23432 return ProfileView.buildPopoverTable(entryInfo);
Blink Reformat4c46d092018-04-07 15:32:37433 }
Tim van der Lippe6288cf32020-01-07 16:58:40434}
Blink Reformat4c46d092018-04-07 15:32:37435
Jan Scheffler76e4ba92021-02-25 12:58:08436export namespace CPUFlameChartDataProvider {
437 export class ChartEntry {
438 depth: number;
439 duration: number;
440 startTime: number;
441 selfTime: number;
442 node: SDK.CPUProfileDataModel.CPUProfileNode;
443
444 constructor(
445 depth: number, duration: number, startTime: number, selfTime: number,
446 node: SDK.CPUProfileDataModel.CPUProfileNode) {
447 this.depth = depth;
448 this.duration = duration;
449 this.startTime = startTime;
450 this.selfTime = selfTime;
451 this.node = node;
452 }
Blink Reformat4c46d092018-04-07 15:32:37453 }
Jan Scheffler76e4ba92021-02-25 12:58:08454}