1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const cp = require('child_process'); 5const fs = require('fs'); 6const path = require('path'); 7 8const CODE = 9 'setTimeout(() => { for (let i = 0; i < 100000; i++) { "test" + i } }, 1)'; 10 11const tmpdir = require('../common/tmpdir'); 12tmpdir.refresh(); 13const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log'); 14 15const proc = cp.spawn(process.execPath, 16 [ '--trace-events-enabled', 17 '--trace-event-categories', 'v8', 18 '-e', CODE ], 19 { cwd: tmpdir.path }); 20 21proc.once('exit', common.mustCall(() => { 22 assert(fs.existsSync(FILE_NAME)); 23 fs.readFile(FILE_NAME, common.mustCall((err, data) => { 24 const traces = JSON.parse(data.toString()).traceEvents; 25 assert(traces.length > 0); 26 // V8 trace events should be generated. 27 assert(traces.some((trace) => { 28 if (trace.pid !== proc.pid) 29 return false; 30 if (trace.cat !== 'v8') 31 return false; 32 if (!trace.name.startsWith('V8.')) 33 return false; 34 return true; 35 })); 36 37 // C++ async_hooks trace events should be generated. 38 assert(!traces.some((trace) => { 39 if (trace.pid !== proc.pid) 40 return false; 41 if (trace.cat !== 'node.async_hooks') 42 return false; 43 return true; 44 })); 45 46 47 // JavaScript async_hooks trace events should be generated. 48 assert(!traces.some((trace) => { 49 if (trace.pid !== proc.pid) 50 return false; 51 if (trace.cat !== 'node.async_hooks') 52 return false; 53 if (trace.name !== 'Timeout') 54 return false; 55 return true; 56 })); 57 })); 58})); 59