Skip to content

Commit cb71088

Browse files
committed
Move defaultThreadOrder to tracks.js
1 parent 8c5866f commit cb71088

File tree

2 files changed

+49
-51
lines changed

2 files changed

+49
-51
lines changed

src/profile-logic/profile-data.js

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ import type {
9595
TabID,
9696
} from 'firefox-profiler/types';
9797
import type { CallNodeInfo, SuffixOrderIndex } from './call-node-info';
98-
import type { ThreadActivityScore } from './tracks';
9998

10099
/**
101100
* Various helpers for dealing with the profile as a data structure.
@@ -1287,54 +1286,6 @@ export function getTimeRangeIncludingAllThreads(
12871286
return completeRange;
12881287
}
12891288

1290-
export function defaultThreadOrder(
1291-
visibleThreadIndexes: ThreadIndex[],
1292-
threads: RawThread[],
1293-
threadActivityScores: Array<ThreadActivityScore>
1294-
): ThreadIndex[] {
1295-
const threadOrder = [...visibleThreadIndexes];
1296-
1297-
// Note: to have a consistent behavior independant of the sorting algorithm,
1298-
// we need to be careful that the comparator function is consistent:
1299-
// comparator(a, b) === - comparator(b, a)
1300-
// and
1301-
// comparator(a, b) === 0 if and only if a === b
1302-
threadOrder.sort((a, b) => {
1303-
const nameA = threads[a].name;
1304-
const nameB = threads[b].name;
1305-
1306-
if (nameA === nameB) {
1307-
return (
1308-
threadActivityScores[b].boostedSampleScore -
1309-
threadActivityScores[a].boostedSampleScore
1310-
);
1311-
}
1312-
1313-
// Put the compositor/renderer thread last.
1314-
// Compositor will always be before Renderer, if both are present.
1315-
if (nameA === 'Compositor') {
1316-
return 1;
1317-
}
1318-
1319-
if (nameB === 'Compositor') {
1320-
return -1;
1321-
}
1322-
1323-
if (nameA === 'Renderer') {
1324-
return 1;
1325-
}
1326-
1327-
if (nameB === 'Renderer') {
1328-
return -1;
1329-
}
1330-
1331-
// Otherwise keep the existing order. We don't return 0 to guarantee that
1332-
// the sort is stable even if the sort algorithm isn't.
1333-
return a - b;
1334-
});
1335-
return threadOrder;
1336-
}
1337-
13381289
export function toValidImplementationFilter(
13391290
implementation: string
13401291
): ImplementationFilter {

src/profile-logic/tracks.js

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import type {
2020
} from 'firefox-profiler/types';
2121

2222
import {
23-
defaultThreadOrder,
2423
getFriendlyThreadName,
2524
computeStackTableFromRawStackTable,
2625
} from './profile-data';
@@ -801,7 +800,7 @@ function getDefaultSelectedThreadIndexes(
801800
throw new Error('Expected to find a thread index to select.');
802801
}
803802

804-
const threadOrder = defaultThreadOrder(
803+
const threadOrder = _defaultThreadOrder(
805804
visibleThreadIndexes,
806805
threads,
807806
threadActivityScores
@@ -819,6 +818,54 @@ function getDefaultSelectedThreadIndexes(
819818
return new Set([defaultThreadIndex]);
820819
}
821820

821+
function _defaultThreadOrder(
822+
visibleThreadIndexes: ThreadIndex[],
823+
threads: RawThread[],
824+
threadActivityScores: Array<ThreadActivityScore>
825+
): ThreadIndex[] {
826+
const threadOrder = [...visibleThreadIndexes];
827+
828+
// Note: to have a consistent behavior independant of the sorting algorithm,
829+
// we need to be careful that the comparator function is consistent:
830+
// comparator(a, b) === - comparator(b, a)
831+
// and
832+
// comparator(a, b) === 0 if and only if a === b
833+
threadOrder.sort((a, b) => {
834+
const nameA = threads[a].name;
835+
const nameB = threads[b].name;
836+
837+
if (nameA === nameB) {
838+
return (
839+
threadActivityScores[b].boostedSampleScore -
840+
threadActivityScores[a].boostedSampleScore
841+
);
842+
}
843+
844+
// Put the compositor/renderer thread last.
845+
// Compositor will always be before Renderer, if both are present.
846+
if (nameA === 'Compositor') {
847+
return 1;
848+
}
849+
850+
if (nameB === 'Compositor') {
851+
return -1;
852+
}
853+
854+
if (nameA === 'Renderer') {
855+
return 1;
856+
}
857+
858+
if (nameB === 'Renderer') {
859+
return -1;
860+
}
861+
862+
// Otherwise keep the existing order. We don't return 0 to guarantee that
863+
// the sort is stable even if the sort algorithm isn't.
864+
return a - b;
865+
});
866+
return threadOrder;
867+
}
868+
822869
// Returns either a configuration of hidden tracks that has at least one
823870
// visible thread, or null.
824871
export function tryInitializeHiddenTracksLegacy(

0 commit comments

Comments
 (0)