@nitedani/inspector-api
Version:
A simple node module to access V8 inspector + some tools to export and read the data.
78 lines (77 loc) • 2.94 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils = __importStar(require("./utils"));
const stream_1 = require("stream");
class Heap {
session;
constructor(session) {
this.session = session;
}
async enable() {
await utils.invokeFunction(this.session, "HeapProfiler.enable");
}
async disable() {
await utils.invokeFunction(this.session, "HeapProfiler.disable");
}
async startSampling() {
await utils.invokeFunction(this.session, "HeapProfiler.startSampling");
}
async stopSampling() {
return utils.invokeStop("HeapProfiler.stopSampling", this.session);
}
async startTimeline() {
await utils.invokeFunction(this.session, "HeapProfiler.startTrackingHeapObjects", { trackAllocations: true });
}
stopTimeline() {
const stream = new stream_1.PassThrough();
const getChunk = (m) => {
stream.push(m.params.chunk);
};
this.session.on("HeapProfiler.addHeapSnapshotChunk", getChunk);
this.session.post("HeapProfiler.stopTrackingHeapObjects", (err) => {
this.session.removeListener("HeapProfiler.addHeapSnapshotChunk", getChunk);
stream.emit("finish");
stream.emit("end");
stream.end();
if (err)
throw err;
});
return stream;
}
takeSnapshot() {
const stream = new stream_1.PassThrough();
const getChunk = (m) => {
stream.push(m.params.chunk);
};
this.session.on("HeapProfiler.addHeapSnapshotChunk", getChunk);
this.session.post("HeapProfiler.takeHeapSnapshot", (err, _r) => {
this.session.removeListener("HeapProfiler.addHeapSnapshotChunk", getChunk);
stream.emit("finish");
stream.emit("end");
stream.end();
if (err)
throw err;
});
return stream;
}
}
exports.default = Heap;