Skip to content

Commit

Permalink
Add line and column number to flame graph and stack chart tooltips (f…
Browse files Browse the repository at this point in the history
…irefox-devtools#2173)

* Add line and column number to flame graph and stack chart tooltips

Fixes firefox-devtools#2094

* Update FlameGraph snapshot test to include filename in the tooltips
  • Loading branch information
brisad authored Jul 30, 2019
1 parent e2971b4 commit 361f18b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/tooltip/CallNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,24 @@ export class TooltipCallNode extends React.PureComponent<Props> {
// Only JavaScript functions have a filename.
const fileNameIndex = thread.funcTable.fileName[funcIndex];
if (fileNameIndex !== null) {
let fileName = thread.stringTable.getString(fileNameIndex);
const lineNumber = thread.funcTable.lineNumber[funcIndex];
if (lineNumber !== null) {
fileName += ':' + lineNumber;
const columnNumber = thread.funcTable.columnNumber[funcIndex];
if (columnNumber !== null) {
fileName += ':' + columnNumber;
}
}

// Because of our use of Grid Layout, all our elements need to be direct
// children of the grid parent. That's why we use arrays here, to add
// the elements as direct children.
resourceOrFileName = [
<div className="tooltipLabel" key="file">
File:
</div>,
thread.stringTable.getString(fileNameIndex),
fileName,
];
} else {
const resourceIndex = thread.funcTable.resource[funcIndex];
Expand Down
9 changes: 9 additions & 0 deletions src/test/components/FlameGraph.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ function setupFlameGraph() {
E[cat:Graphics] G[cat:Graphics]
`);

// Add some file and line number to the profile so that tooltips generate
// an interesting snapshot.
const { funcTable, stringTable } = profile.threads[0];
for (let funcIndex = 0; funcIndex < funcTable.length; funcIndex++) {
funcTable.lineNumber[funcIndex] = funcIndex + 10;
funcTable.columnNumber[funcIndex] = funcIndex + 100;
funcTable.fileName[funcIndex] = stringTable.indexForString('path/to/file');
}

const store = storeWithProfile(profile);

const renderResult = render(
Expand Down
6 changes: 6 additions & 0 deletions src/test/components/__snapshots__/FlameGraph.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ exports[`FlameGraph has a tooltip that matches the snapshot 1`] = `
/>
DOM
</div>
<div
class="tooltipLabel"
>
File:
</div>
path/to/file:10:100
</div>
</div>
</div>
Expand Down

0 comments on commit 361f18b

Please sign in to comment.