summaryrefslogtreecommitdiffstats
path: root/devtools/server/actors/heap-snapshot-file.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/server/actors/heap-snapshot-file.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/server/actors/heap-snapshot-file.js')
-rw-r--r--devtools/server/actors/heap-snapshot-file.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/devtools/server/actors/heap-snapshot-file.js b/devtools/server/actors/heap-snapshot-file.js
new file mode 100644
index 000000000..545f2265d
--- /dev/null
+++ b/devtools/server/actors/heap-snapshot-file.js
@@ -0,0 +1,68 @@
+/* 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 protocol = require("devtools/shared/protocol");
+const { method, Arg } = protocol;
+const Services = require("Services");
+const { Task } = require("devtools/shared/task");
+
+const { heapSnapshotFileSpec } = require("devtools/shared/specs/heap-snapshot-file");
+
+loader.lazyRequireGetter(this, "DevToolsUtils",
+ "devtools/shared/DevToolsUtils");
+loader.lazyRequireGetter(this, "OS", "resource://gre/modules/osfile.jsm", true);
+loader.lazyRequireGetter(this, "HeapSnapshotFileUtils",
+ "devtools/shared/heapsnapshot/HeapSnapshotFileUtils");
+
+/**
+ * The HeapSnapshotFileActor handles transferring heap snapshot files from the
+ * server to the client. This has to be a global actor in the parent process
+ * because child processes are sandboxed and do not have access to the file
+ * system.
+ */
+exports.HeapSnapshotFileActor = protocol.ActorClassWithSpec(heapSnapshotFileSpec, {
+ initialize: function (conn, parent) {
+ if (Services.appinfo.processType !== Services.appinfo.PROCESS_TYPE_DEFAULT) {
+ const err = new Error("Attempt to create a HeapSnapshotFileActor in a " +
+ "child process! The HeapSnapshotFileActor *MUST* " +
+ "be in the parent process!");
+ DevToolsUtils.reportException(
+ "HeapSnapshotFileActor.prototype.initialize", err);
+ return;
+ }
+
+ protocol.Actor.prototype.initialize.call(this, conn, parent);
+ },
+
+ /**
+ * @see MemoryFront.prototype.transferHeapSnapshot
+ */
+ transferHeapSnapshot: Task.async(function* (snapshotId) {
+ const snapshotFilePath =
+ HeapSnapshotFileUtils.getHeapSnapshotTempFilePath(snapshotId);
+ if (!snapshotFilePath) {
+ throw new Error(`No heap snapshot with id: ${snapshotId}`);
+ }
+
+ const streamPromise = DevToolsUtils.openFileStream(snapshotFilePath);
+
+ const { size } = yield OS.File.stat(snapshotFilePath);
+ const bulkPromise = this.conn.startBulkSend({
+ actor: this.actorID,
+ type: "heap-snapshot",
+ length: size
+ });
+
+ const [bulk, stream] = yield Promise.all([bulkPromise, streamPromise]);
+
+ try {
+ yield bulk.copyFrom(stream);
+ } finally {
+ stream.close();
+ }
+ }),
+
+});