-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support finish profiling before process exit (#203)
- Loading branch information
Showing
10 changed files
with
319 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
const os = require('os'); | ||
const mm = require('mm'); | ||
const xprofiler = require('../../'); | ||
const utils = require('./utils'); | ||
|
||
if (process.env.XPROFILER_UNIT_TEST_TMP_HOMEDIR) { | ||
mm(os, 'homedir', () => process.env.XPROFILER_UNIT_TEST_TMP_HOMEDIR); | ||
} | ||
|
||
xprofiler(); | ||
|
||
process.send({ type: utils.clientConst.xprofilerDone }); | ||
|
||
setTimeout(() => { | ||
// empty exit | ||
}, 2000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
'use strict'; | ||
|
||
const os = require('os'); | ||
const mm = require('mm'); | ||
const xprofiler = require('../../'); | ||
const utils = require('./utils'); | ||
|
||
if (process.env.XPROFILER_UNIT_TEST_TMP_HOMEDIR) { | ||
mm(os, 'homedir', () => process.env.XPROFILER_UNIT_TEST_TMP_HOMEDIR); | ||
} | ||
|
||
xprofiler(); | ||
|
||
process.send({ type: utils.clientConst.xprofilerDone }); | ||
|
||
const array = []; | ||
|
||
setInterval(() => { | ||
array.push(new Array(10e6).fill('*')); | ||
console.log('now rss:', process.memoryUsage().rss / 1024 / 1024 + ' Mb'); | ||
}, 1); | ||
}, Number(process.env.XPROFILER_FATAL_ERROR_INTERVAL) || 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { profileRule: { cpuprofile, heapprofile, gcprofile }, checkProfile } = require('./command.test'); | ||
|
||
exports = module.exports = function () { | ||
const list = [ | ||
// fatal error | ||
{ | ||
title: '<fatal_error> cpu profiling', | ||
jspath: path.join(__dirname, 'fatal-error.js'), | ||
tid: 0, | ||
cmd: 'start_cpu_profiling', | ||
options: { profiling_time: 5 * 60 * 1000 }, | ||
checkExitInfo: false, | ||
check(file) { | ||
const content = fs.readFileSync(file, 'utf8').trim(); | ||
checkProfile(cpuprofile, JSON.parse(content)); | ||
} | ||
}, | ||
{ | ||
title: '<fatal_error> heap profiling', | ||
jspath: path.join(__dirname, 'fatal-error.js'), | ||
tid: 0, | ||
cmd: 'start_heap_profiling', | ||
options: { profiling_time: 5 * 60 * 1000 }, | ||
checkExitInfo: false, | ||
check(file) { | ||
const content = fs.readFileSync(file, 'utf8').trim(); | ||
checkProfile(heapprofile, JSON.parse(content)); | ||
} | ||
}, | ||
{ | ||
title: '<fatal_error> gc profiling', | ||
jspath: path.join(__dirname, 'fatal-error.js'), | ||
tid: 0, | ||
cmd: 'start_gc_profiling', | ||
options: { profiling_time: 5 * 60 * 1000 }, | ||
checkExitInfo: false, | ||
check(file) { | ||
const content = fs.readFileSync(file, 'utf8').trim(); | ||
checkProfile(gcprofile, JSON.parse(content)); | ||
} | ||
}, | ||
|
||
// exit 0 with profiling time | ||
{ | ||
title: '<at_exit> cpu profiling', | ||
jspath: path.join(__dirname, 'exit.js'), | ||
tid: 0, | ||
cmd: 'start_cpu_profiling', | ||
options: { profiling_time: 5 * 60 * 1000 }, | ||
checkExitInfo: true, | ||
check(file) { | ||
const content = fs.readFileSync(file, 'utf8').trim(); | ||
checkProfile(cpuprofile, JSON.parse(content)); | ||
} | ||
}, | ||
{ | ||
title: '<at_exit> heap profiling', | ||
jspath: path.join(__dirname, 'exit.js'), | ||
tid: 0, | ||
cmd: 'start_heap_profiling', | ||
options: { profiling_time: 5 * 60 * 1000 }, | ||
checkExitInfo: true, | ||
check(file) { | ||
const content = fs.readFileSync(file, 'utf8').trim(); | ||
checkProfile(heapprofile, JSON.parse(content)); | ||
} | ||
}, | ||
{ | ||
title: '<at_exit> gc profiling', | ||
jspath: path.join(__dirname, 'exit.js'), | ||
tid: 0, | ||
cmd: 'start_gc_profiling', | ||
options: { profiling_time: 5 * 60 * 1000 }, | ||
checkExitInfo: true, | ||
check(file) { | ||
const content = fs.readFileSync(file, 'utf8').trim(); | ||
checkProfile(gcprofile, JSON.parse(content)); | ||
} | ||
}, | ||
|
||
// exit 0 with no profiling time | ||
{ | ||
title: '<at_exit> cpu profiling', | ||
jspath: path.join(__dirname, 'exit.js'), | ||
tid: 0, | ||
cmd: 'start_cpu_profiling', | ||
options: undefined, | ||
checkExitInfo: true, | ||
check(file) { | ||
const content = fs.readFileSync(file, 'utf8').trim(); | ||
checkProfile(cpuprofile, JSON.parse(content)); | ||
} | ||
}, | ||
{ | ||
title: '<at_exit> heap profiling', | ||
jspath: path.join(__dirname, 'exit.js'), | ||
tid: 0, | ||
cmd: 'start_heap_profiling', | ||
options: undefined, | ||
checkExitInfo: true, | ||
check(file) { | ||
const content = fs.readFileSync(file, 'utf8').trim(); | ||
checkProfile(heapprofile, JSON.parse(content)); | ||
} | ||
}, | ||
{ | ||
title: '<at_exit> gc profiling', | ||
jspath: path.join(__dirname, 'exit.js'), | ||
tid: 0, | ||
cmd: 'start_gc_profiling', | ||
options: undefined, | ||
checkExitInfo: true, | ||
check(file) { | ||
const content = fs.readFileSync(file, 'utf8').trim(); | ||
checkProfile(gcprofile, JSON.parse(content)); | ||
} | ||
}, | ||
]; | ||
|
||
return list; | ||
}; |
Oops, something went wrong.