Skip to content

Fix marker-only compare profiles #5130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/profile-logic/merge-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,19 @@ export function mergeProfilesForDiffing(

// We adjust the various times so that the 2 profiles are aligned at the
// start and the data is consistent.
const startTimeAdjustment = -thread.samples.time[0];
let startTimeAdjustment = 0;
if (thread.samples.length) {
startTimeAdjustment = -thread.samples.time[0];
} else if (thread.markers.length) {
for (const startTime of thread.markers.startTime) {
// Find the first marker startTime.
if (startTime !== null) {
startTimeAdjustment = -startTime;
break;
}
}
}

thread.samples = adjustTableTimestamps(thread.samples, startTimeAdjustment);
thread.markers = adjustMarkerTimestamps(
thread.markers,
Expand Down
34 changes: 33 additions & 1 deletion src/test/unit/merge-compare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '../fixtures/profiles/processed-profile';
import { markerSchemaForTests } from '../fixtures/profiles/marker-schema';
import { ensureExists } from 'firefox-profiler/utils/flow';

import { getTimeRangeIncludingAllThreads } from 'firefox-profiler/profile-logic/profile-data';
import type { Thread } from 'firefox-profiler/types';

describe('mergeProfilesForDiffing function', function () {
Expand Down Expand Up @@ -233,6 +233,38 @@ describe('mergeProfilesForDiffing function', function () {
expect(mergedProfileThreadB.nativeSymbols.libIndex).toEqual([1, 1]);
expect(mergedThread.nativeSymbols.libIndex).toEqual([0, 0, 1, 1]);
});

it('should use marker timing if there are no samples', () => {
const profiles = [
getProfileWithMarkers([
['Thread1 Marker1', 2],
['Thread1 Marker2', 3, 5],
['Thread1 Marker3', 6, 7],
]),

getProfileWithMarkers([
['Thread1 Marker1', 5],
['Thread1 Marker2', 6, 8],
['Thread1 Marker3', 10, 15],
]),
];

const profileState = stateFromLocation({
pathname: '/public/fakehash1/',
search: '?thread=0&v=3',
hash: '',
});

const { profile } = mergeProfilesForDiffing(profiles, [
profileState,
profileState,
]);

expect(getTimeRangeIncludingAllThreads(profile)).toEqual({
start: 0,
end: 11,
});
});
});

describe('mergeThreads function', function () {
Expand Down