Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function profLogConvert ({isolateLogPath, pid, folder, stream}, args) {
const { stdout, stderr, status } = spawnSync('node', ['--prof-process', '--preprocess', '-j', isolateLogPath])
if (status !== 0) {
args.log('prof isolateLogPath convert Failed: ', stderr + '', stdout + '')
return
}
const json = isolateLogPath + '.json'
fs.writeFileSync(json, stdout)
const data = require(json)
data.ticks.forEach((tick, i) => {
// tick.ms = Math.round(tick.tm / 1000)
const addr = tick.s.filter((n, i) => i % 2 === 0)
const offsets = tick.s.filter((n, i) => i % 2 === 1)
tick.stack = addr.map((n, i) => data.code[n]).filter(Boolean)
tick.stack = tick.stack.filter(({type}) => type === 'JS')
if (tick.stack.length === 0) {
data.ticks[i] = undefined
return
}
})
data.ticks = data.ticks.filter(Boolean)
const proc = 'node'
const profName = 'cpu-clock'
const space = ' '
fs.writeFileSync(json, stdout)
const data = require(json)
data.ticks.forEach((tick, i) => {
// tick.ms = Math.round(tick.tm / 1000)
const addr = tick.s.filter((n, i) => i % 2 === 0)
const offsets = tick.s.filter((n, i) => i % 2 === 1)
tick.stack = addr.map((n, i) => data.code[n]).filter(Boolean)
tick.stack = tick.stack.filter(({type}) => type === 'JS')
if (tick.stack.length === 0) {
data.ticks[i] = undefined
return
}
})
data.ticks = data.ticks.filter(Boolean)
const proc = 'node'
const profName = 'cpu-clock'
const space = ' '
data.ticks.forEach((tick) => {
stream.write(`${proc} ${pid} ${tick.tm}: ${profName}:\n`)
stream.write(tick.stack.map(({name, kind}) => {
if (!name) return 'UKNOWN'
if (name[0] === ' ') name = '(anonymous)' + name
if (kind === 'Opt') name = '*' + name
if (kind === 'Unopt') name = '~' + name
return space + name
}).join('\n'))
stream.write('\n\n')
})