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