-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
src: allow setting a dir for all diagnostic output #33584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,9 @@ added: v12.0.0 | |
| Specify the directory where the CPU profiles generated by `--cpu-prof` will | ||
| be placed. | ||
|
|
||
| The default value is controlled by the | ||
| [--diagnostic-dir](#--diagnostic-dir=directory) command line option. | ||
|
|
||
| ### `--cpu-prof-interval` | ||
| <!-- YAML | ||
| added: v12.2.0 | ||
|
|
@@ -127,6 +130,16 @@ added: v12.0.0 | |
|
|
||
| Specify the file name of the CPU profile generated by `--cpu-prof`. | ||
|
|
||
| ### `--diagnostic-dir=directory` | ||
|
|
||
| Set the directory to which all diagnostic output files will be written to. | ||
| Defaults to current working directory. | ||
|
|
||
| Affects the default output directory of: | ||
| * [--cpu-prof-dir](#--cpu-prof-dir) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering these two dir flags are still experimental, I think we could just emit a deprecation warning for them, and make them no-ops when
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. um, on the other hand, maybe we would also want to allow the user to override these directories individually through
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thats what I intented with: if (cpu_prof && cpu_prof_dir.empty() && !diagnostic_dir.empty()) {
cpu_prof_dir = diagnostic_dir;
} |
||
| * [--heap-prof-dir](#--heap-prof-dir) | ||
| * [--redirect-warnings](#--redirect-warnings=file) | ||
|
|
||
| ### `--disable-proto=mode` | ||
| <!-- YAML | ||
| added: | ||
|
|
@@ -360,6 +373,9 @@ added: v12.4.0 | |
| Specify the directory where the heap profiles generated by `--heap-prof` will | ||
| be placed. | ||
|
|
||
| The default value is controlled by the | ||
| [--diagnostic-dir](#--diagnostic-dir=directory) command line option. | ||
|
|
||
| ### `--heap-prof-interval` | ||
| <!-- YAML | ||
| added: v12.4.0 | ||
|
|
@@ -640,6 +656,10 @@ file will be created if it does not exist, and will be appended to if it does. | |
| If an error occurs while attempting to write the warning to the file, the | ||
| warning will be written to stderr instead. | ||
|
|
||
| The `file` name may be an absolute path. If it is not, the default directory it | ||
| will be written to is controlled by the | ||
| [--diagnostic-dir](#--diagnostic-dir=directory) command line option. | ||
|
|
||
| ### `--report-compact` | ||
| <!-- YAML | ||
| added: | ||
|
|
@@ -1222,6 +1242,7 @@ node --require "./a.js" --require "./b.js" | |
|
|
||
| Node.js options that are allowed are: | ||
| <!-- node-options-node start --> | ||
| * `--diagnostic-dir` | ||
| * `--disable-proto` | ||
| * `--enable-fips` | ||
| * `--enable-source-maps` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| 'use strict'; | ||
|
|
||
| // This test is to ensure that --diagnostic-dir does not change the directory | ||
| // for --cpu-prof when --cpu-prof-dir is specified | ||
|
|
||
| const common = require('../common'); | ||
| const fixtures = require('../common/fixtures'); | ||
| common.skipIfInspectorDisabled(); | ||
|
|
||
| const assert = require('assert'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const { spawnSync } = require('child_process'); | ||
|
|
||
| const tmpdir = require('../common/tmpdir'); | ||
| const { | ||
| getCpuProfiles, | ||
| kCpuProfInterval, | ||
| env, | ||
| verifyFrames | ||
| } = require('../common/cpu-prof'); | ||
|
|
||
| // Test --diagnostic-dir changes the default for --cpu-prof | ||
|
|
||
| { | ||
| tmpdir.refresh(); | ||
| const dir = path.join(tmpdir.path, 'prof'); | ||
| const output = spawnSync(process.execPath, [ | ||
| '--cpu-prof', | ||
| '--cpu-prof-interval', | ||
| kCpuProfInterval, | ||
| '--diagnostic-dir', | ||
| dir, | ||
| fixtures.path('workload', 'fibonacci.js'), | ||
| ], { | ||
| cwd: tmpdir.path, | ||
| env | ||
| }); | ||
| if (output.status !== 0) { | ||
| console.log(output.stderr.toString()); | ||
| } | ||
| assert.strictEqual(output.status, 0); | ||
| assert(fs.existsSync(dir)); | ||
| const profiles = getCpuProfiles(dir); | ||
| assert.strictEqual(profiles.length, 1); | ||
| verifyFrames(output, profiles[0], 'fibonacci.js'); | ||
| } | ||
|
|
||
| // Test --cpu-prof-dir overwrites --diagnostic-dir | ||
|
|
||
| { | ||
| tmpdir.refresh(); | ||
| const dir = path.join(tmpdir.path, 'diag'); | ||
| const dir2 = path.join(tmpdir.path, 'prof'); | ||
| const output = spawnSync(process.execPath, [ | ||
| '--cpu-prof', | ||
| '--cpu-prof-interval', | ||
| kCpuProfInterval, | ||
| '--diagnostic-dir', | ||
| dir, | ||
| '--cpu-prof-dir', | ||
| dir2, | ||
| fixtures.path('workload', 'fibonacci.js'), | ||
| ], { | ||
| cwd: tmpdir.path, | ||
| env | ||
| }); | ||
| if (output.status !== 0) { | ||
| console.log(output.stderr.toString()); | ||
| } | ||
| assert.strictEqual(output.status, 0); | ||
| assert(fs.existsSync(dir2)); | ||
| const profiles = getCpuProfiles(dir2); | ||
| assert.strictEqual(profiles.length, 1); | ||
| verifyFrames(output, profiles[0], 'fibonacci.js'); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| 'use strict'; | ||
|
|
||
| // This test is to ensure that --diagnostic-dir does not change the directory | ||
| // for --cpu-prof when --cpu-prof-dir is specified | ||
|
|
||
| const common = require('../common'); | ||
| const fixtures = require('../common/fixtures'); | ||
| common.skipIfInspectorDisabled(); | ||
|
|
||
| const assert = require('assert'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const { spawnSync } = require('child_process'); | ||
|
|
||
| const tmpdir = require('../common/tmpdir'); | ||
|
|
||
| function findFirstFrameInNode(root, func) { | ||
| const first = root.children.find( | ||
| (child) => child.callFrame.functionName === func | ||
| ); | ||
| if (first) { | ||
| return first; | ||
| } | ||
| for (const child of root.children) { | ||
| const first = findFirstFrameInNode(child, func); | ||
| if (first) { | ||
| return first; | ||
| } | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| function findFirstFrame(file, func) { | ||
| const data = fs.readFileSync(file, 'utf8'); | ||
| const profile = JSON.parse(data); | ||
| const first = findFirstFrameInNode(profile.head, func); | ||
| return { frame: first, roots: profile.head.children }; | ||
| } | ||
|
|
||
| function verifyFrames(output, file, func) { | ||
| const { frame, roots } = findFirstFrame(file, func); | ||
| if (!frame) { | ||
| // Show native debug output and the profile for debugging. | ||
| console.log(output.stderr.toString()); | ||
| console.log(roots); | ||
| } | ||
| assert.notDeepStrictEqual(frame, undefined); | ||
| } | ||
|
|
||
| const kHeapProfInterval = 128; | ||
| const TEST_ALLOCATION = kHeapProfInterval * 2; | ||
|
|
||
| const env = { | ||
| ...process.env, | ||
| TEST_ALLOCATION, | ||
| NODE_DEBUG_NATIVE: 'INSPECTOR_PROFILER' | ||
| }; | ||
|
|
||
| function getHeapProfiles(dir) { | ||
| const list = fs.readdirSync(dir); | ||
| return list | ||
| .filter((file) => file.endsWith('.heapprofile')) | ||
| .map((file) => path.join(dir, file)); | ||
| } | ||
|
|
||
| // Test --diagnostic-dir changes the default for --cpu-prof | ||
| { | ||
| tmpdir.refresh(); | ||
| const dir = path.join(tmpdir.path, 'prof'); | ||
| const output = spawnSync(process.execPath, [ | ||
| '--heap-prof', | ||
| '--diagnostic-dir', | ||
| dir, | ||
| '--heap-prof-interval', | ||
| kHeapProfInterval, | ||
| fixtures.path('workload', 'allocation.js'), | ||
| ], { | ||
| cwd: tmpdir.path, | ||
| env | ||
| }); | ||
| if (output.status !== 0) { | ||
| console.log(output.stderr.toString()); | ||
| } | ||
| assert.strictEqual(output.status, 0); | ||
| assert(fs.existsSync(dir)); | ||
| const profiles = getHeapProfiles(dir); | ||
| assert.strictEqual(profiles.length, 1); | ||
| verifyFrames(output, profiles[0], 'runAllocation'); | ||
| } | ||
|
|
||
| // Test --heap-prof-dir overwrites --diagnostic-dir | ||
| { | ||
| tmpdir.refresh(); | ||
| const dir = path.join(tmpdir.path, 'diag'); | ||
| const dir2 = path.join(tmpdir.path, 'prof'); | ||
| const output = spawnSync(process.execPath, [ | ||
| '--heap-prof', | ||
| '--heap-prof-interval', | ||
| kHeapProfInterval, | ||
| '--diagnostic-dir', | ||
| dir, | ||
| '--heap-prof-dir', | ||
| dir2, | ||
| fixtures.path('workload', 'allocation.js'), | ||
| ], { | ||
| cwd: tmpdir.path, | ||
| env | ||
| }); | ||
| if (output.status !== 0) { | ||
| console.log(output.stderr.toString()); | ||
| } | ||
| assert.strictEqual(output.status, 0); | ||
| assert(fs.existsSync(dir2)); | ||
| const profiles = getHeapProfiles(dir2); | ||
| assert.strictEqual(profiles.length, 1); | ||
| verifyFrames(output, profiles[0], 'runAllocation'); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.