Skip to content

Commit 11c8943

Browse files
committed
Fixed support for Node 8.12.0.
1 parent 1ceb9fb commit 11c8943

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

lib/v8-log-to-ticks.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,32 @@
33
const { spawn } = require('child_process')
44
const { parse } = require('jsonstream2')
55
const { extname } = require('path')
6+
const { promisify } = require('util')
67
const through = require('through2')
78
const fs = require('fs')
89
const pump = require('pump')
910

10-
module.exports = v8LogToTicks
11+
const readFile = promisify(fs.readFile)
12+
const writeFile = promisify(fs.writeFile)
13+
14+
module.exports = process
15+
16+
function process (isolateLogPath, node) {
17+
return filterLinesThatAreTooLong(isolateLogPath).then((filtered) => {
18+
return v8LogToTicks(filtered, node)
19+
})
20+
}
21+
22+
// long lines make the --preprocess crash. We are just filtering them beforehand
23+
// as Node.js 8.12.0 would crash if there is any error in the preprocess script
24+
function filterLinesThatAreTooLong (isolateLogPath) {
25+
const dest = isolateLogPath + '.filtered'
26+
// TODO use streams
27+
return readFile(isolateLogPath, 'utf8').then((data) => {
28+
data = data.split('\n').filter((s) => s.length < 1024).join('\n')
29+
return writeFile(dest, data)
30+
}).then(() => dest)
31+
}
1132

1233
function v8LogToTicks (isolateLogPath, node) {
1334
const isJson = extname(isolateLogPath) === '.json'
@@ -22,8 +43,12 @@ function v8LogToTicks (isolateLogPath, node) {
2243
// it's an error in the V8 internal tick profiler)
2344
// ignore them.
2445
const ignore = /unknown code state:/
46+
// pump(sp.stderr, process.stderr)
2547
pump(sp.stderr, through((errMsg, _, cb) => {
26-
if (ignore.test(errMsg)) cb()
48+
if (ignore.test(errMsg)) {
49+
console.log('ignored', errMsg.toString())
50+
cb()
51+
}
2752
else cb(errMsg, _, cb)
2853
}), process.stderr)
2954
}

0 commit comments

Comments
 (0)