Skip to content

Commit

Permalink
Tested by entering input into this search bar and checking if items f…
Browse files Browse the repository at this point in the history
…iltered out match the criteria that the name of an item or its children must regex match the string in the search bar

PiperOrigin-RevId: 705934808
  • Loading branch information
Profiler Team authored and copybara-github committed Dec 13, 2024
1 parent 4d0a1d4 commit e0b1784
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
6 changes: 5 additions & 1 deletion frontend/app/components/op_profile/op_profile.ng.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
matTooltip="Number of ops to show per layer. 10 ~ 100 with increment of 10."
(change)="updateChildrenCount($event.target.value)" />
</mat-form-field>
<div class="control">
<input type="text" name="Search Bar" [value]="searchFilterString" (keyup)="updateSearchFilter($event.target.value)" placeholder="Search for ops..">
</div>
</div>
</div>
</div>
Expand All @@ -73,5 +76,6 @@
[rootNode]="rootNode"
[byWasted]="byWasted"
[showP90]="showP90"
[childrenCount]="childrenCount">
[childrenCount]="childrenCount"
[searchFilterString]="searchFilterString">
</op-table>
8 changes: 8 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,11 @@ export class OpProfileBase {
updateShowP90() {
this.showP90 = !this.showP90;
}

updateSearchFilter(value: string) {
this.searchFilterString = value ?? '';
console.log('updateSearchFilter', this.searchFilterString);
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

0 comments on commit e0b1784

Please sign in to comment.