3
3
const { spawn } = require ( 'child_process' )
4
4
const { parse } = require ( 'jsonstream2' )
5
5
const { extname } = require ( 'path' )
6
+ const { promisify } = require ( 'util' )
6
7
const through = require ( 'through2' )
7
8
const fs = require ( 'fs' )
8
9
const pump = require ( 'pump' )
9
10
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
+ }
11
32
12
33
function v8LogToTicks ( isolateLogPath , node ) {
13
34
const isJson = extname ( isolateLogPath ) === '.json'
@@ -22,8 +43,12 @@ function v8LogToTicks (isolateLogPath, node) {
22
43
// it's an error in the V8 internal tick profiler)
23
44
// ignore them.
24
45
const ignore = / u n k n o w n c o d e s t a t e : /
46
+ // pump(sp.stderr, process.stderr)
25
47
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
+ }
27
52
else cb ( errMsg , _ , cb )
28
53
} ) , process . stderr )
29
54
}
0 commit comments