Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creates search bar for filtering HLO ops in the op profile tool #1180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion frontend/app/components/op_profile/op_profile.ng.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,30 @@
(change)="updateChildrenCount($event.target.value)" />
</mat-form-field>
</div>
<div class="control">
<mat-form-field class="full-width">
<mat-label>Op Name</mat-label>
<input
matInput
matTooltip="Op name to filter by."
aria-label="op-name"
required
autocomplete="off"
type="text"
name="Search Bar"
[value]="searchFilterString"
(keyup)="updateSearchFilter($event.target.value)"
placeholder="Search for ops.."
/>
</mat-form-field>
</div>
</div>
</div>

<op-table
[rootNode]="rootNode"
[byWasted]="byWasted"
[showP90]="showP90"
[childrenCount]="childrenCount">
[childrenCount]="childrenCount"
[searchFilterString]="searchFilterString">
</op-table>
7 changes: 7 additions & 0 deletions frontend/app/components/op_profile/op_profile_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class OpProfileBase {
showP90 = false;
childrenCount = 10;
deviceType = 'TPU';
searchFilterString = '';

private updateRoot() {
if (!this.profile) {
Expand Down Expand Up @@ -76,4 +77,10 @@ export class OpProfileBase {
updateShowP90() {
this.showP90 = !this.showP90;
}

updateSearchFilter(value: string) {
this.searchFilterString = value.toLowerCase() ?? '';
this.updateRoot();
this.data.update(this.rootNode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
[byWasted]="byWasted"
[showP90]="showP90"
[childrenCount]="childrenCount"
[searchFilterString]="searchFilterString"
(hover)="updateActive($event)"
(selected)="updateSelected($event); updateActive($event);">
</op-table-entry>
2 changes: 2 additions & 0 deletions frontend/app/components/op_profile/op_table/op_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export class OpTable implements OnDestroy {
/** The number of children nodes to be shown. */
@Input() childrenCount: number = 10;

@Input() searchFilterString = '';

selectedNode?: Node;

constructor(private readonly store: Store<{}>) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
[byWasted]="byWasted"
[showP90]="showP90"
[childrenCount]="childrenCount"
[searchFilterString]="searchFilterString"
(hover)="hover.emit($event);"
(selected)="onSelect($event);">
</op-table-entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class OpTableEntry implements OnChanges {
/** The number of children nodes to be shown. */
@Input() childrenCount = 10;

// Filters out nodes that don't have descendants that match the filter.
@Input() searchFilterString = '';

/** The event when the mouse enter or leave. */
@Output() readonly hover = new EventEmitter<Node|null>();

Expand Down Expand Up @@ -123,11 +126,29 @@ export class OpTableEntry implements OnChanges {
return this.childrenCount;
}

private matchesSearchFilter(node: Node): boolean {
if (!node || !node.name || node.children?.length === 0) {
return false;
}
if (this.searchFilterString.length === 0) {
return true;
}
if (node.name &&
node.name.toLowerCase().includes(this.searchFilterString)) {
return true;
}
return (node.children ?? [])
.some((child) => this.matchesSearchFilter(child));
}

private getChildren(): Node[] {
if (!this.node || !this.node.children || !this.rootNode) {
return [];
}
let children: Node[] = this.node.children.slice();
let children: Node[] =
(this.node.children.slice())
.filter(
(child) => this.level !== 0 || this.matchesSearchFilter(child));
if (this.byWasted && this.rootNode) {
children.sort(
(a, b) => {
Expand Down
Loading