Socket
Socket
Sign inDemoInstall

pm2

Package Overview
Dependencies
Maintainers
1
Versions
278
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pm2 - npm Package Compare versions

Comparing version 3.3.0 to 3.3.1

64

lib/API/Extra.js

@@ -171,2 +171,3 @@

}
/**

@@ -177,9 +178,27 @@ * Create PM2 memory snapshot

*/
CLI.prototype.snapshotPM2 = function(cb) {
CLI.prototype.profile = function(type, time, cb) {
var that = this;
var moment = require('moment');
var file = path.join(process.cwd(), moment().format('dd-HH:mm:ss') + '.heapsnapshot');
var cmd
that.Client.executeRemote('snapshotPM2', {
pwd : file
if (type == 'cpu') {
cmd = {
ext: '.cpuprofile',
action: 'profileCPU'
}
}
if (type == 'mem') {
cmd = {
ext: '.heapprofile',
action: 'profileMEM'
}
}
var file = path.join(process.cwd(), moment().format('dd-HH:mm:ss') + cmd.ext);
time = time || 10000
console.log(`Starting ${cmd.action} profiling for ${time}ms...`)
that.Client.executeRemote(cmd.action, {
pwd : file,
timeout: time
}, function(err) {

@@ -190,3 +209,3 @@ if (err) {

}
console.log('Heapdump in %s', file);
console.log(`Profile done in ${file}`)
return cb ? cb.apply(null, arguments) : that.exitCli(cst.SUCCESS_EXIT);

@@ -198,37 +217,2 @@ });

/**
* Create PM2 memory snapshot
* @method getVersion
* @callback cb
*/
CLI.prototype.profilePM2 = function(command, cb) {
var that = this;
var moment = require('moment');
var file = path.join(process.cwd(), moment().format('dd-HH:mm:ss') + '.cpuprofile');
if (command == 'start') {
that.Client.executeRemote('profileStart', {
}, function(err) {
if (err) {
console.error(err);
return that.exitCli(1);
}
console.log('CPU profiling started, type pm2 profile stop once finished');
return cb ? cb.apply(null, arguments) : that.exitCli(cst.SUCCESS_EXIT);
});
}
else if (command == 'stop') {
that.Client.executeRemote('profileStop', {
pwd : file
}, function(err) {
if (err) {
console.error(err);
return that.exitCli(1);
}
console.log('CPU profile in %s', file);
return cb ? cb.apply(null, arguments) : that.exitCli(cst.SUCCESS_EXIT);
});
}
};
/**
* Description

@@ -235,0 +219,0 @@ * @method sendLineToStdin

@@ -154,69 +154,59 @@ /**

var profiler;
try {
profiler = semver.satisfies(process.version, '>= 10.0.0') ? require('inspector') : null;
} catch(e) {
profiler = null;
}
/**
* Memory Snapshot
*/
function snapshotPM2(msg, cb) {
if (profiler == null) {
console.log('Heap snapshot is not available (node 10+)');
return cb(new Error('Heap snapshot is not available (node 10+)'));
}
function profile(type, msg, cb) {
if (semver.satisfies(process.version, '< 8'))
return cb(null, { error: 'Node.js is not on right version' })
const session = new profiler.Session()
session.connect()
session.post('HeapProfiler.enable')
var cmd
const chunks = []
session.on('HeapProfiler.addHeapSnapshotChunk', (data) => {
chunks.push(data.params.chunk)
})
if (type === 'cpu') {
cmd = {
enable: 'Profiler.enable',
start: 'Profiler.start',
stop: 'Profiler.stop',
disable: 'Profiler.disable'
}
}
if (type == 'mem') {
cmd = {
enable: 'HeapProfiler.enable',
start: 'HeapProfiler.startSampling',
stop: 'HeapProfiler.stopSampling',
disable: 'HeapProfiler.disable'
}
}
session.post('HeapProfiler.takeHeapSnapshot', {
reportProgress: false
}, (err, data) => {
if (err) return cb(err)
const inspector = require('inspector')
var session = new inspector.Session()
fs.writeFile(msg.pwd, chunks.join(''), function() {
session.post('Profiler.disable')
session.disconnect()
session.connect()
return cb(null, {file : msg.pwd});
});
})
}
var timeout = msg.timeout || 5000
function startProfilingPM2(msg, cb) {
if (profiler == null) {
console.log('v8-profiler is not available');
return cb(new Error('v8-profiler is not available'));
}
session.post(cmd.enable, (err, data) => {
if (err) return cb(null, { error: err.message || err })
profiler.startProfiling('cpu');
console.log(`Starting ${cmd.start}`)
session.post(cmd.start, (err, data) => {
if (err) return cb(null, { error: err.message || err })
process.nextTick(function() {
return cb(null, {msg : 'profiling started'});
});
}
setTimeout(() => {
session.post(cmd.stop, (err, data) => {
if (err) return cb(null, { error: err.message || err })
const profile = data.profile
function stopProfilingPM2(msg, cb) {
if (profiler == null) {
console.log('v8-profiler is not available');
return cb(new Error('v8-profiler is not available'));
}
console.log(`Stopping ${cmd.stop}`)
session.post(cmd.disable)
var profile1 = profiler.stopProfiling('cpu');
profile1.export()
.pipe(fs.createWriteStream(msg.pwd))
.on('finish', function() {
profile1.delete();
return cb(null, {file : msg.pwd});
});
fs.writeFile(msg.pwd, JSON.stringify(profile), (err) => {
if (err) return cb(null, { error: err.message || err })
return cb(null, { file : msg.pwd })
})
})
}, timeout)
})
})
}

@@ -226,5 +216,4 @@

killMe : that.close.bind(this),
snapshotPM2 : snapshotPM2,
profileStart : startProfilingPM2,
profileStop : stopProfilingPM2,
profileCPU : profile.bind(this, 'cpu'),
profileMEM : profile.bind(this, 'mem'),
prepare : God.prepare,

@@ -231,0 +220,0 @@ getMonitorData : God.getMonitorData,

{
"name": "pm2",
"preferGlobal": true,
"version": "3.3.0",
"version": "3.3.1",
"engines": {

@@ -6,0 +6,0 @@ "node": ">=4.0.0"

@@ -53,3 +53,3 @@ <div align="center">

*npm is a builtin CLI when you install Node.js - [Installing Node.js with NVM](https://blog.pm2.io/install-node-js-with-nvm/)*
*npm is a builtin CLI when you install Node.js - [Installing Node.js with NVM](https://blog.pm2.io/2018-02-19/Installing-Node-js-with-NVM/)*

@@ -56,0 +56,0 @@ ### Start an application

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc