Skip to content

Commit

Permalink
Create formatDurationPs in utils to create human readable time stri…
Browse files Browse the repository at this point in the history
…ng in op-details.

PiperOrigin-RevId: 727085680
  • Loading branch information
zzzaries authored and copybara-github committed Feb 14, 2025
1 parent e4615b2 commit 3b04a3c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
15 changes: 15 additions & 0 deletions frontend/app/common/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,18 @@ export function getStringColumnValue(
}
return String((row[columnIndex] || {}).v || '');
}

/**
* Format the duration in picoseconds to a string with proper unit.
* durationPs: duration in picoseconds
* dp: number of decimal places to display, default is 2
*/
export function formatDurationPs(durationPs: number, dp = 2) {
const units = ['ps', 'ns', 'us', 'ms', 's'];
let i = 0;
while (durationPs >= 1000 && i < units.length - 1) {
durationPs /= 1000;
i++;
}
return `${durationPs.toFixed(dp)} ${units[i]}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
</button>
</a>
</div>
<div class="info" [hidden]="!avgTimeMs">
<div class="info" [hidden]="!avgTime">
<div class="title">Total Time Avg:</div>
<code class="expression">{{avgTimeMs}}</code>
<code class="expression">{{avgTime}}</code>
</div>
<div class="info" [hidden]="!flopsUtilization">
<div class="title">FLOPS utilization:</div>
Expand Down
7 changes: 3 additions & 4 deletions frontend/app/components/op_profile/op_details/op_details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class OpDetails {
provenance: string = '';
rawTimeMs = '';
occurrences = 0;
avgTimeMs = '';
avgTime = '';
fused: boolean = false;
hasCategory: boolean = false;
hasLayout: boolean = false;
Expand Down Expand Up @@ -273,10 +273,9 @@ export class OpDetails {
this.occurrences = this.node.metrics?.occurrences || 0;

if (this.node.metrics && this.node.metrics.avgTimePs) {
this.avgTimeMs = utils.humanReadableText(
this.node.metrics.avgTimePs / 1e9, {si: true, dp: 2, suffix: ' ms'});
this.avgTime = utils.formatDurationPs(this.node.metrics.avgTimePs);
} else {
this.avgTimeMs = '';
this.avgTime = '';
}

this.fused = !!this.node.xla && !this.node.metrics;
Expand Down

0 comments on commit 3b04a3c

Please sign in to comment.