1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 const { Actor } = require("resource://devtools/shared/protocol.js");
10 } = require("resource://devtools/shared/specs/heap-snapshot-file.js");
12 loader.lazyRequireGetter(
15 "resource://devtools/shared/DevToolsUtils.js"
17 loader.lazyRequireGetter(
19 "HeapSnapshotFileUtils",
20 "resource://devtools/shared/heapsnapshot/HeapSnapshotFileUtils.js"
24 * The HeapSnapshotFileActor handles transferring heap snapshot files from the
25 * server to the client. This has to be a global actor in the parent process
26 * because child processes are sandboxed and do not have access to the file
29 exports.HeapSnapshotFileActor = class HeapSnapshotFileActor extends Actor {
31 super(conn, heapSnapshotFileSpec);
34 Services.appinfo.processType !== Services.appinfo.PROCESS_TYPE_DEFAULT
36 const err = new Error(
37 "Attempt to create a HeapSnapshotFileActor in a " +
38 "child process! The HeapSnapshotFileActor *MUST* " +
39 "be in the parent process!"
41 DevToolsUtils.reportException("HeapSnapshotFileActor's constructor", err);
46 * @see MemoryFront.prototype.transferHeapSnapshot
48 async transferHeapSnapshot(snapshotId) {
49 const snapshotFilePath =
50 HeapSnapshotFileUtils.getHeapSnapshotTempFilePath(snapshotId);
51 if (!snapshotFilePath) {
52 throw new Error(`No heap snapshot with id: ${snapshotId}`);
55 const streamPromise = DevToolsUtils.openFileStream(snapshotFilePath);
57 const { size } = await IOUtils.stat(snapshotFilePath);
58 const bulkPromise = this.conn.startBulkSend({
60 type: "heap-snapshot",
64 const [bulk, stream] = await Promise.all([bulkPromise, streamPromise]);
67 await bulk.copyFrom(stream);