⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Merged
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
96 changes: 62 additions & 34 deletions src/profile-logic/merge-compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import type {
MarkerIndex,
Milliseconds,
Tid,
RawProfileSharedData,
} from 'firefox-profiler/types';

/**
Expand Down Expand Up @@ -134,40 +135,23 @@ export function mergeProfilesForDiffing(
);
}

// First let's merge categories. We'll use the resulting maps when
// handling the thread data later.
// First, let's merge profile.meta.categories, profile.libs, and profile.shared.
const {
categories: newCategories,
translationMaps: translationMapsForCategories,
} = mergeCategories(profiles.map((profile) => profile.meta.categories));
libs: newLibs,
shared: newShared,
translationMapsForCategories,
translationMapsForLibs,
translationMapsForStrings,
translationMapsForSources,
} = mergeSharedData(profiles);
resultProfile.meta.categories = newCategories;

const {
stringArray: newStringArray,
translationMaps: translationMapForStrings,
} = mergeStringArrays(profiles.map((profile) => profile.shared.stringArray));

// Then merge sources.
const { sources: newSources, translationMaps: translationMapForSources } =
mergeSources(
profiles.map((profile) => profile.shared.sources ?? null),
translationMapForStrings
);

// Then merge libs.
const { libs: newLibs, translationMaps: translationMapsForLibs } = mergeLibs(
profiles.map((profile) => profile.libs)
);
resultProfile.libs = newLibs;

resultProfile.shared = {
stringArray: newStringArray,
sources: newSources,
};
resultProfile.shared = newShared;

// Then we loop over all profiles and do the necessary changes according
// to the states we computed earlier.
const transformStacks: any = {};
const transformStacks: TransformStacksPerThread = {};
const implementationFilters: ImplementationFilter[] = [];
// These may be needed for filtering markers.
let ipcCorrelations;
Expand Down Expand Up @@ -203,22 +187,22 @@ export function mergeProfilesForDiffing(
...thread.funcTable,
name: adjustStringIndexes(
thread.funcTable.name,
translationMapForStrings[i]
translationMapsForStrings[i]
),
source: adjustNullableSourceIndexes(
thread.funcTable.source,
translationMapForSources[i]
translationMapsForSources[i]
),
};
thread.resourceTable = {
...thread.resourceTable,
name: adjustStringIndexes(
thread.resourceTable.name,
translationMapForStrings[i]
translationMapsForStrings[i]
),
host: adjustNullableStringIndexes(
thread.resourceTable.host,
translationMapForStrings[i]
translationMapsForStrings[i]
),
lib: adjustResourceTableLibs(
thread.resourceTable.lib,
Expand All @@ -229,7 +213,7 @@ export function mergeProfilesForDiffing(
...thread.nativeSymbols,
name: adjustStringIndexes(
thread.nativeSymbols.name,
translationMapForStrings[i]
translationMapsForStrings[i]
),
libIndex: adjustNativeSymbolLibs(
thread.nativeSymbols.libIndex,
Expand All @@ -240,11 +224,11 @@ export function mergeProfilesForDiffing(
...thread.markers,
name: adjustStringIndexes(
thread.markers.name,
translationMapForStrings[i]
translationMapsForStrings[i]
),
data: adjustMarkerDataStringIndexes(
thread.markers.data,
translationMapForStrings[i],
translationMapsForStrings[i],
stringIndexMarkerFieldsByDataType
),
};
Expand Down Expand Up @@ -475,6 +459,50 @@ function mergeCategories(categoriesPerProfile: Array<CategoryList | void>): {
return { categories: newCategories, translationMaps };
}

export function mergeSharedData(profiles: Profile[]): {
categories: CategoryList;
libs: Lib[];
shared: RawProfileSharedData;
translationMapsForCategories: TranslationMapForCategories[];
translationMapsForLibs: TranslationMapForLibs[];
translationMapsForStrings: TranslationMapForStrings[];
translationMapsForSources: TranslationMapForSources[];
} {
const {
categories: newCategories,
translationMaps: translationMapsForCategories,
} = mergeCategories(profiles.map((profile) => profile.meta.categories));

const {
stringArray: newStringArray,
translationMaps: translationMapsForStrings,
} = mergeStringArrays(profiles.map((profile) => profile.shared.stringArray));

const { libs: newLibs, translationMaps: translationMapsForLibs } = mergeLibs(
profiles.map((profile) => profile.libs)
);

const { sources: newSources, translationMaps: translationMapsForSources } =
mergeSources(
profiles.map((profile) => profile.shared.sources ?? null),
translationMapsForStrings
);
const newShared: RawProfileSharedData = {
stringArray: newStringArray,
sources: newSources,
};

return {
categories: newCategories,
libs: newLibs,
shared: newShared,
translationMapsForCategories,
translationMapsForLibs,
translationMapsForStrings,
translationMapsForSources,
};
}

function mergeStringArrays(stringArraysPerProfile: Array<string[]>): {
stringArray: string[];
translationMaps: TranslationMapForStrings[];
Expand Down