• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 'use strict';
2 
3 // This tests that --cpu-prof generates CPU profile when
4 // process.kill(process.pid, "SIGINT"); exits the process.
5 
6 const common = require('../common');
7 const fixtures = require('../common/fixtures');
8 common.skipIfInspectorDisabled();
9 
10 const assert = require('assert');
11 const { spawnSync } = require('child_process');
12 
13 const tmpdir = require('../common/tmpdir');
14 const {
15   getCpuProfiles,
16   kCpuProfInterval,
17   env,
18   verifyFrames
19 } = require('../common/cpu-prof');
20 
21 {
22   tmpdir.refresh();
23   const output = spawnSync(process.execPath, [
24     '--cpu-prof',
25     '--cpu-prof-interval',
26     kCpuProfInterval,
27     fixtures.path('workload', 'fibonacci-sigint.js'),
28   ], {
29     cwd: tmpdir.path,
30     env
31   });
32   if (!common.isWindows) {
33     if (output.signal !== 'SIGINT') {
34       console.log(output.stderr.toString());
35     }
36     assert.strictEqual(output.signal, 'SIGINT');
37   }
38   const profiles = getCpuProfiles(tmpdir.path);
39   assert.strictEqual(profiles.length, 1);
40   verifyFrames(output, profiles[0], 'fibonacci-sigint.js');
41 }
42