forked from mirrors/gecko-dev
This changeset is the result of running `hg mv devtools/shared/fronts/ devtools/client` The necessary adaptations (renaming and moz.build changes) have been split in other patches for the review. Differential Revision: https://phabricator.services.mozilla.com/D67603 --HG-- rename : devtools/shared/fronts/accessibility.js => devtools/client/fronts/accessibility.js rename : devtools/shared/fronts/addon/addons.js => devtools/client/fronts/addon/addons.js rename : devtools/shared/fronts/addon/moz.build => devtools/client/fronts/addon/moz.build rename : devtools/shared/fronts/addon/webextension-inspected-window.js => devtools/client/fronts/addon/webextension-inspected-window.js rename : devtools/shared/fronts/animation.js => devtools/client/fronts/animation.js rename : devtools/shared/fronts/array-buffer.js => devtools/client/fronts/array-buffer.js rename : devtools/shared/fronts/changes.js => devtools/client/fronts/changes.js rename : devtools/shared/fronts/content-viewer.js => devtools/client/fronts/content-viewer.js rename : devtools/shared/fronts/css-properties.js => devtools/client/fronts/css-properties.js rename : devtools/shared/fronts/descriptors/frame.js => devtools/client/fronts/descriptors/frame.js rename : devtools/shared/fronts/descriptors/moz.build => devtools/client/fronts/descriptors/moz.build rename : devtools/shared/fronts/descriptors/process.js => devtools/client/fronts/descriptors/process.js rename : devtools/shared/fronts/descriptors/tab.js => devtools/client/fronts/descriptors/tab.js rename : devtools/shared/fronts/descriptors/webextension.js => devtools/client/fronts/descriptors/webextension.js rename : devtools/shared/fronts/device.js => devtools/client/fronts/device.js rename : devtools/shared/fronts/environment.js => devtools/client/fronts/environment.js rename : devtools/shared/fronts/frame.js => devtools/client/fronts/frame.js rename : devtools/shared/fronts/framerate.js => devtools/client/fronts/framerate.js rename : devtools/shared/fronts/highlighters.js => devtools/client/fronts/highlighters.js rename : devtools/shared/fronts/inspector.js => devtools/client/fronts/inspector.js rename : devtools/shared/fronts/inspector/moz.build => devtools/client/fronts/inspector/moz.build rename : devtools/shared/fronts/inspector/rule-rewriter.js => devtools/client/fronts/inspector/rule-rewriter.js rename : devtools/shared/fronts/layout.js => devtools/client/fronts/layout.js rename : devtools/shared/fronts/manifest.js => devtools/client/fronts/manifest.js rename : devtools/shared/fronts/memory.js => devtools/client/fronts/memory.js rename : devtools/shared/fronts/moz.build => devtools/client/fronts/moz.build rename : devtools/shared/fronts/node.js => devtools/client/fronts/node.js rename : devtools/shared/fronts/object.js => devtools/client/fronts/object.js rename : devtools/shared/fronts/perf.js => devtools/client/fronts/perf.js rename : devtools/shared/fronts/performance-recording.js => devtools/client/fronts/performance-recording.js rename : devtools/shared/fronts/performance.js => devtools/client/fronts/performance.js rename : devtools/shared/fronts/preference.js => devtools/client/fronts/preference.js rename : devtools/shared/fronts/property-iterator.js => devtools/client/fronts/property-iterator.js rename : devtools/shared/fronts/reflow.js => devtools/client/fronts/reflow.js rename : devtools/shared/fronts/responsive.js => devtools/client/fronts/responsive.js rename : devtools/shared/fronts/root.js => devtools/client/fronts/root.js rename : devtools/shared/fronts/screenshot.js => devtools/client/fronts/screenshot.js rename : devtools/shared/fronts/source.js => devtools/client/fronts/source.js rename : devtools/shared/fronts/storage.js => devtools/client/fronts/storage.js rename : devtools/shared/fronts/string.js => devtools/client/fronts/string.js rename : devtools/shared/fronts/styles.js => devtools/client/fronts/styles.js rename : devtools/shared/fronts/stylesheets.js => devtools/client/fronts/stylesheets.js rename : devtools/shared/fronts/symbol-iterator.js => devtools/client/fronts/symbol-iterator.js rename : devtools/shared/fronts/targets/browsing-context.js => devtools/client/fronts/targets/browsing-context.js rename : devtools/shared/fronts/targets/content-process.js => devtools/client/fronts/targets/content-process.js rename : devtools/shared/fronts/targets/local-tab.js => devtools/client/fronts/targets/local-tab.js rename : devtools/shared/fronts/targets/moz.build => devtools/client/fronts/targets/moz.build rename : devtools/shared/fronts/targets/target-mixin.js => devtools/client/fronts/targets/target-mixin.js rename : devtools/shared/fronts/targets/worker.js => devtools/client/fronts/targets/worker.js rename : devtools/shared/fronts/thread.js => devtools/client/fronts/thread.js rename : devtools/shared/fronts/walker.js => devtools/client/fronts/walker.js rename : devtools/shared/fronts/webconsole.js => devtools/client/fronts/webconsole.js rename : devtools/shared/fronts/websocket.js => devtools/client/fronts/websocket.js rename : devtools/shared/fronts/worker/moz.build => devtools/client/fronts/worker/moz.build rename : devtools/shared/fronts/worker/push-subscription.js => devtools/client/fronts/worker/push-subscription.js rename : devtools/shared/fronts/worker/service-worker-registration.js => devtools/client/fronts/worker/service-worker-registration.js rename : devtools/shared/fronts/worker/service-worker.js => devtools/client/fronts/worker/service-worker.js extra : moz-landing-system : lando
117 lines
3.6 KiB
JavaScript
117 lines
3.6 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
const { memorySpec } = require("devtools/shared/specs/memory");
|
|
const {
|
|
FrontClassWithSpec,
|
|
registerFront,
|
|
} = require("devtools/shared/protocol");
|
|
|
|
loader.lazyRequireGetter(
|
|
this,
|
|
"FileUtils",
|
|
"resource://gre/modules/FileUtils.jsm",
|
|
true
|
|
);
|
|
loader.lazyRequireGetter(
|
|
this,
|
|
"HeapSnapshotFileUtils",
|
|
"devtools/shared/heapsnapshot/HeapSnapshotFileUtils"
|
|
);
|
|
|
|
class MemoryFront extends FrontClassWithSpec(memorySpec) {
|
|
constructor(client, targetFront, parentFront) {
|
|
super(client, targetFront, parentFront);
|
|
this._client = client;
|
|
this.heapSnapshotFileActorID = null;
|
|
|
|
// Attribute name from which to retrieve the actorID out of the target actor's form
|
|
this.formAttributeName = "memoryActor";
|
|
}
|
|
|
|
/**
|
|
* Save a heap snapshot, transfer it from the server to the client if the
|
|
* server and client do not share a file system, and return the local file
|
|
* path to the heap snapshot.
|
|
*
|
|
* Note that this is safe to call for actors inside sandoxed child processes,
|
|
* as we jump through the correct IPDL hoops.
|
|
*
|
|
* @params Boolean options.forceCopy
|
|
* Always force a bulk data copy of the saved heap snapshot, even when
|
|
* the server and client share a file system.
|
|
*
|
|
* @params {Object|undefined} options.boundaries
|
|
* The boundaries for the heap snapshot. See
|
|
* ChromeUtils.webidl for more details.
|
|
*
|
|
* @returns Promise<String>
|
|
*/
|
|
async saveHeapSnapshot(options = {}) {
|
|
const snapshotId = await super.saveHeapSnapshot(options.boundaries);
|
|
|
|
if (
|
|
!options.forceCopy &&
|
|
(await HeapSnapshotFileUtils.haveHeapSnapshotTempFile(snapshotId))
|
|
) {
|
|
return HeapSnapshotFileUtils.getHeapSnapshotTempFilePath(snapshotId);
|
|
}
|
|
|
|
return this.transferHeapSnapshot(snapshotId);
|
|
}
|
|
|
|
/**
|
|
* Given that we have taken a heap snapshot with the given id, transfer the
|
|
* heap snapshot file to the client. The path to the client's local file is
|
|
* returned.
|
|
*
|
|
* @param {String} snapshotId
|
|
*
|
|
* @returns Promise<String>
|
|
*/
|
|
async transferHeapSnapshot(snapshotId) {
|
|
if (!this.heapSnapshotFileActorID) {
|
|
const form = await this._client.mainRoot.rootForm;
|
|
this.heapSnapshotFileActorID = form.heapSnapshotFileActor;
|
|
}
|
|
|
|
try {
|
|
const request = this._client.request({
|
|
to: this.heapSnapshotFileActorID,
|
|
type: "transferHeapSnapshot",
|
|
snapshotId,
|
|
});
|
|
|
|
const outFilePath = HeapSnapshotFileUtils.getNewUniqueHeapSnapshotTempFilePath();
|
|
const outFile = new FileUtils.File(outFilePath);
|
|
const outFileStream = FileUtils.openSafeFileOutputStream(outFile);
|
|
|
|
// This request is a bulk request. That's why the result of the request is
|
|
// an object with the `copyTo` function that can transfer the data to
|
|
// another stream.
|
|
// See devtools/shared/transport/transport.js to know more about this mode.
|
|
const { copyTo } = await request;
|
|
await copyTo(outFileStream);
|
|
|
|
FileUtils.closeSafeFileOutputStream(outFileStream);
|
|
return outFilePath;
|
|
} catch (e) {
|
|
if (e.error) {
|
|
// This isn't a real error, rather this is a message coming from the
|
|
// server. So let's throw a real error instead.
|
|
throw new Error(
|
|
`The server's actor threw an error: (${e.error}) ${e.message}`
|
|
);
|
|
}
|
|
|
|
// Otherwise, rethrow the error
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
|
|
exports.MemoryFront = MemoryFront;
|
|
registerFront(MemoryFront);
|