• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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', '-e', CODE ],
17                      { cwd: tmpdir.path });
18
19proc.once('exit', common.mustCall(() => {
20  assert(fs.existsSync(FILE_NAME));
21  fs.readFile(FILE_NAME, common.mustCall((err, data) => {
22    const traces = JSON.parse(data.toString()).traceEvents;
23    assert(traces.length > 0);
24    // V8 trace events should be generated.
25    assert(traces.some((trace) => {
26      if (trace.pid !== proc.pid)
27        return false;
28      if (trace.cat !== 'v8')
29        return false;
30      if (trace.name !== 'V8.ScriptCompiler')
31        return false;
32      return true;
33    }));
34
35    // C++ async_hooks trace events should be generated.
36    assert(traces.some((trace) => {
37      if (trace.pid !== proc.pid)
38        return false;
39      if (trace.cat !== 'node,node.async_hooks')
40        return false;
41      return true;
42    }));
43
44
45    // JavaScript async_hooks trace events should be generated.
46    assert(traces.some((trace) => {
47      if (trace.pid !== proc.pid)
48        return false;
49      if (trace.cat !== 'node,node.async_hooks')
50        return false;
51      if (trace.name !== 'Timeout')
52        return false;
53      return true;
54    }));
55  }));
56}));
57