Skip to content

Commit ec67ce2

Browse files
nevedarenSkCQ
authored andcommitted
Revert "Perf: Clear graphs when count is too large"
This reverts commit 27b508c. Reason for revert: breaks opening from shortcuts (b/467935356) Bug: 467935356 Original change's description: > Perf: Clear graphs when count is too large > > Adds a feature to clear all graphs when the trace count exceeds a maximum limit in the Test Picker. > It also fixes a potential crash in explore-multi-sk when handling remove-explore events without details. > > Change-Id: I15477f7eb8030bc15000a07f436ee9cdd8d088c6 > Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/1056545 > Commit-Queue: Tony Seaward <[email protected]> > Reviewed-by: Farid (Mojtaba) Faridzad <[email protected]> Change-Id: I208e0d2c907bc6efe0dbd7cd324f15f26d3f1ea4 Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/1123236 Auto-Submit: Anri Sidorov <[email protected]> Bot-Commit: Rubber Stamper <[email protected]> Commit-Queue: Rubber Stamper <[email protected]>
1 parent 51b9574 commit ec67ce2

File tree

5 files changed

+35
-103
lines changed

5 files changed

+35
-103
lines changed

perf/modules/explore-multi-sk/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ sk_element(
1919
"//elements-sk/modules:define_ts_lib",
2020
"//infra-sk/modules:hintable_ts_lib",
2121
"//infra-sk/modules:jsonorthrow_ts_lib",
22-
"//infra-sk/modules:query_ts_lib",
2322
"//infra-sk/modules:statereflector_ts_lib",
2423
"//infra-sk/modules/ElementSk:index_ts_lib",
2524
"//infra-sk/modules/json:index_ts_lib",
2625
"//perf/modules/errorMessage:index_ts_lib",
2726
"//perf/modules/json:index_ts_lib",
2827
"//perf/modules/paramtools:index_ts_lib",
29-
"//perf/modules/telemetry:telemetry_ts_lib",
3028
"//perf/modules/window:window_ts_lib",
29+
"//infra-sk/modules:query_ts_lib",
30+
"//perf/modules/telemetry:telemetry_ts_lib",
3131
],
3232
ts_srcs = [
3333
"explore-multi-sk.ts",

perf/modules/explore-multi-sk/explore-multi-sk.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -316,28 +316,20 @@ export class ExploreMultiSk extends ElementSk {
316316
private _onRemoveExplore = (e: Event) => {
317317
this._dataLoading = true;
318318
this.testPicker?.setReadOnly(true);
319-
const detail = (e as CustomEvent).detail;
320-
const exploreElemToRemove = detail ? (detail.elem as ExploreSimpleSk) : null;
321-
if (exploreElemToRemove === null) {
322-
// Remove all explore elements.
323-
this.resetGraphs();
319+
const exploreElemToRemove = (e as CustomEvent).detail.elem as ExploreSimpleSk;
320+
if (this.exploreElements.length === 1) {
321+
this.removeExplore(exploreElemToRemove);
322+
e.stopPropagation();
324323
} else {
325-
if (this.exploreElements.length === 1) {
326-
this.removeExplore(exploreElemToRemove);
327-
e.stopPropagation();
328-
} else {
329-
const param = this.state.splitByKeys[0];
330-
if (exploreElemToRemove.state.queries.length > 0) {
331-
const query = exploreElemToRemove.state.queries[0];
332-
const valueToRemove = new URLSearchParams(query).get(param);
333-
if (valueToRemove) {
334-
this.testPicker?.removeItemFromChart(param, [valueToRemove]);
335-
}
324+
const param = this.state.splitByKeys[0];
325+
if (exploreElemToRemove.state.queries.length > 0) {
326+
const query = exploreElemToRemove.state.queries[0];
327+
const valueToRemove = new URLSearchParams(query).get(param);
328+
if (valueToRemove) {
329+
this.testPicker?.removeItemFromChart(param, [valueToRemove]);
336330
}
337331
}
338332
}
339-
this._dataLoading = false;
340-
this.testPicker?.setReadOnly(false);
341333
};
342334

343335
// Event listener for when the Test Picker plot button is clicked.
@@ -569,7 +561,7 @@ export class ExploreMultiSk extends ElementSk {
569561

570562
// Remove the traces from the current page explore elements.
571563
const elemsToRemove: ExploreSimpleSk[] = [];
572-
const updatePromises = this.exploreElements.map(async (elem) => {
564+
const updatePromises = this.exploreElements.map((elem) => {
573565
const hasQueryToRemove =
574566
elem.state.queries && queriesToRemove.some((qr) => elem.state.queries.includes(qr));
575567

@@ -597,7 +589,7 @@ export class ExploreMultiSk extends ElementSk {
597589
}
598590
if (elem.state.queries.length === 0) {
599591
elemsToRemove.push(elem);
600-
return await Promise.resolve();
592+
return Promise.resolve();
601593
}
602594
const params: ParamSet = ParamSet({});
603595
Object.keys(traceset).forEach((trace) => {
@@ -628,7 +620,7 @@ export class ExploreMultiSk extends ElementSk {
628620
msg: '',
629621
skps: [],
630622
};
631-
return await elem.UpdateWithFrameResponse(
623+
return elem.UpdateWithFrameResponse(
632624
updatedResponse,
633625
updatedRequest,
634626
/* switchToTab= */ true,
@@ -637,7 +629,7 @@ export class ExploreMultiSk extends ElementSk {
637629
/* replaceAnomalies= */ true
638630
);
639631
}
640-
return await Promise.resolve();
632+
return Promise.resolve();
641633
});
642634

643635
await Promise.all(updatePromises);
@@ -1085,7 +1077,7 @@ export class ExploreMultiSk extends ElementSk {
10851077
}
10861078

10871079
const readOnly = this.exploreElements.length > 0;
1088-
await this.testPicker!.initializeTestPicker(testPickerParams!, defaultParams, readOnly);
1080+
this.testPicker!.initializeTestPicker(testPickerParams!, defaultParams, readOnly);
10891081
this._render();
10901082
}
10911083

perf/modules/explore-multi-sk/explore-multi-sk_test.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -335,22 +335,6 @@ describe('ExploreMultiSk', () => {
335335
assert.equal(element['exploreElements'].length, initialGraphCount - 1);
336336
});
337337

338-
it('removes all graphs when a remove-explore event is dispatched with null detail', async () => {
339-
await element['initializeTestPicker'](); // Initialize to attach the listener.
340-
element['addEmptyGraph']();
341-
const initialGraphCount = element['exploreElements'].length;
342-
assert.isAbove(initialGraphCount, 0);
343-
344-
const event = new CustomEvent('remove-explore', {
345-
bubbles: true,
346-
composed: true,
347-
// No detail provided, simulating the bug/feature
348-
});
349-
element.dispatchEvent(event);
350-
351-
assert.equal(element['exploreElements'].length, 0);
352-
});
353-
354338
it('resets pagination when the last graph is removed', async () => {
355339
await element['initializeTestPicker']();
356340
const graph1 = element['addEmptyGraph']()!;
@@ -806,7 +790,7 @@ describe('ExploreMultiSk', () => {
806790
loadExtendedSpy = sinon.stub(mainGraph, 'loadExtendedRangeData').resolves();
807791
sinon.stub(mainGraph, 'getSelectedRange').returns({ begin: 0, end: 1 });
808792
// Ensure that awaiting 'requestComplete' doesn't hang the test.
809-
sinon.stub(mainGraph, 'requestComplete').get(async () => await Promise.resolve());
793+
sinon.stub(mainGraph, 'requestComplete').get(() => Promise.resolve());
810794

811795
// We stub 'addEmptyGraph' to ensure it returns our controlled instance
812796
// of ExploreSimpleSk, allowing us to spy on its methods.

perf/modules/test-picker-sk/test-picker-sk.ts

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,7 @@ export class TestPickerSk extends ElementSk {
121121

122122
this._containerDiv = this.querySelector('#fieldContainer');
123123
this._plotButton = this.querySelector('#plot-button');
124-
// Using document.querySelector('#graphContainer') fails when ExploreMultiSk uses Shadow DOM.
125-
// Instead, find the graph container in the same root (shadow or light) as this element.
126-
const root = this.getRootNode() as ParentNode;
127-
this._graphDiv = root.querySelector ? root.querySelector('#graphContainer') : null;
124+
this._graphDiv = document.querySelector('#graphContainer');
128125

129126
window.addEventListener('data-loaded', () => {
130127
this._dataLoading = false;
@@ -138,7 +135,7 @@ export class TestPickerSk extends ElementSk {
138135
* initializes and populates the field, focuses it, and sets up event
139136
* listeners.
140137
*/
141-
private async addChildField(readOnly: boolean): Promise<void> {
138+
private addChildField(readOnly: boolean): Promise<void> {
142139
const currentIndex = this._currentIndex;
143140
const currentFieldInfo = this._fieldData[currentIndex];
144141
const param = currentFieldInfo.param;
@@ -193,7 +190,7 @@ export class TestPickerSk extends ElementSk {
193190
}
194191
this._render();
195192
};
196-
return await this.callNextParamList(handler, currentIndex);
193+
return this.callNextParamList(handler, currentIndex);
197194
}
198195

199196
/**
@@ -279,7 +276,7 @@ export class TestPickerSk extends ElementSk {
279276
* @param handler - A callback function to handle the JSON response.
280277
* @param index - The index of the current field.
281278
*/
282-
private async callNextParamList(
279+
private callNextParamList(
283280
handler: (json: NextParamListHandlerResponse) => void,
284281
index: number
285282
): Promise<void> {
@@ -296,7 +293,7 @@ export class TestPickerSk extends ElementSk {
296293
q: fieldData,
297294
};
298295

299-
return await fetch('/_/nextParamList/', {
296+
return fetch('/_/nextParamList/', {
300297
method: 'POST',
301298
body: JSON.stringify(body),
302299
headers: {
@@ -693,7 +690,7 @@ export class TestPickerSk extends ElementSk {
693690
*
694691
* @param index
695692
*/
696-
private async fetchExtraOptions(index: number): Promise<void> {
693+
private fetchExtraOptions(index: number): Promise<void> {
697694
const handler = async (json: NextParamListHandlerResponse) => {
698695
const param = Object.keys(json.paramset)[0];
699696
const count: number = json.count || -1;
@@ -756,7 +753,7 @@ export class TestPickerSk extends ElementSk {
756753
}
757754
this._render();
758755
};
759-
return await this.callNextParamList(handler, index);
756+
return this.callNextParamList(handler, index);
760757
}
761758

762759
createParamSetFromFieldData(): ParamSet {
@@ -863,33 +860,19 @@ export class TestPickerSk extends ElementSk {
863860
}
864861

865862
this.setReadOnly(false);
866-
867-
// 1. Check if we need to clear existing graphs due to high count.
868-
if (this._graphDiv && this._graphDiv.children.length > 0 && count > PLOT_MAXIMUM) {
869-
this.dispatchEvent(
870-
new CustomEvent('remove-explore', {
871-
bubbles: true,
872-
composed: true,
873-
})
874-
);
875-
}
876-
877863
this._count = count;
878-
879-
// 2. Handle invalid count (too many or none).
880864
if (count > PLOT_MAXIMUM || count <= 0) {
865+
// Disable plotting if there are too many or no traces.
881866
this.autoAddTrace = false;
882-
this._plotButton!.title = count > PLOT_MAXIMUM ? 'Too many traces.' : 'No traces.';
867+
this._plotButton!.title = this._count > PLOT_MAXIMUM ? 'Too many traces.' : 'No traces.';
883868
this._plotButton!.disabled = true;
884869
return;
885870
}
886-
887-
// 3. Handle valid count.
888871
if (this._graphDiv && this._graphDiv.children.length > 0) {
889-
// Graph loaded, auto-add changes.
872+
// Graph is already loaded, so allow new changes automatically.
890873
this.autoAddTrace = true;
891874
} else {
892-
// No graph, ready to plot.
875+
// No graph loaded yet, so allow plotting.
893876
this._plotButton!.title = 'Plot graph';
894877
this.autoAddTrace = false;
895878
this._plotButton!.disabled = false;
@@ -958,15 +941,15 @@ export class TestPickerSk extends ElementSk {
958941
* queries will automatically get "bot=linux-perf" appended. The exception
959942
* is if bot is already specified in the query, then no defaults are applied.
960943
*/
961-
async initializeTestPicker(
944+
initializeTestPicker(
962945
params: string[],
963946
defaultParams: { [key: string]: string[] | null },
964947
readOnly: boolean
965948
): Promise<void> {
966949
this._defaultParams = defaultParams;
967950
this.initializeFieldData(params);
968951
this._render();
969-
return await this.addChildField(readOnly);
952+
return this.addChildField(readOnly);
970953
}
971954

972955
/**

perf/modules/test-picker-sk/test-picker-sk_test.ts

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('test-picker-sk', () => {
1414

1515
beforeEach(async () => {
1616
// Mock the fetch function.
17-
fetchMock = async (_url: RequestInfo | URL, request: RequestInit | undefined) => {
17+
fetchMock = (_url: RequestInfo | URL, request: RequestInit | undefined) => {
1818
const req = JSON.parse(request!.body as string) as NextParamListHandlerRequest;
1919
const params = toParamSet(req.q!);
2020
const paramset: any = {};
@@ -27,7 +27,7 @@ describe('test-picker-sk', () => {
2727
paramset: paramset,
2828
count: 10,
2929
};
30-
return await Promise.resolve(new Response(JSON.stringify(response)));
30+
return Promise.resolve(new Response(JSON.stringify(response)));
3131
};
3232
window.fetch = fetchMock;
3333

@@ -88,33 +88,6 @@ describe('test-picker-sk', () => {
8888
const e = await eventPromise;
8989
expect(e.detail.query).to.equal('');
9090
});
91-
92-
it('should emit remove-explore event when count exceeds limit and graph is present', async () => {
93-
// Mock the presence of a graph in the container.
94-
const graphDiv = document.createElement('div');
95-
graphDiv.id = 'graphContainer';
96-
graphDiv.appendChild(document.createElement('div')); // Add a child to simulate a loaded graph.
97-
document.body.appendChild(graphDiv);
98-
99-
// Re-initialize element to pick up the graphDiv.
100-
element = newInstance((_el: TestPickerSk) => {});
101-
element.initializeTestPicker(['benchmark'], {}, false);
102-
await new Promise((resolve) => setTimeout(resolve, 100));
103-
104-
// Listen for the event.
105-
let eventCaught = false;
106-
element.addEventListener('remove-explore', () => {
107-
eventCaught = true;
108-
});
109-
110-
// Manually trigger updateCount with a large number.
111-
(element as any).updateCount(201);
112-
113-
expect(eventCaught).to.be.true;
114-
115-
// Cleanup
116-
document.body.removeChild(graphDiv);
117-
});
11891
});
11992

12093
describe('test-picker-sk conditional defaults', () => {
@@ -129,7 +102,7 @@ describe('test-picker-sk conditional defaults', () => {
129102
document.body.appendChild(mockExplore);
130103

131104
// Mock fetch
132-
window.fetch = async (_url: RequestInfo | URL, request: RequestInit | undefined) => {
105+
window.fetch = (_url: RequestInfo | URL, request: RequestInit | undefined) => {
133106
const req = JSON.parse(request!.body as string) as NextParamListHandlerRequest;
134107
const params = toParamSet(req.q!);
135108
const paramset: any = {};
@@ -145,7 +118,7 @@ describe('test-picker-sk conditional defaults', () => {
145118
paramset: paramset,
146119
count: 10,
147120
};
148-
return await Promise.resolve(new Response(JSON.stringify(response)));
121+
return Promise.resolve(new Response(JSON.stringify(response)));
149122
};
150123

151124
element = newInstance((_el: TestPickerSk) => {});

0 commit comments

Comments
 (0)