Skip to content
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

Change page information structure to match the gecko side #2266

Merged
merged 4 commits into from Oct 9, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app-logic/constants.js
Expand Up @@ -5,10 +5,10 @@
// @flow

// The current version of the Gecko profile format.
export const GECKO_PROFILE_VERSION = 16;
export const GECKO_PROFILE_VERSION = 17;

// The current version of the "processed" profile format.
export const PROCESSED_PROFILE_VERSION = 24;
export const PROCESSED_PROFILE_VERSION = 25;

// The following are the margin sizes for the left and right of the timeline. Independent
// components need to share these values.
Expand Down
8 changes: 3 additions & 5 deletions src/components/timeline/VerticalIndicators.js
Expand Up @@ -80,12 +80,10 @@ class VerticalIndicatorsImpl extends React.PureComponent<Props> {
data.type === 'tracing' &&
data.category === 'Navigation'
) {
const docshellId = data.docShellId;
const historyId = data.docshellHistoryId;
if (docshellId) {
const innerWindowID = data.innerWindowID;
if (innerWindowID) {
const page = pages.find(
page =>
page.docshellId === docshellId && page.historyId === historyId
page => page.innerWindowID === innerWindowID
);
if (page) {
url = (
Expand Down
9 changes: 3 additions & 6 deletions src/components/tooltip/Marker.js
Expand Up @@ -663,15 +663,12 @@ class MarkerTooltipContents extends React.PureComponent<Props> {
_getUrl = (marker: Marker): string | null => {
const { pages } = this.props;

if (!(pages && marker.data && marker.data.docShellId)) {
if (!(pages && marker.data && marker.data.innerWindowID)) {
return null;
}

const docshellId = marker.data.docShellId;
const historyId = marker.data.docshellHistoryId;
const page = pages.find(
page => page.docshellId === docshellId && page.historyId === historyId
);
const innerWindowID = marker.data.innerWindowID;
const page = pages.find(page => page.innerWindowID === innerWindowID);
return page ? page.url : null;
};

Expand Down
93 changes: 93 additions & 0 deletions src/profile-logic/gecko-profile-versioning.js
Expand Up @@ -710,5 +710,98 @@ const _upgraders = {
}
addMarkerCategoriesRecursively(profile);
},
[17]: profile => {
// Previously, we had DocShell ID and DocShell History ID in the page object
// to identify a specific page. We changed these IDs in the gecko side to
// Browsing Context ID and Inner Window ID. Inner Window ID is enough to
// identify a specific frame now. We were keeping two field in marker
// payloads, but now we are only keeping innerWindowID. Browsing Context IDs
// are necessary to identify which frame belongs to which tab. Browsing
// Contexts doesn't change after a navigation.
let browsingContextID = 1;
let innerWindowID = 1;
function convertToVersion17Recursive(p) {
if (p.pages && p.pages.length > 0) {
// It's not possible to have a marker belongs to a different DocShell in
// different processes currently(pre-fission). It's not necessary to put
// those maps outside of the function.
const oldKeysToNewKey: Map<string, number> = new Map();
const docShellIDtoBrowsingContextID: Map<string, number> = new Map();

for (const page of p.pages) {
// Constructing our old keys to new key map so we can use it for markers.
oldKeysToNewKey.set(
`d${page.docshellId}h${page.historyId}`,
innerWindowID
);

// There are multiple pages with same DocShell IDs. We are checking to
// see if we assigned a Browsing Context ID to that DocShell ID
// before. Otherwise assigning one.
let currentBrowsingContextID = docShellIDtoBrowsingContextID.get(
page.docshellId
);
if (!currentBrowsingContextID) {
currentBrowsingContextID = browsingContextID++;
docShellIDtoBrowsingContextID.set(
page.docshellId,
currentBrowsingContextID
);
}

// Putting DocShell ID to this field. It fully doesn't correspond to a
// Browsing Context ID but that's the closest we have right now.
page.browsingContextID = currentBrowsingContextID;
// Putting a unique Inner Window ID to each page.
page.innerWindowID = innerWindowID;
// This information is new. We had isSubFrame field but that's not
// useful for us to determine the embedders. Therefore setting older
// pages to 0 which means null.
page.embedderInnerWindowID = 0;
canova marked this conversation as resolved.
Show resolved Hide resolved

innerWindowID++;
delete page.docshellId;
delete page.historyId;
delete page.isSubFrame;
}

for (const thread of p.threads) {
const { markers } = thread;
const dataIndex = markers.schema.data;
for (let i = 0; i < thread.markers.data.length; i++) {
const markerData = thread.markers.data[i];
const payload = markerData[dataIndex];

if (
payload &&
payload.docShellId !== undefined &&
payload.docshellHistoryId !== undefined
) {
const newKey = oldKeysToNewKey.get(
`d${payload.docShellId}h${payload.docshellHistoryId}`
);
if (newKey === undefined) {
console.error(
'No page found with given docShellId and historyId'
);
} else {
// We don't need to add the browsingContextID here because we
// only need innerWindowID since it's unique for each page.
payload.innerWindowID = newKey;
}

delete payload.docShellId;
delete payload.docshellHistoryId;
}
}
}
}

for (const subprocessProfile of p.processes) {
convertToVersion17Recursive(subprocessProfile);
}
}
convertToVersion17Recursive(profile);
},
};
/* eslint-enable no-useless-computed-key */
80 changes: 80 additions & 0 deletions src/profile-logic/processed-profile-versioning.js
Expand Up @@ -1058,5 +1058,85 @@ const _upgraders = {
}
}
},
[25]: profile => {
// Previously, we had DocShell ID and DocShell History ID in the page object
// to identify a specific page. We changed these IDs in the gecko side to
// Browsing Context ID and Inner Window ID. Inner Window ID is enough to
// identify a specific frame now. We were keeping two field in marker
// payloads, but now we are only keeping innerWindowID. Browsing Context IDs
// are necessary to identify which frame belongs to which tab. Browsing
// Contexts doesn't change after a navigation.
if (profile.pages && profile.pages.length > 0) {
const oldKeysToNewKey: Map<string, number> = new Map();
const docShellIDtoBrowsingContextID: Map<string, number> = new Map();
let browsingContextID = 1;
let innerWindowID = 1;

for (const page of profile.pages) {
// Constructing our old keys to new key map so we can use it for markers.
oldKeysToNewKey.set(
`d${page.docshellId}h${page.historyId}`,
innerWindowID
);

// There are multiple pages with same DocShell IDs. We are checking to
// see if we assigned a Browsing Context ID to that DocShell ID
// before. Otherwise assigning one.
let currentBrowsingContextID = docShellIDtoBrowsingContextID.get(
page.docshellId
);
if (!currentBrowsingContextID) {
currentBrowsingContextID = browsingContextID++;
docShellIDtoBrowsingContextID.set(
page.docshellId,
currentBrowsingContextID
);
}

// Putting DocShell ID to this field. It fully doesn't correspond to a
// Browsing Context ID but that's the closest we have right now.
page.browsingContextID = currentBrowsingContextID;
// Putting a unique Inner Window ID to each page.
page.innerWindowID = innerWindowID;
// This information is new. We had isSubFrame field but that's not
// useful for us to determine the embedders. Therefore setting older
// pages to 0 which means null.
page.embedderInnerWindowID = 0;

innerWindowID++;
delete page.docshellId;
delete page.historyId;
delete page.isSubFrame;
}

for (const thread of profile.threads) {
const { markers } = thread;
markers.data = markers.data.map(data => {
if (
data &&
data.docShellId !== undefined &&
data.docshellHistoryId !== undefined
) {
const newKey = oldKeysToNewKey.get(
`d${data.docShellId}h${data.docshellHistoryId}`
);
if (newKey === undefined) {
console.error(
'No page found with given docShellId and historyId'
);
} else {
// We don't need to add the browsingContextID here because we only
// need innerWindowID since it's unique for each page.
data.innerWindowID = newKey;
}

delete data.docShellId;
delete data.docshellHistoryId;
}
return data;
});
}
}
},
};
/* eslint-enable no-useless-computed-key */
13 changes: 6 additions & 7 deletions src/test/components/TooltipMarker.test.js
Expand Up @@ -53,14 +53,14 @@ describe('TooltipMarker', function() {

// Connect a page to one of the markers so that we render a URL in
// its tooltip.
const docShellId = '{c03a6ebd-2430-7949-b25b-95ba9776bdbf}';
const docshellHistoryId = 1;
const browsingContextID = 123123;
const innerWindowID = 1;
profile.pages = [
{
docshellId: docShellId,
historyId: docshellHistoryId,
browsingContextID: browsingContextID,
innerWindowID: innerWindowID,
url: 'https://developer.mozilla.org/en-US/',
isSubFrame: false,
embedderInnerWindowID: 0,
},
];
profile.threads[0].name = 'Main Thread';
Expand All @@ -77,8 +77,7 @@ describe('TooltipMarker', function() {
eventType: 'commandupdate',
interval: 'start',
phase: 2,
docShellId,
docshellHistoryId,
innerWindowID: innerWindowID,
},
],
[
Expand Down
4 changes: 2 additions & 2 deletions src/test/components/__snapshots__/MenuButtons.test.js.snap
Expand Up @@ -62,7 +62,7 @@ exports[`app/MenuButtons <MenuButtonsMetaInfo> matches the snapshot 1`] = `
>
Profile Version:
</span>
24
25
</div>
</div>
<h2
Expand Down Expand Up @@ -386,7 +386,7 @@ exports[`app/MenuButtons <MenuButtonsMetaInfo> with no statistics object should
>
Profile Version:
</span>
24
25
</div>
</div>
<h2
Expand Down
6 changes: 3 additions & 3 deletions src/test/fixtures/profiles/gecko-profile.js
Expand Up @@ -85,10 +85,10 @@ export function createGeckoSubprocessProfile(
libs: [contentProcessBinary, ...parentProfile.libs.slice(1)], // libs are stringified in the Gecko profile
pages: [
{
docshellId: '{e18794dd-3960-3543-b101-e5ed287ab617}',
historyId: 1,
browsingContextID: 123123,
innerWindowID: 1,
url: 'https://github.com/rustwasm/wasm-bindgen/issues/5',
isSubFrame: false,
embedderInnerWindowID: 0,
},
],
threads: [
Expand Down
16 changes: 7 additions & 9 deletions src/test/fixtures/profiles/processed-profile.js
Expand Up @@ -591,15 +591,15 @@ export function getNetworkTrackProfile() {
);
const profile = getProfileWithMarkers([].concat(...arrayOfNetworkMarkers));

const docShellId = '{c03a6ebd-2430-7949-b25b-95ba9776bdbf}';
const docshellHistoryId = 1;
const browsingContextID = 123123;
const innerWindowID = 1;

profile.pages = [
{
docshellId: docShellId,
historyId: docshellHistoryId,
browsingContextID: browsingContextID,
innerWindowID: innerWindowID,
url: 'https://developer.mozilla.org/en-US/',
isSubFrame: false,
embedderInnerWindowID: 0,
},
];

Expand All @@ -609,16 +609,14 @@ export function getNetworkTrackProfile() {
type: 'tracing',
category: 'Navigation',
eventType: 'load',
docShellId,
docshellHistoryId,
innerWindowID: innerWindowID,
};

const domContentLoadedBase = {
type: 'tracing',
category: 'Navigation',
interval: 'start',
docShellId,
docshellHistoryId,
innerWindowID: innerWindowID,
};

addMarkersToThreadWithCorrespondingSamples(thread, [
Expand Down