• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// This tests that --cpu-prof-dir works for workers.
4
5const common = require('../common');
6const fixtures = require('../common/fixtures');
7common.skipIfInspectorDisabled();
8
9const assert = require('assert');
10const fs = require('fs');
11const path = require('path');
12const { spawnSync } = require('child_process');
13
14const tmpdir = require('../common/tmpdir');
15const {
16  getCpuProfiles,
17  kCpuProfInterval,
18  env,
19  getFrames
20} = require('../common/cpu-prof');
21
22// --cpu-prof-dir with worker
23{
24  tmpdir.refresh();
25  const output = spawnSync(process.execPath, [
26    '--cpu-prof-interval',
27    kCpuProfInterval,
28    '--cpu-prof-dir',
29    'prof',
30    '--cpu-prof',
31    fixtures.path('workload', 'fibonacci-worker.js'),
32  ], {
33    cwd: tmpdir.path,
34    env
35  });
36  if (output.status !== 0) {
37    console.log(output.stderr.toString());
38  }
39  assert.strictEqual(output.status, 0);
40  const dir = path.join(tmpdir.path, 'prof');
41  assert(fs.existsSync(dir));
42  const profiles = getCpuProfiles(dir);
43  assert.strictEqual(profiles.length, 2);
44  const profile1 = getFrames(profiles[0], 'fibonacci.js');
45  const profile2 = getFrames(profiles[1], 'fibonacci.js');
46  if (profile1.frames.length === 0 && profile2.frames.length === 0) {
47    // Show native debug output and the profile for debugging.
48    console.log(output.stderr.toString());
49    console.log('CPU path: ', profiles[0]);
50    console.log(profile1.nodes);
51    console.log('CPU path: ', profiles[1]);
52    console.log(profile2.nodes);
53  }
54  assert(profile1.frames.length > 0 || profile2.frames.length > 0);
55}
56