Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Profiler.prototype.createSnapshot = function(reason) {
const timestamp = moment().unix().toString();
const path = `${this.heapshotDir}/${this.serviceName}-heap-${timestamp}.heapsnapshot`;
const snapshot = v8Profiler.takeSnapshot();
const done = (err, path) => {
if (err) {
return this.agent.logger.error(err);
}
this.report(path, reason);
};
process.send(JSON.stringify({ msg: 'pause_monitoring' }));
snapshot.export()
.pipe(fs.createWriteStream(path))
.on('finish', () => {
snapshot.delete();
setTimeout(() => {
process.send(JSON.stringify({ msg: 'resume_monitoring' }));