Skip to content

Commit

Permalink
Bug 1625309 - Remove the frame script and instead use the WebChannel …
Browse files Browse the repository at this point in the history
…to expose the profile and symbolication. r=julienw

Differential Revision: https://phabricator.services.mozilla.com/D121933
  • Loading branch information
mstange committed Nov 16, 2021
1 parent a8f1947 commit 7bc4df8
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 337 deletions.
1 change: 0 additions & 1 deletion devtools/client/jar.mn
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ devtools.jar:
# Perfomance
content/performance/index.xhtml (performance/index.xhtml)
content/performance-new/index.xhtml (performance-new/index.xhtml)
content/performance-new/frame-script.js (performance-new/frame-script.js)

# Memory
content/memory/index.xhtml (memory/index.xhtml)
Expand Down
17 changes: 0 additions & 17 deletions devtools/client/performance-new/@types/frame-script.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion devtools/client/performance-new/@types/gecko.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ declare namespace MockedExports {
* Then add the file path to the KnownModules above.
*/
import: <S extends keyof KnownModules>(module: S) => KnownModules[S];
createObjectIn: (content: ContentWindow) => object;
exportFunction: (fn: Function, scope: object, options?: object) => void;
cloneInto: (value: any, scope: object, options?: object) => void;
isInAutomation: boolean;
Expand Down
119 changes: 99 additions & 20 deletions devtools/client/performance-new/@types/perf.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,26 +452,85 @@ export interface Presets {
[presetName: string]: PresetDefinition;
}

export type MessageFromFrontend =
| {
type: "STATUS_QUERY";
requestId: number;
}
| {
type: "ENABLE_MENU_BUTTON";
requestId: number;
};
// Should be kept in sync with the types in https://github.com/firefox-devtools/profiler/blob/main/src/app-logic/web-channel.js .
// Compatibility is handled as follows:
// - The front-end needs to worry about compatibility and handle older browser versions.
// - The browser can require the latest front-end version and does not need to keep any legacy functionality for older front-end versions.

type MessageFromFrontend = {
requestId: number;
} & RequestFromFrontend;

export type RequestFromFrontend =
| StatusQueryRequest
| EnableMenuButtonRequest
| GetProfileRequest
| GetSymbolTableRequest
| QuerySymbolicationApiRequest;

type StatusQueryRequest = { type: "STATUS_QUERY" };
type EnableMenuButtonRequest = { type: "ENABLE_MENU_BUTTON" };
type GetProfileRequest = { type: "GET_PROFILE" };
type GetSymbolTableRequest = {
type: "GET_SYMBOL_TABLE";
debugName: string;
breakpadId: string;
};
type QuerySymbolicationApiRequest = {
type: "QUERY_SYMBOLICATION_API";
path: string;
requestJson: string;
};

export type MessageToFrontend =
| {
type: "STATUS_RESPONSE";
menuButtonIsEnabled: boolean;
requestId: number;
}
| {
type: "ENABLE_MENU_BUTTON_DONE";
requestId: number;
};
export type MessageToFrontend<R> =
| OutOfBandErrorMessageToFrontend
| ErrorResponseMessageToFrontend
| SuccessResponseMessageToFrontend<R>;

type OutOfBandErrorMessageToFrontend = {
errno: number;
error: string;
};

type ErrorResponseMessageToFrontend = {
type: "ERROR_RESPONSE";
requestId: number;
error: string;
};

type SuccessResponseMessageToFrontend<R> = {
type: "SUCCESS_RESPONSE";
requestId: number;
response: R;
};

export type ResponseToFrontend =
| StatusQueryResponse
| EnableMenuButtonResponse
| GetProfileResponse
| GetSymbolTableResponse
| QuerySymbolicationApiResponse;

type StatusQueryResponse = {
menuButtonIsEnabled: boolean;
// The version indicates which message types are supported by the browser.
// No version:
// Shipped in Firefox 76.
// Supports the following message types:
// - STATUS_QUERY
// - ENABLE_MENU_BUTTON
// Version 1:
// Shipped in Firefox 93.
// Adds support for the following message types:
// - GET_PROFILE
// - GET_SYMBOL_TABLE
// - QUERY_SYMBOLICATION_API
version: number;
};
type EnableMenuButtonResponse = void;
type GetProfileResponse = ArrayBuffer | MinimallyTypedGeckoProfile;
type GetSymbolTableResponse = SymbolTableAsTuple;
type QuerySymbolicationApiResponse = string;

/**
* This represents an event channel that can talk to a content page on the web.
Expand All @@ -484,7 +543,7 @@ export type MessageToFrontend =
export class ProfilerWebChannel {
constructor(id: string, url: MockedExports.nsIURI);
send: (
message: MessageToFrontend,
message: MessageToFrontend<ResponseToFrontend>,
target: MockedExports.WebChannelTarget
) => void;
listen: (
Expand All @@ -496,6 +555,26 @@ export class ProfilerWebChannel {
) => void;
}

/**
* The per-tab information that is stored when a new profile is captured
* and a profiler tab is opened, to serve the correct profile to the tab
* that sends the WebChannel message.
*/
export type ProfilerBrowserInfo = {
profileCaptureResult: ProfileCaptureResult;
symbolicationService: SymbolicationService;
};

export type ProfileCaptureResult =
| {
type: "SUCCESS";
profile: MinimallyTypedGeckoProfile | ArrayBuffer;
}
| {
type: "ERROR";
error: Error;
};

/**
* Describes all of the profiling features that can be turned on and
* off in about:profiling.
Expand Down
53 changes: 5 additions & 48 deletions devtools/client/performance-new/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ const lazy = createLazyLoaders({
),
});

const TRANSFER_EVENT = "devtools:perf-html-transfer-profile";
const SYMBOL_TABLE_REQUEST_EVENT = "devtools:perf-html-request-symbol-table";
const SYMBOL_TABLE_RESPONSE_EVENT = "devtools:perf-html-reply-symbol-table";

/** @type {PerformancePref["UIBaseUrl"]} */
const UI_BASE_URL_PREF = "devtools.performance.recording.ui-base-url";
/** @type {PerformancePref["UIBaseUrlPathPref"]} */
Expand All @@ -58,23 +54,13 @@ const UI_BASE_URL_PATH_DEFAULT = "/from-addon";
/**
* Once a profile is received from the actor, it needs to be opened up in
* profiler.firefox.com to be analyzed. This function opens up profiler.firefox.com
* into a new browser tab, and injects the profile via a frame script.
*
* @param {MinimallyTypedGeckoProfile | ArrayBuffer | {}} profile - The Gecko profile.
* into a new browser tab.
* @param {ProfilerViewMode | undefined} profilerViewMode - View mode for the Firefox Profiler
* front-end timeline. While opening the url, we should append a query string
* if a view other than "full" needs to be displayed.
* @param {SymbolicationService} symbolicationService - An object which implements the
* SymbolicationService interface, whose getSymbolTable method will be invoked
* when profiler.firefox.com sends SYMBOL_TABLE_REQUEST_EVENT messages to us. This
* method should obtain a symbol table for the requested binary and resolve the
* returned promise with it.
* @returns {MockedExports.Browser} The browser for the opened tab.
*/
function openProfilerAndDisplayProfile(
profile,
profilerViewMode,
symbolicationService
) {
function openProfilerTab(profilerViewMode) {
const Services = lazy.Services();
// Find the most recently used window, as the DevTools client could be in a variety
// of hosts.
Expand Down Expand Up @@ -115,36 +101,7 @@ function openProfilerAndDisplayProfile(
}
);
browser.selectedTab = tab;
const mm = tab.linkedBrowser.messageManager;
mm.loadFrameScript(
"chrome://devtools/content/performance-new/frame-script.js",
false
);
mm.sendAsyncMessage(TRANSFER_EVENT, profile);
mm.addMessageListener(SYMBOL_TABLE_REQUEST_EVENT, e => {
const { debugName, breakpadId } = e.data;
symbolicationService.getSymbolTable(debugName, breakpadId).then(
result => {
const [addr, index, buffer] = result;
mm.sendAsyncMessage(SYMBOL_TABLE_RESPONSE_EVENT, {
status: "success",
debugName,
breakpadId,
result: [addr, index, buffer],
});
},
error => {
// Re-wrap the error object into an object that is Structured Clone-able.
const { name, message, lineNumber, fileName } = error;
mm.sendAsyncMessage(SYMBOL_TABLE_RESPONSE_EVENT, {
status: "error",
debugName,
breakpadId,
error: { name, message, lineNumber, fileName },
});
}
);
});
return tab.linkedBrowser;
}

/**
Expand Down Expand Up @@ -221,7 +178,7 @@ function openFilePickerForObjdir(window, objdirs, changeObjdirs) {
}

module.exports = {
openProfilerAndDisplayProfile,
openProfilerTab,
sharedLibrariesFromProfile,
restartBrowserWithEnvironmentVariable,
getEnvironmentVariable,
Expand Down
Loading

0 comments on commit 7bc4df8

Please sign in to comment.