Skip to content

Commit

Permalink
In Trace Viewer event tooltip, show event duration in appropriate tim…
Browse files Browse the repository at this point in the history
…e unit and round to 3 decimal places.

Also, truncate event names such that they're limited to 50 characters.

PiperOrigin-RevId: 674413971
  • Loading branch information
Profiler Team authored and copybara-github committed Sep 13, 2024
1 parent e32a378 commit ac8aae3
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions plugin/trace_viewer/tf_trace_viewer/tf-trace-viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,17 @@
}
},

_formatDuration: function(durationMs) {
const units = ['ps', 'ns', 'us', 'ms', 's'];
let i = 0;
let value = Math.round(durationMs * 1_000_000_000); // to picoseconds
while (value >= 1000 && i < units.length - 1) {
value /= 1000;
i++;
}
return `${value.toFixed(3)} ${units[i]}`;
},

_addRectTooltipNode: function() {
const tooltipDiv = document.createElement('div');
tooltipDiv.setAttribute('id', 'event_tooltip');
Expand All @@ -811,14 +822,18 @@
return;
};
const el = document.getElementById('event_tooltip');
// TODO: handle event duration that's < 0.005 ms
const text = `${this._hoverRect.title} - [${this._hoverRect.duration.toFixed(2)} ms]`;
const maxTitleLength = 50;
let truncatedTitle = this._hoverRect.title.substring(0, maxTitleLength);
if (this._hoverRect.title.length > maxTitleLength) {
truncatedTitle += "...";
}
const text = `${truncatedTitle} [${this._formatDuration(this._hoverRect.duration)}]`;
el.innerText = text;
const xOffset = 10;
el.style.left=`${x + xOffset}px`;
el.style.top =`${y}px`;
el.style.visibility = 'visible';
el.style.width = `${text.length * 6}px`;
el.style.width = `fit-content`;
},

_hideRectTooltip: function() {
Expand Down

0 comments on commit ac8aae3

Please sign in to comment.