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

Move the node finding function to op detail data class #725

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 26 additions & 0 deletions frontend/app/components/op_profile/op_profile_data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Node} from 'org_xprof/frontend/app/common/interfaces/op_profile.jsonpb_decls';
import {ProfileOrNull} from 'org_xprof/frontend/app/common/interfaces/data_table';
import * as utils from 'org_xprof/frontend/app/common/utils/utils';

/** An op profile data class. */
Expand Down Expand Up @@ -36,4 +37,29 @@ export class OpProfileData {
this.flopsUtilizationPercent = undefined;
}
}

// TODO: Make this function stateful or move to util.
findNode(opProfile: ProfileOrNull, moduleName: string, nodeName: string): Node
|null|undefined {
if (!opProfile || !opProfile.byProgram) return null;
for (const topLevelNode of opProfile.byProgram.children!) {
// Find the program id from OpProfile by the selected XLA module.
if (topLevelNode.name === moduleName) {
const node = this.findNodeHelper(topLevelNode.children, nodeName);
if (node) return node;
}
}
return null;
}

private findNodeHelper(children: Node[]|null|undefined, name: string): Node
|null|undefined {
if (!children) return null;
for (const node of children) {
if (node.name === name) return node;
const findChildren = this.findNodeHelper(node.children, name);
if (findChildren) return findChildren;
}
return null;
}
}
Loading