Merge remote-tracking branch 'origin/api-v1.5.5' into dev
This commit is contained in:
commit
5fdc9c09b2
3 changed files with 38 additions and 21 deletions
|
|
@ -51,8 +51,7 @@ peerServer.on('disconnect', peerDisconnect);
|
|||
peerServer.on('error', peerError);
|
||||
app.use('/', peerServer);
|
||||
app.enable('trust proxy');
|
||||
app.get('/heapdump', dumps.sendHeapSnapshot);
|
||||
app.get('/heapdump/save', dumps.saveHeapSnapshot);
|
||||
app.use('/heapdump', dumps.router);
|
||||
|
||||
if (process.env.uws !== "true") {
|
||||
var wsapp = express();
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ app.use('/sourcemaps', sourcemapsReaderServer);
|
|||
app.use('/assist', peerRouter);
|
||||
wsapp.use('/assist', socket.wsRouter);
|
||||
|
||||
app.get('/heapdump', dumps.sendHeapSnapshot);
|
||||
app.get('/heapdump/save', dumps.saveHeapSnapshot);
|
||||
app.use('/heapdump', dumps.router);
|
||||
|
||||
const server = app.listen(PORT, HOST, () => {
|
||||
console.log(`App listening on http://${HOST}:${PORT}`);
|
||||
|
|
|
|||
|
|
@ -1,20 +1,35 @@
|
|||
const fs = require('fs');
|
||||
const v8 = require('v8');
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const location = '/tmp/';
|
||||
let creationStatus = null;
|
||||
let fileName = null;
|
||||
|
||||
async function createHeapSnapshot() {
|
||||
const fileName = `${Date.now()}.heapsnapshot`;
|
||||
if (creationStatus) {
|
||||
return console.log(`In progress ${fileName}`);
|
||||
}
|
||||
if (fileName === null) {
|
||||
fileName = `${Date.now()}.heapsnapshot`;
|
||||
}
|
||||
console.log(`Creating ${fileName}`);
|
||||
await fs.promises.writeFile(
|
||||
location + fileName,
|
||||
v8.getHeapSnapshot()
|
||||
);
|
||||
return fileName;
|
||||
console.log(`Created ${fileName}`);
|
||||
creationStatus = true;
|
||||
}
|
||||
|
||||
|
||||
async function sendHeapSnapshot(req, res) {
|
||||
const fileName = await createHeapSnapshot();
|
||||
async function downloadHeapSnapshot(req, res) {
|
||||
if (creationStatus === null) {
|
||||
return res.end("should call /new first");
|
||||
} else if (!creationStatus) {
|
||||
return res.end("should wait for done status");
|
||||
}
|
||||
res.download(location + fileName, function (err) {
|
||||
try {
|
||||
fs.unlinkSync(location + fileName)
|
||||
|
|
@ -25,20 +40,24 @@ async function sendHeapSnapshot(req, res) {
|
|||
});
|
||||
}
|
||||
|
||||
process.on('USR2', () => {
|
||||
console.info('USR2 signal received.');
|
||||
});
|
||||
|
||||
async function saveHeapSnapshot(req, res) {
|
||||
const fileName = await createHeapSnapshot();
|
||||
const path = location + fileName;
|
||||
console.log(`Heapdump saved to ${path}`)
|
||||
function getHeapSnapshotStatus(req, res) {
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify({path}));
|
||||
res.end(JSON.stringify({path: location + fileName, 'done': creationStatus}));
|
||||
}
|
||||
|
||||
process.on('USR2', () => {
|
||||
console.info('USR2 signal received.');
|
||||
});
|
||||
module.exports = {sendHeapSnapshot, saveHeapSnapshot}
|
||||
function createNewHeapSnapshot(req, res) {
|
||||
creationStatus = false;
|
||||
fileName = `${Date.now()}.heapsnapshot`;
|
||||
setTimeout(() => {
|
||||
createHeapSnapshot()
|
||||
}, 0);
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify({path: location + fileName, 'done': creationStatus}));
|
||||
}
|
||||
|
||||
router.get('/status', getHeapSnapshotStatus);
|
||||
router.get(`/new`, createNewHeapSnapshot);
|
||||
router.get(`/download`, downloadHeapSnapshot);
|
||||
module.exports = {router}
|
||||
Loading…
Add table
Reference in a new issue