Skip to content

Commit 059d7d0

Browse files
muditgokhale2copybara-github
authored andcommitted
Revert source mapper changes for Hlo stats and roofline model.
PiperOrigin-RevId: 839088687
1 parent 8b5f433 commit 059d7d0

File tree

12 files changed

+76
-265
lines changed

12 files changed

+76
-265
lines changed

frontend/app/common/utils/BUILD

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,3 @@ ts_library(
2525
"@org_xprof//frontend/app/store",
2626
],
2727
)
28-
29-
ts_library(
30-
name = "source_info_utils",
31-
srcs = [
32-
"source_info_utils.ts",
33-
],
34-
deps = ["@npm//safevalues"],
35-
)

frontend/app/common/utils/source_info_utils.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

frontend/app/components/hlo_stats/BUILD

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ xprof_ng_module(
2020
"@npm//@angular/router",
2121
"@npm//@ngrx/store",
2222
"@npm//rxjs",
23-
"@npm//safevalues",
2423
"@org_xprof//frontend/app/common/angular:angular_material_divider",
2524
"@org_xprof//frontend/app/common/angular:angular_material_expansion",
2625
"@org_xprof//frontend/app/common/angular:angular_material_form_field",
@@ -33,18 +32,16 @@ xprof_ng_module(
3332
"@org_xprof//frontend/app/common/interfaces",
3433
"@org_xprof//frontend/app/common/interfaces:chart",
3534
"@org_xprof//frontend/app/common/utils",
36-
"@org_xprof//frontend/app/common/utils:source_info_utils",
3735
"@org_xprof//frontend/app/components/chart",
3836
"@org_xprof//frontend/app/components/chart:chart_options",
3937
"@org_xprof//frontend/app/components/chart:data_processor",
4038
"@org_xprof//frontend/app/components/chart:default_data_provider",
4139
"@org_xprof//frontend/app/components/chart/dashboard",
42-
"@org_xprof//frontend/app/components/chart/table",
4340
"@org_xprof//frontend/app/components/controls/category_filter",
4441
"@org_xprof//frontend/app/components/controls/export_as_csv",
4542
"@org_xprof//frontend/app/components/controls/string_filter",
4643
"@org_xprof//frontend/app/components/framework_op_stats/flop_rate_chart",
47-
"@org_xprof//frontend/app/components/source_mapper",
44+
"@org_xprof//frontend/app/components/stack_trace_snippet",
4845
"@org_xprof//frontend/app/services/data_service_v2:data_service_v2_interface",
4946
"@org_xprof//frontend/app/services/source_code_service:source_code_service_interface",
5047
"@org_xprof//frontend/app/store",

frontend/app/components/hlo_stats/hlo_stats.ng.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@
122122
</chart>
123123
</div>
124124

125-
<source-mapper
125+
<stack-trace-snippet
126126
[sourceFileAndLineNumber]="sourceFileAndLineNumber"
127127
[stackTrace]="stackTrace"
128-
[sessionId]="sessionId"
129-
[programId]="selectedProgramId"
130-
[opName]="selectedOpName"
131-
[opCategory]="selectedOpCategory"
132128
*ngIf="sourceCodeServiceIsAvailable && showStackTrace"/>

frontend/app/components/hlo_stats/hlo_stats.ts

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import {AfterViewInit, Component, inject, Injector, NgZone, OnDestroy, ViewChild} from '@angular/core';
1+
import {Component, ElementRef, inject, Injector, NgZone, OnDestroy, Renderer2, ViewChild} from '@angular/core';
22
import {FormControl} from '@angular/forms';
33
import {ActivatedRoute, Params} from '@angular/router';
44
import {Store} from '@ngrx/store';
55
import {Throbber} from 'org_xprof/frontend/app/common/classes/throbber';
66
import {OpType} from 'org_xprof/frontend/app/common/constants/enums';
77
import {ChartDataInfo} from 'org_xprof/frontend/app/common/interfaces/chart';
88
import {SimpleDataTable} from 'org_xprof/frontend/app/common/interfaces/data_table';
9-
import {parseSourceInfo} from 'org_xprof/frontend/app/common/utils/source_info_utils';
109
import {setLoadingState} from 'org_xprof/frontend/app/common/utils/utils';
1110
import {CategoryTableDataProcessor} from 'org_xprof/frontend/app/components/chart/category_table_data_processor';
1211
import {Chart} from 'org_xprof/frontend/app/components/chart/chart';
@@ -41,14 +40,10 @@ const TOTAL_TIME_ID = 'total_time';
4140
templateUrl: './hlo_stats.ng.html',
4241
styleUrls: ['./hlo_stats.css'],
4342
})
44-
export class HloStats extends Dashboard implements OnDestroy, AfterViewInit {
43+
export class HloStats extends Dashboard implements OnDestroy {
4544
tool = 'hlo_op_stats';
4645
sessionId = '';
4746
host = '';
48-
// Info for selected op.
49-
selectedProgramId = '';
50-
selectedOpName = '';
51-
selectedOpCategory = '';
5247
private readonly injector = inject(Injector);
5348
private readonly dataService: DataServiceV2Interface =
5449
inject(DATA_SERVICE_INTERFACE_TOKEN);
@@ -116,8 +111,15 @@ export class HloStats extends Dashboard implements OnDestroy, AfterViewInit {
116111
tableColumnsControl = new FormControl<number[]>([]);
117112
tableColumns: Array<{index: number; label: string}> = [];
118113

114+
// We add a listener to `chart` and manipulate multiple elements of
115+
// `chartElement`. Knowing that `Chart.elementRef` is private, we use
116+
// `ViewChild` twice to access both. See `addSourceInfoClickListener` for
117+
// more details.
119118
@ViewChild('table', {read: Chart, static: false})
120-
tableRef: Chart|undefined = undefined;
119+
chartRef: Chart|undefined = undefined;
120+
@ViewChild('table', {read: ElementRef, static: false})
121+
chartElementRef: ElementRef|undefined = undefined;
122+
private readonly renderer: Renderer2 = inject(Renderer2);
121123
sourceFileAndLineNumber = '';
122124
stackTrace = '';
123125
showStackTrace = false;
@@ -144,6 +146,9 @@ export class HloStats extends Dashboard implements OnDestroy, AfterViewInit {
144146
this.injector.get(SOURCE_CODE_SERVICE_INTERFACE_TOKEN, null);
145147
this.sourceCodeServiceIsAvailable =
146148
sourceCodeService?.isAvailable() === true;
149+
if (this.sourceCodeServiceIsAvailable) {
150+
this.addSourceInfoClickListener();
151+
}
147152
}
148153

149154
processQuery(params: Params) {
@@ -225,63 +230,48 @@ export class HloStats extends Dashboard implements OnDestroy, AfterViewInit {
225230
return updatedData;
226231
}
227232

228-
ngAfterViewInit() {
229-
if (this.sourceCodeServiceIsAvailable) {
230-
this.addTableRowSelectListener();
231-
}
232-
}
233-
234-
private addTableRowSelectListener() {
235-
const chart = this.tableRef?.chart;
236-
if (!chart) {
233+
/**
234+
* Adds a click listener to the source info cells.
235+
*
236+
* If "Show Source Code" is checked, then whenever user clicks on the source
237+
* info cell, we show snippets of source code around the stack trace.
238+
*
239+
* Unfortunately, `google.visualization.Table` does not provide any API to
240+
* listen to click events on *cells*. So we manually add the click listener
241+
* to the items in this table (see
242+
* https://developers.google.com/chart/interactive/docs/gallery/table#events
243+
* as a reference).
244+
*
245+
* Unfortunately, `google.visualization.Table` does not provide enough
246+
* extension points to add interactive elements to cells. Therefore, we go
247+
* to the native elements of the table and add the click listener to the
248+
* cells with class `source-info-cell`.
249+
*/
250+
private addSourceInfoClickListener() {
251+
const chart = this.chartRef?.chart;
252+
const chartElement = this.chartElementRef?.nativeElement;
253+
if (!chart || !chartElement) {
254+
// TODO: b/429036372 - Using setTimeout to detect change is inefficient.
237255
setTimeout(() => {
238-
this.addTableRowSelectListener();
256+
this.addSourceInfoClickListener();
239257
}, 100);
240258
return;
241259
}
242-
google.visualization.events.addListener(chart, 'select', () => {
243-
this.zone.run(() => {
244-
const selection = chart.getSelection();
245-
if (selection && selection.length > 0 && selection[0].row != null) {
246-
const rowIndex = selection[0].row;
247-
const rowData: Array<string|number|boolean|Date|null|undefined> = [];
248-
if (this.dataView) {
249-
for (let i = 0; i < this.dataView.getNumberOfColumns(); i++) {
250-
rowData.push(this.dataView.getValue(rowIndex, i));
251-
}
252-
this.handleRowSelection(rowIndex, rowData);
260+
google.visualization.events.addListener(chart, 'ready', () => {
261+
this.renderer.listen(chartElement, 'click', (event: Event) => {
262+
const target = event.target;
263+
if (target instanceof HTMLElement) {
264+
if (target.classList.contains('source-info-cell')) {
265+
this.zone.run(() => {
266+
this.sourceFileAndLineNumber = target.textContent || '';
267+
this.stackTrace = target.getAttribute('title') || '';
268+
});
253269
}
254270
}
255271
});
256272
});
257273
}
258274

259-
handleRowSelection(
260-
rowIndex: number,
261-
rowData: Array<string|number|boolean|Date|null|undefined>) {
262-
if (!this.dataView || !this.dataTable) return;
263-
const programId =
264-
(rowData[this.dataTable.getColumnIndex(PROGRAM_ID)] as string ||
265-
'').trim();
266-
const opName =
267-
(rowData[this.dataTable.getColumnIndex(OP_NAME_ID)] as string ||
268-
'').trim();
269-
const opCategory =
270-
(rowData[this.dataTable.getColumnIndex(OP_CATEGORY_ID)] as string ||
271-
'').trim();
272-
const sourceInfoHtmlString =
273-
(rowData[this.dataTable.getColumnIndex(SOURCE_INFO_ID)] as string ||
274-
'').trim();
275-
this.selectedProgramId = programId;
276-
this.selectedOpName = opName;
277-
this.selectedOpCategory = opCategory;
278-
279-
const {sourceFileAndLineNumber, stackTrace} =
280-
parseSourceInfo(sourceInfoHtmlString);
281-
this.sourceFileAndLineNumber = sourceFileAndLineNumber;
282-
this.stackTrace = stackTrace;
283-
}
284-
285275
toggleShowStackTrace() {
286276
this.showStackTrace = !this.showStackTrace;
287277
}
@@ -301,7 +291,6 @@ export class HloStats extends Dashboard implements OnDestroy, AfterViewInit {
301291
}
302292

303293
override updateView() {
304-
super.updateView();
305294
this.dataInfoForTable = {
306295
...this.dataInfoForTable,
307296
filters: this.getFilters(),

frontend/app/components/hlo_stats/hlo_stats_module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {CategoryFilterModule} from 'org_xprof/frontend/app/components/controls/c
1313
import {ExportAsCsvModule} from 'org_xprof/frontend/app/components/controls/export_as_csv/export_as_csv_module';
1414
import {StringFilterModule} from 'org_xprof/frontend/app/components/controls/string_filter/string_filter_module';
1515
import {FlopRateChartModule} from 'org_xprof/frontend/app/components/framework_op_stats/flop_rate_chart/flop_rate_chart_module';
16-
import {SourceMapperModule} from 'org_xprof/frontend/app/components/source_mapper/source_mapper_module';
16+
import {StackTraceSnippetModule} from 'org_xprof/frontend/app/components/stack_trace_snippet/stack_trace_snippet_module';
1717

1818
import {HloStats} from './hlo_stats';
1919

@@ -36,7 +36,7 @@ import {HloStats} from './hlo_stats';
3636
ReactiveFormsModule,
3737
MatIconModule,
3838
MatSlideToggleModule,
39-
SourceMapperModule,
39+
StackTraceSnippetModule,
4040
],
4141
exports: [HloStats],
4242
})

frontend/app/components/hlo_stats/stack_trace_utils.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

frontend/app/components/roofline_model/operation_level_analysis/BUILD

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ xprof_ng_module(
1616
# strict_templates = False,
1717
deps = [
1818
"@npm//@angular/core",
19-
"@npm//safevalues",
2019
"@org_xprof//frontend/app/common/angular:angular_material_icon",
2120
"@org_xprof//frontend/app/common/angular:angular_material_slide_toggle",
2221
"@org_xprof//frontend/app/common/constants:roofline_model_constants",
2322
"@org_xprof//frontend/app/common/interfaces",
2423
"@org_xprof//frontend/app/common/interfaces:chart",
25-
"@org_xprof//frontend/app/common/utils:source_info_utils",
2624
"@org_xprof//frontend/app/components/chart",
2725
"@org_xprof//frontend/app/components/chart:chart_options",
2826
"@org_xprof//frontend/app/components/chart:data_processor",
@@ -31,7 +29,7 @@ xprof_ng_module(
3129
"@org_xprof//frontend/app/components/chart/table",
3230
"@org_xprof//frontend/app/components/controls/category_filter",
3331
"@org_xprof//frontend/app/components/controls/string_filter",
34-
"@org_xprof//frontend/app/components/source_mapper",
32+
"@org_xprof//frontend/app/components/stack_trace_snippet",
3533
"@org_xprof//frontend/app/services/source_code_service:source_code_service_interface",
3634
],
3735
)

frontend/app/components/roofline_model/operation_level_analysis/operation_level_analysis.ng.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
</div>
2525
<table #table [dataView]="dataView" [showRowNumber]="true"></table>
2626

27-
<source-mapper
27+
<stack-trace-snippet
2828
[sourceFileAndLineNumber]="sourceFileAndLineNumber"
2929
[stackTrace]="stackTrace"
30-
[sessionId]="sessionId"
31-
[programId]="selectedProgramId"
32-
[opName]="selectedOpName"
33-
[opCategory]="selectedOpCategory"
3430
*ngIf="sourceCodeServiceIsAvailable && showStackTrace"/>

0 commit comments

Comments
 (0)