Skip to content

Commit d4a2211

Browse files
Connor ClarkDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Move pretty-mapping for profile data to ProfilePlugin
This moves the manual mapping for the profile data decoration out of UISourceCode and into the ProfilePlugin. This also adds support for the experimental memory decorations for pretty'd sources. Bug: 462212096, 406012441 Change-Id: Id3ceb4e2d6f3b356c3c896d78c08afe39a45cbe8 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7173542 Auto-Submit: Connor Clark <[email protected]> Commit-Queue: Connor Clark <[email protected]> Reviewed-by: Paul Irish <[email protected]>
1 parent d09625d commit d4a2211

File tree

4 files changed

+27
-82
lines changed

4 files changed

+27
-82
lines changed

front_end/models/workspace/UISourceCode.test.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -378,38 +378,6 @@ describe('UISourceCode', () => {
378378

379379
assert.isTrue(sutObject.sut.editDisabled());
380380
});
381-
382-
describe('formatChanged', () => {
383-
it('should remap performance decorations when the source is formatted', () => {
384-
const {sut} = setupMockedUISourceCode();
385-
const decorations = new Map<number, Map<number, number>>();
386-
const columnData = new Map<number, number>();
387-
columnData.set(10, 100); // column 10, value 100
388-
decorations.set(1, columnData); // line 1
389-
390-
sut.setDecorationData(Workspace.UISourceCode.DecoratorType.PERFORMANCE, decorations);
391-
392-
const format = {
393-
originalToFormatted: (lineNumber: number, columnNumber?: number) => {
394-
if (lineNumber === 0 && columnNumber === 9) {
395-
return [4, 1]; // new line 5, new column 2 (0-based)
396-
}
397-
return [lineNumber, columnNumber || 0];
398-
},
399-
};
400-
401-
sut.formatChanged(format);
402-
403-
const newDecorations = sut.getDecorationData(Workspace.UISourceCode.DecoratorType.PERFORMANCE);
404-
assert.isDefined(newDecorations);
405-
406-
const newLineData = newDecorations.get(5); // check line 5 (1-based)
407-
assert.isDefined(newLineData);
408-
409-
const newData = newLineData.get(2); // check column 2 (1-based)
410-
assert.strictEqual(newData, 100);
411-
});
412-
});
413381
});
414382

