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: run tick processor without forking #4224

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
8 participants
@matthewloring
Copy link
Contributor

commented Dec 10, 2015

Using the tick processor no longer creates temporary files or spawns a
child process.

/cc @bnoordhuis

@mscdex mscdex added the tools label Dec 10, 2015

@JungMinu

View changes

lib/internal/v8_prof_processor.js Outdated
fs.writeFileSync(tempNm, process.binding('natives')['v8/tools/mac-nm'],
{ mode: 0o555 });
tickArguments.push('--mac', '--nm=' + path.join(process.cwd(), tempNm));
var nm = 'foo() { nm "$@" | (c++filt -p -i || cat) }; foo';

This comment has been minimized.

Copy link
@JungMinu

JungMinu Dec 10, 2015

Member

maybe const nm

This comment has been minimized.

Copy link
@matthewloring

matthewloring Dec 10, 2015

Author Contributor

I've converted as many of the vars in the polyfill and processor to const as I could. Unfortunately, the lack of strict mode prevents the use of let (not sure why const is allowed outside of strict now that I think about it).

This comment has been minimized.

Copy link
@evanlucas

evanlucas Dec 10, 2015

Member

Hm, if we are not in strict mode, shouldn't we use var instead. Sloppy mode const is totally different IIRC

This comment has been minimized.

Copy link
@matthewloring

matthewloring Dec 10, 2015

Author Contributor

The script appears to behave correctly using either const or var and I am unfamiliar with how things operate outside of strict mode. Happy to switch back to var if that is preferred.

@JungMinu

This comment has been minimized.

Copy link
Member

commented Dec 10, 2015

@bnoordhuis

View changes

lib/internal/v8_prof_polyfill.js Outdated
return require('child_process').execFileSync(
name, args, {encoding: 'utf8'});
const cmd = name + ' ' + args.join(' ');
return cp.execSync(cmd, {encoding: 'utf8'});

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Dec 17, 2015

Member

Maybe use .spawnSync() here? You can pass it arguments as an array and it will take care of shell escaping them.

This comment has been minimized.

Copy link
@matthewloring

matthewloring Dec 18, 2015

Author Contributor

When I use spawnSync, I get the error Error: spawnSync foo() { nm "$@" | (c++filt -p -i || cat) }; foo ENOENT. I'm not sure exactly how spawnSync and execSync differ but they're not handling this command the same way.

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Dec 18, 2015

Member

.execSync() executes the command as /bin/sh -c '<cmd> <args>' (cmd.exe /s /c "<cmd> <args>" on Windows) whereas .spawnSync() simply calls execve(). Guess I was wrong saying it takes care of shell escaping because it doesn't need to escape anything.

You could wrap that bit of shell script in a sh -c or bash -c below. Longer term, it might be nice to move normalizeExecArgs() from lib/child_process.js to lib/internal/child_process.js so you can use it here. It's possible some more work needs to be done on the internal module system to make that work, though.

I'll leave it up to you if you want to change this line.

This comment has been minimized.

Copy link
@matthewloring

matthewloring Dec 18, 2015

Author Contributor

I don't believe wrapping it in sh -c or bash -c will work in this instance because the shell script defines a function and then calls it on arguments that will be provided later at the call site. This is the snippet in question:

foo() { nm "$@" | (c++filt -p -i || cat) }; foo

Later it will be invoked as:

foo() { nm "$@" | (c++filt -p -i || cat) }; foo -n -f /usr/lib/system/example.dylib

Is it possible to perform that wrapping you described in this case?

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Dec 18, 2015

Member

sh -c 'foo() { ... }; foo $@' -- should work, if I understand you right.

This comment has been minimized.

Copy link
@matthewloring

matthewloring Dec 18, 2015

Author Contributor

I have this working now. Will spawning /bin/sh work correctly on windows or does that need to be special cased?

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Dec 18, 2015

Member

On Windows there is no /bin/sh, you'd use cmd.exe /s /c, but I don't think you actually need to spawn a shell. The OS X case is special because you're executing shell script, on other platforms nm is invoked directly.

This comment has been minimized.

Copy link
@matthewloring

matthewloring Dec 18, 2015

Author Contributor

I can handle the OS X case specially here if that is preferable. What is the motivation of changing execSync to spawnSync?

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Dec 18, 2015

Member

That you won't have to worry about escaping spaces in paths, for example.

This comment has been minimized.

Copy link
@matthewloring

matthewloring Dec 18, 2015

Author Contributor

Ok, that makes sense, I've added the special casing here and it's working on my test machine (OS X).

@bnoordhuis

This comment has been minimized.

Copy link
Member

commented Dec 18, 2015

LGTM with a suggestion.

@jasnell

This comment has been minimized.

Copy link
Member

commented Dec 18, 2015

LGTM

Matt Loring
tools: run tick processor without forking
Using the tick processor no longer creates temporary files or spawns a
child process.
@bnoordhuis

This comment has been minimized.

Copy link
Member

commented Dec 20, 2015

@Trott Trott force-pushed the nodejs:master branch to 082cc8d Dec 27, 2015

ofrobots added a commit that referenced this pull request Dec 29, 2015

tools: run tick processor without forking
Using the tick processor no longer creates temporary files or spawns a
child process.

PR-URL: #4224
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
@ofrobots

This comment has been minimized.

Copy link
Contributor

commented Dec 29, 2015

Thanks. Landed on master in 3e2a2e6.

@ofrobots ofrobots closed this Dec 29, 2015

Fishrock123 added a commit to Fishrock123/node that referenced this pull request Jan 6, 2016

tools: run tick processor without forking
Using the tick processor no longer creates temporary files or spawns a
child process.

PR-URL: nodejs#4224
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
@MylesBorins

This comment has been minimized.

Copy link
Member

commented Jan 6, 2016

@jasnell should this go to LTS?

@MylesBorins

This comment has been minimized.

Copy link
Member

commented Jan 28, 2016

relies on #4021

@matthewloring matthewloring deleted the matthewloring:tp-no-cp branch Feb 25, 2016

MylesBorins added a commit to MylesBorins/node that referenced this pull request Mar 1, 2016

tools: run tick processor without forking
Using the tick processor no longer creates temporary files or spawns a
child process.

PR-URL: nodejs#4224
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>

MylesBorins added a commit that referenced this pull request Mar 1, 2016

tools: run tick processor without forking
Using the tick processor no longer creates temporary files or spawns a
child process.

PR-URL: #4224
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>

MylesBorins added a commit that referenced this pull request Mar 2, 2016

tools: run tick processor without forking
Using the tick processor no longer creates temporary files or spawns a
child process.

PR-URL: #4224
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>

@MylesBorins MylesBorins removed the lts-agenda label Mar 21, 2016

scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016

tools: run tick processor without forking
Using the tick processor no longer creates temporary files or spawns a
child process.

PR-URL: nodejs#4224
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.