summaryrefslogtreecommitdiff
path: root/test/sequential
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-04-19 17:15:04 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-04-23 01:48:46 +0800
commit49d3d11ba7975b2c6df4ecab55b4619da46fcb95 (patch)
tree90a6011d693065805b725fed7a475b1bf1e2f7ef /test/sequential
parenta3d1922958a18851afaae7238cfbd8079070f272 (diff)
downloadandroid-node-v8-49d3d11ba7975b2c6df4ecab55b4619da46fcb95.tar.gz
android-node-v8-49d3d11ba7975b2c6df4ecab55b4619da46fcb95.tar.bz2
android-node-v8-49d3d11ba7975b2c6df4ecab55b4619da46fcb95.zip
inspector: split --cpu-prof-path to --cpu-prof-dir and --cpu-prof-name
To improve the integration of `--cpu-prof` with workers, this patch splits `--cpu-prof-path` into `--cpu-prof-dir` and `--cpu-prof-name`, so when a worker is launched from a thread that enables `--cpu-prof`, if the parent thread sets `--cpu-prof-dir`, then the profile of both thread would be generated to the specified directory. If they end up specifying the same `--cpu-prof-name` the behavior is undefined the last profile will overwritten the first one. PR-URL: https://github.com/nodejs/node/pull/27306 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/sequential')
-rw-r--r--test/sequential/test-cpu-prof.js147
1 files changed, 128 insertions, 19 deletions
diff --git a/test/sequential/test-cpu-prof.js b/test/sequential/test-cpu-prof.js
index 8b9001ba67..ffaa0e9b1b 100644
--- a/test/sequential/test-cpu-prof.js
+++ b/test/sequential/test-cpu-prof.js
@@ -1,6 +1,6 @@
'use strict';
-// This tests that --cpu-prof and --cpu-prof-path works.
+// This tests that --cpu-prof, --cpu-prof-dir and --cpu-prof-name works.
const common = require('../common');
if (process.features.debug &&
@@ -27,17 +27,22 @@ function getCpuProfiles(dir) {
.map((file) => path.join(dir, file));
}
-function verifyFrames(output, file, suffix) {
+function getFrames(output, file, suffix) {
const data = fs.readFileSync(file, 'utf8');
const profile = JSON.parse(data);
const frames = profile.nodes.filter((i) => {
const frame = i.callFrame;
return frame.url.endsWith(suffix);
});
+ return { frames, nodes: profile.nodes };
+}
+
+function verifyFrames(output, file, suffix) {
+ const { frames, nodes } = getFrames(output, file, suffix);
if (frames.length === 0) {
// Show native debug output and the profile for debugging.
console.log(output.stderr.toString());
- console.log(profile.nodes);
+ console.log(nodes);
}
assert.notDeepStrictEqual(frames, []);
}
@@ -118,11 +123,11 @@ const env = {
verifyFrames(output, profiles[0], 'fibonacci-sigint.js');
}
-// Outputs CPU profile from worker.
+// Outputs CPU profile from worker when execArgv is set.
{
tmpdir.refresh();
const output = spawnSync(process.execPath, [
- fixtures.path('workload', 'fibonacci-worker.js'),
+ fixtures.path('workload', 'fibonacci-worker-argv.js'),
], {
cwd: tmpdir.path,
env
@@ -136,13 +141,56 @@ const env = {
verifyFrames(output, profiles[0], 'fibonacci.js');
}
-// Output to specified --cpu-prof-path without --cpu-prof
+// --cpu-prof-name without --cpu-prof
+{
+ tmpdir.refresh();
+ const output = spawnSync(process.execPath, [
+ '--cpu-prof-name',
+ 'test.cpuprofile',
+ fixtures.path('workload', 'fibonacci.js'),
+ ], {
+ cwd: tmpdir.path,
+ env
+ });
+ const stderr = output.stderr.toString().trim();
+ if (output.status !== 9) {
+ console.log(stderr);
+ }
+ assert.strictEqual(output.status, 9);
+ assert.strictEqual(
+ stderr,
+ `${process.execPath}: --cpu-prof-name must be used with --cpu-prof`);
+}
+
+// --cpu-prof-dir without --cpu-prof
+{
+ tmpdir.refresh();
+ const output = spawnSync(process.execPath, [
+ '--cpu-prof-dir',
+ 'prof',
+ fixtures.path('workload', 'fibonacci.js'),
+ ], {
+ cwd: tmpdir.path,
+ env
+ });
+ const stderr = output.stderr.toString().trim();
+ if (output.status !== 9) {
+ console.log(stderr);
+ }
+ assert.strictEqual(output.status, 9);
+ assert.strictEqual(
+ stderr,
+ `${process.execPath}: --cpu-prof-dir must be used with --cpu-prof`);
+}
+
+// --cpu-prof-name
{
tmpdir.refresh();
const file = path.join(tmpdir.path, 'test.cpuprofile');
const output = spawnSync(process.execPath, [
- '--cpu-prof-path',
- file,
+ '--cpu-prof',
+ '--cpu-prof-name',
+ 'test.cpuprofile',
fixtures.path('workload', 'fibonacci.js'),
], {
cwd: tmpdir.path,
@@ -157,14 +205,13 @@ const env = {
verifyFrames(output, file, 'fibonacci.js');
}
-// Output to specified --cpu-prof-path with --cpu-prof
+// relative --cpu-prof-dir
{
tmpdir.refresh();
- const file = path.join(tmpdir.path, 'test.cpuprofile');
const output = spawnSync(process.execPath, [
'--cpu-prof',
- '--cpu-prof-path',
- file,
+ '--cpu-prof-dir',
+ 'prof',
fixtures.path('workload', 'fibonacci.js'),
], {
cwd: tmpdir.path,
@@ -174,19 +221,47 @@ const env = {
console.log(output.stderr.toString());
}
assert.strictEqual(output.status, 0);
- const profiles = getCpuProfiles(tmpdir.path);
- assert.deepStrictEqual(profiles, [file]);
- verifyFrames(output, file, 'fibonacci.js');
+ const dir = path.join(tmpdir.path, 'prof');
+ assert(fs.existsSync(dir));
+ const profiles = getCpuProfiles(dir);
+ assert.strictEqual(profiles.length, 1);
+ verifyFrames(output, profiles[0], 'fibonacci.js');
}
-// Output to specified --cpu-prof-path when it's not absolute
+// absolute --cpu-prof-dir
{
tmpdir.refresh();
- const file = path.join(tmpdir.path, 'test.cpuprofile');
+ const dir = path.join(tmpdir.path, 'prof');
const output = spawnSync(process.execPath, [
'--cpu-prof',
- '--cpu-prof-path',
+ '--cpu-prof-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');
+}
+
+// --cpu-prof-dir and --cpu-prof-name
+{
+ tmpdir.refresh();
+ const dir = path.join(tmpdir.path, 'prof');
+ const file = path.join(dir, 'test.cpuprofile');
+ const output = spawnSync(process.execPath, [
+ '--cpu-prof',
+ '--cpu-prof-name',
'test.cpuprofile',
+ '--cpu-prof-dir',
+ dir,
fixtures.path('workload', 'fibonacci.js'),
], {
cwd: tmpdir.path,
@@ -196,7 +271,41 @@ const env = {
console.log(output.stderr.toString());
}
assert.strictEqual(output.status, 0);
- const profiles = getCpuProfiles(tmpdir.path);
+ assert(fs.existsSync(dir));
+ const profiles = getCpuProfiles(dir);
assert.deepStrictEqual(profiles, [file]);
verifyFrames(output, file, 'fibonacci.js');
}
+
+// --cpu-prof-dir with worker
+{
+ tmpdir.refresh();
+ const output = spawnSync(process.execPath, [
+ '--cpu-prof-dir',
+ 'prof',
+ '--cpu-prof',
+ fixtures.path('workload', 'fibonacci-worker.js'),
+ ], {
+ cwd: tmpdir.path,
+ env
+ });
+ if (output.status !== 0) {
+ console.log(output.stderr.toString());
+ }
+ assert.strictEqual(output.status, 0);
+ const dir = path.join(tmpdir.path, 'prof');
+ assert(fs.existsSync(dir));
+ const profiles = getCpuProfiles(dir);
+ assert.strictEqual(profiles.length, 2);
+ const profile1 = getFrames(output, profiles[0], 'fibonacci.js');
+ const profile2 = getFrames(output, profiles[1], 'fibonacci.js');
+ if (profile1.frames.length === 0 && profile2.frames.length === 0) {
+ // Show native debug output and the profile for debugging.
+ console.log(output.stderr.toString());
+ console.log('CPU path: ', profiles[0]);
+ console.log(profile1.nodes);
+ console.log('CPU path: ', profiles[1]);
+ console.log(profile2.nodes);
+ }
+ assert(profile1.frames.length > 0 || profile2.frames.length > 0);
+}