Skip to content

Commit

Permalink
feat(flamegraph): allow sorting by diff percentage (#1776)
Browse files Browse the repository at this point in the history
* add sort by diff column to ProfilerTable

* handle infinity value
  • Loading branch information
dogfrogfog authored Nov 30, 2022
1 parent ebef7aa commit 8d9c838
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/pyroscope-flamegraph/src/ProfilerTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const tableFormatDouble: {
{ sortable: 1, name: 'name', label: 'Location' },
{ sortable: 1, name: 'baseline', label: 'Baseline', default: true },
{ sortable: 1, name: 'comparison', label: 'Comparison' },
{ sortable: 0, name: 'diff', label: 'Diff' },
{ sortable: 1, name: 'diff', label: 'Diff' },
];

function Table({
Expand Down Expand Up @@ -290,10 +290,23 @@ const getTableBody = ({
);
break;
}
// todo: add sort for ProfileTable diff column
// case 'diff': {
// break;
// }
case 'diff': {
sorted = (tableBodyCells as (DoubleCell & { name: string })[]).sort(
(a, b) => {
const totalDiffA = diffPercent(
ratioToPercent(a.totalLeft / a.leftTicks),
ratioToPercent(a.totalRght / a.rightTicks)
);
const totalDiffB = diffPercent(
ratioToPercent(b.totalLeft / b.leftTicks),
ratioToPercent(b.totalRght / b.rightTicks)
);

return m * (totalDiffA - totalDiffB);
}
);
break;
}
default:
sorted = tableBodyCells;
break;
Expand Down Expand Up @@ -356,7 +369,7 @@ const getTableBody = ({
}

let diffValue = '';
if (!x.totalLeft) {
if (!x.totalLeft || totalDiff === Infinity) {
// this is a new function
diffValue = '(new)';
} else if (!x.totalRght) {
Expand Down

0 comments on commit 8d9c838

Please sign in to comment.