Skip to content

Commit d12a3a0

Browse files
authored
Fix marker-only compare profiles (#5130)
1 parent ee2bc25 commit d12a3a0

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/profile-logic/merge-compare.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,19 @@ export function mergeProfilesForDiffing(
217217

218218
// We adjust the various times so that the 2 profiles are aligned at the
219219
// start and the data is consistent.
220-
const startTimeAdjustment = -thread.samples.time[0];
220+
let startTimeAdjustment = 0;
221+
if (thread.samples.length) {
222+
startTimeAdjustment = -thread.samples.time[0];
223+
} else if (thread.markers.length) {
224+
for (const startTime of thread.markers.startTime) {
225+
// Find the first marker startTime.
226+
if (startTime !== null) {
227+
startTimeAdjustment = -startTime;
228+
break;
229+
}
230+
}
231+
}
232+
221233
thread.samples = adjustTableTimestamps(thread.samples, startTimeAdjustment);
222234
thread.markers = adjustMarkerTimestamps(
223235
thread.markers,

src/test/unit/merge-compare.test.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '../fixtures/profiles/processed-profile';
1515
import { markerSchemaForTests } from '../fixtures/profiles/marker-schema';
1616
import { ensureExists } from 'firefox-profiler/utils/flow';
17-
17+
import { getTimeRangeIncludingAllThreads } from 'firefox-profiler/profile-logic/profile-data';
1818
import type { Thread } from 'firefox-profiler/types';
1919

2020
describe('mergeProfilesForDiffing function', function () {
@@ -233,6 +233,38 @@ describe('mergeProfilesForDiffing function', function () {
233233
expect(mergedProfileThreadB.nativeSymbols.libIndex).toEqual([1, 1]);
234234
expect(mergedThread.nativeSymbols.libIndex).toEqual([0, 0, 1, 1]);
235235
});
236+
237+
it('should use marker timing if there are no samples', () => {
238+
const profiles = [
239+
getProfileWithMarkers([
240+
['Thread1 Marker1', 2],
241+
['Thread1 Marker2', 3, 5],
242+
['Thread1 Marker3', 6, 7],
243+
]),
244+
245+
getProfileWithMarkers([
246+
['Thread1 Marker1', 5],
247+
['Thread1 Marker2', 6, 8],
248+
['Thread1 Marker3', 10, 15],
249+
]),
250+
];
251+
252+
const profileState = stateFromLocation({
253+
pathname: '/public/fakehash1/',
254+
search: '?thread=0&v=3',
255+
hash: '',
256+
});
257+
258+
const { profile } = mergeProfilesForDiffing(profiles, [
259+
profileState,
260+
profileState,
261+
]);
262+
263+
expect(getTimeRangeIncludingAllThreads(profile)).toEqual({
264+
start: 0,
265+
end: 11,
266+
});
267+
});
236268
});
237269

238270
describe('mergeThreads function', function () {

0 commit comments

Comments
 (0)