415383
describe('UILocation', () => {

front_end/models/workspace/UISourceCode.ts

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import * as TextUtils from '../text_utils/text_utils.js';
1212
import {IgnoreListManager} from './IgnoreListManager.js';
1313
import {Events as WorkspaceImplEvents, type Project} from './WorkspaceImpl.js';
1414

15-
export type LineColumnProfileMap = Map<number, Map<number, number>>;
16-
1715
const UIStrings = {
1816
/**
1917
* @description Text for the index of something
@@ -37,9 +35,7 @@ export class UISourceCode extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
3735
#contentType: Common.ResourceType.ResourceType;
3836
#requestContentPromise: Promise<TextUtils.ContentData.ContentDataOrError>|null = null;
3937
#decorations = new Map<string, any>();
40-
#formattedDecorations = new Map<string, any>();
4138
#hasCommits = false;
42-
#prettied = false;
4339
#messages: Set<Message>|null = null;
4440
#content: TextUtils.ContentData.ContentDataOrError|null = null;
4541
#forceLoadOnCheckContent = false;
@@ -501,9 +497,6 @@ export class UISourceCode extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
501497
}
502498

503499
getDecorationData(type: string): any {
504-
if (this.#prettied && this.#formattedDecorations.get(type)) {
505-
return this.#formattedDecorations.get(type);
506-
}
507500
return this.#decorations.get(type);
508501
}
509502

@@ -515,45 +508,6 @@ export class UISourceCode extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
515508
return this.#disableEdit;
516509
}
517510

518-
formatChanged(format: {originalToFormatted(lineNumber: number, columnNumber?: number): number[]}|null): void {
519-
if (this.#prettied === Boolean(format)) {
520-
return;
521-
}
522-
this.#prettied = Boolean(format);
523-
if (!format) {
524-
this.dispatchEventToListeners(Events.DecorationChanged, DecoratorType.PERFORMANCE);
525-
return;
526-
}
527-
const performanceDecorations = this.#decorations.get(DecoratorType.PERFORMANCE);
528-
if (!performanceDecorations) {
529-
return;
530-
}
531-
let formattedPerformanceDecorations: LineColumnProfileMap =
532-
this.#formattedDecorations.get(DecoratorType.PERFORMANCE);
533-
if (!formattedPerformanceDecorations) {
534-
formattedPerformanceDecorations = new Map();
535-
this.#formattedDecorations.set(DecoratorType.PERFORMANCE, formattedPerformanceDecorations);
536-
} else {
537-
formattedPerformanceDecorations.clear();
538-
}
539-
540-
for (const [lineNumber, columnData] of performanceDecorations) {
541-
for (const [columnNumber, data] of columnData) {
542-
const [formattedLineNumber, formattedColumnNumber] =
543-
format.originalToFormatted(lineNumber - 1, columnNumber - 1);
544-
const oneBasedFormattedLineNumber = formattedLineNumber + 1;
545-
const oneBasedFormattedColumnNumber = formattedColumnNumber + 1;
546-
let lineData = formattedPerformanceDecorations.get(oneBasedFormattedLineNumber);
547-
if (!lineData) {
548-
lineData = new Map();
549-
formattedPerformanceDecorations.set(oneBasedFormattedLineNumber, lineData);
550-
}
551-
lineData.set(oneBasedFormattedColumnNumber, (lineData.get(oneBasedFormattedColumnNumber) || 0) + data);
552-
}
553-
}
554-
this.dispatchEventToListeners(Events.DecorationChanged, 'performance');
555-
}
556-
557511
isIgnoreListed(): boolean {
558512
return IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(this);
559513
}

front_end/panels/sources/ProfilePlugin.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as Workspace from '../../models/workspace/workspace.js';
99
import * as CodeMirror from '../../third_party/codemirror.next/codemirror.next.js';
1010
import type * as TextEditor from '../../ui/components/text_editor/text_editor.js';
1111
import type * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
12+
import type * as SourceFrame from '../../ui/legacy/components/source_frame/source_frame.js';
1213

1314
import {Plugin} from './Plugin.js';
1415

@@ -109,13 +110,15 @@ function markersFromProfileData(
109110
return CodeMirror.RangeSet.of(markers, true);
110111
}
111112

112-
const makeLineLevelProfilePlugin = (type: Workspace.UISourceCode.DecoratorType): typeof Plugin => class extends Plugin {
113+
const makeLineLevelProfilePlugin = (type: Workspace.UISourceCode.DecoratorType): typeof Plugin =>
114+
class ProfilePlugin extends Plugin {
113115
updateEffect = CodeMirror.StateEffect.define<PerfUI.LineLevelProfile.LineColumnProfileMap>();
114116
field: CodeMirror.StateField<CodeMirror.RangeSet<CodeMirror.GutterMarker>>;
115117
gutter: CodeMirror.Extension;
116118
compartment: CodeMirror.Compartment = new CodeMirror.Compartment();
119+
readonly #transformer: SourceFrame.SourceFrame.Transformer;
117120

118-
constructor(uiSourceCode: Workspace.UISourceCode.UISourceCode) {
121+
constructor(uiSourceCode: Workspace.UISourceCode.UISourceCode, transformer: SourceFrame.SourceFrame.Transformer) {
119122
super(uiSourceCode);
120123

121124
this.field = CodeMirror.StateField.define<CodeMirror.RangeSet<CodeMirror.GutterMarker>>({
@@ -133,14 +136,35 @@ const makeLineLevelProfilePlugin = (type: Workspace.UISourceCode.DecoratorType):
133136
markers: view => view.state.field(this.field),
134137
class: `cm-${type}Gutter`,
135138
});
139+
140+
this.#transformer = transformer;
136141
}
137142

138143
static override accepts(uiSourceCode: Workspace.UISourceCode.UISourceCode): boolean {
139144
return uiSourceCode.contentType().hasScripts();
140145
}
141146

142147
private getLineMap(): PerfUI.LineLevelProfile.LineColumnProfileMap|undefined {
143-
return this.uiSourceCode.getDecorationData(type);
148+
const uiSourceCodeProfileMap = this.uiSourceCode.getDecorationData(type);
149+
if (!uiSourceCodeProfileMap) {
150+
return undefined;
151+
}
152+
153+
const editorProfileMap: PerfUI.LineLevelProfile.LineColumnProfileMap = new Map();
154+
for (const [lineNumber, columnData] of uiSourceCodeProfileMap) {
155+
for (const [columnNumber, data] of columnData) {
156+
const editorLocation = this.#transformer.uiLocationToEditorLocation(lineNumber - 1, columnNumber - 1);
157+
const oneBasedFormattedLineNumber = editorLocation.lineNumber + 1;
158+
const oneBasedFormattedColumnNumber = editorLocation.columnNumber + 1;
159+
let columnData = editorProfileMap.get(oneBasedFormattedLineNumber);
160+
if (!columnData) {
161+
columnData = new Map();
162+
editorProfileMap.set(oneBasedFormattedLineNumber, columnData);
163+
}
164+
columnData.set(oneBasedFormattedColumnNumber, (columnData.get(oneBasedFormattedColumnNumber) || 0) + data);
165+
}
166+
}
167+
return editorProfileMap;
144168
}
145169

146170
override editorExtension(): CodeMirror.Extension {

front_end/panels/sources/UISourceCodeFrame.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ export class UISourceCodeFrame extends Common.ObjectWrapper
238238
}
239239

240240
override async setContent(content: string): Promise<void> {
241-
this.#uiSourceCode.formatChanged(this.formattedMap);
242241
this.disposePlugins();
243242
this.loadPlugins();
244243
await super.setContent(content);

0 commit comments

Comments
 (0)