Skip to content
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

tools: fix prof polyfill readline #18641

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/internal/v8_prof_polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ function readline() {
if (line.length === 0) {
return '';
}
if (bytes === 0) {
process.emitWarning('profile file is broken', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: you might just add the filename of the broken file? And please use a capital letter as first character.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the advice.Add the filename is better.

code: 'BROKEN_PROFILE_FILE',
detail: `${JSON.stringify(line)} at the file end is broken`
});
return '';
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ Platform check for Windows.

Platform check for Windows 32-bit on Windows 64-bit.

### isCPPSymbolsNotMapped
* [<Boolean>]

Platform check for c++ symbols are mapped or not.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c++ => C++


### leakedGlobals()
* return [<Array>]

Expand Down
5 changes: 5 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,3 +802,8 @@ exports.hijackStdout = hijackStdWritable.bind(null, 'stdout');
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
exports.restoreStdout = restoreWritable.bind(null, 'stdout');
exports.restoreStderr = restoreWritable.bind(null, 'stderr');
exports.isCPPSymbolsNotMapped = exports.isWindows ||
exports.isSunOS ||
exports.isAIX ||
exports.isLinuxPPCBE ||
exports.isFreeBSD;
7 changes: 2 additions & 5 deletions test/tick-processor/test-tick-processor-builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ const common = require('../common');
if (!common.enoughTestCpu)
common.skip('test is CPU-intensive');

if (common.isWindows ||
common.isSunOS ||
common.isAIX ||
common.isLinuxPPCBE ||
common.isFreeBSD)
if (common.isCPPSymbolsNotMapped) {
common.skip('C++ symbols are not mapped for this os.');
}

const base = require('./tick-processor-base.js');

Expand Down
7 changes: 2 additions & 5 deletions test/tick-processor/test-tick-processor-cpp-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ const common = require('../common');
if (!common.enoughTestCpu)
common.skip('test is CPU-intensive');

if (common.isWindows ||
common.isSunOS ||
common.isAIX ||
common.isLinuxPPCBE ||
common.isFreeBSD)
if (common.isCPPSymbolsNotMapped) {
common.skip('C++ symbols are not mapped for this os.');
}

const base = require('./tick-processor-base.js');

Expand Down
60 changes: 60 additions & 0 deletions test/tick-processor/test-tick-processor-polyfill-brokenfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

if (!common.enoughTestCpu)
common.skip('test is CPU-intensive');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: would you be so kind and use a capital letter as first character? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the node test,the first character in skip message is always lower case.


if (common.isCPPSymbolsNotMapped) {
common.skip('C++ symbols are not mapped for this os.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether the linter (make lint) will complain or not, but this is difficult to read. Please use braces here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Operating system should be upper cased as in OS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the advice.It should be upper cased.

}

//This test will produce a broken profile log.
//ensure prof-polyfill not stuck in infinite loop
//and success process
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please use a space at the beginning of each line in a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the advice.It should have a space at the beginning of each line.



const assert = require('assert');
const cp = require('child_process');
const path = require('path');
const fs = require('fs');

const LOG_FILE = path.join(tmpdir.path, 'tick-processor.log');
const RETRY_TIMEOUT = 150;
const BROKEN_PART = 'tick,';
const WARN_REG_EXP = /\(node:\d+\) \[BROKEN_PROFILE_FILE\] Warning: profile file is broken[\r\n]+".*tick," at the file end is broken/;

const code = `function f() {
this.ts = Date.now();
setImmediate(function() { new f(); });
};
f();`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we have the unwritten rule not to use multi line template strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the advice.I will split it to two lines.


const proc = cp.spawn(process.execPath, [
'--no_logfile_per_isolate',
'--logfile=-',
'--prof',
'-pe', code
], {
stdio: ['ignore', 'pipe', 'inherit']
});

let ticks = '';
proc.stdout.on('data', (chunk) => ticks += chunk);


function runPolyfill(content) {
proc.kill();
content += BROKEN_PART;
fs.writeFileSync(LOG_FILE, content);
const child = cp.spawnSync(
`${process.execPath}`,
[
'--prof-process', LOG_FILE
]);
assert(WARN_REG_EXP.test(child.stderr.toString()));
assert.strictEqual(child.status, 0, 'broken file should success too');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally would like to stick to the default message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default message will be removed.

}

setTimeout(() => runPolyfill(ticks), RETRY_TIMEOUT);
7 changes: 2 additions & 5 deletions test/tick-processor/test-tick-processor-preprocess-flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ const common = require('../common');
if (!common.enoughTestCpu)
common.skip('test is CPU-intensive');

if (common.isWindows ||
common.isSunOS ||
common.isAIX ||
common.isLinuxPPCBE ||
common.isFreeBSD)
if (common.isCPPSymbolsNotMapped) {
common.skip('C++ symbols are not mapped for this os.');
}

const base = require('./tick-processor-base.js');

Expand Down