You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
--cpu-prof-name 'CPU.${pid}.cpuprofile' doesn't replace the placeholder #57418
If --cpu-prof-name is not specified, the generated profile is named CPU.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.cpuprofile.
I expect to be able to use those placeholder when I specify a name, especially when I use the cluster module to avoid having all the profiling overriding each others.
I expected the filename to be CPU.43689.cpuprofile
It looks like either a misunderstanding of what the doc says, or that the doc not being clear enough that the argument is not a pattern that will be filled by Node.js. The doc specifically says:
If --cpu-prof-name is not specified, ...
which is not to be interpreted as "if it IS specified, Node.js will fill in the blank using a user-provided pattern". Rather, it means "if it IS specified, the name provided will be used as-is".
@BourgoisMickael I was writing the docs and trying out the parameter myself. Calling node --cpu-prof --cpu-prof-name 'CPU.${pid}.cpuprofile' I obtain the same output as you, but calling node --cpu-prof --cpu-prof-name "CPU.${pid}.cpuprofile" (using double quotes) actually outputs a file with the pid in the name. Could you try it? Please note that I'm on windows at the moment.
EDIT: after trying it on wsl, using double quotes I get a file with the name CPU..cpuprofile, so the behaviour could be OS dependent.
Using double quotes or no quotes will trigger the substitution and replace it with the value of the variable pid or an empty string.
So on linux you end up sending --cpu-prof-name CPU..cpuprofile to the process. Hence the use of single quotes to send the literal string ${pid} as argumen without shell substitution.
It doesn't seem like a big change to be able to handle pattern as name if it's already available when name is not provided
Oof, I didn't know that I'm sorry.
I agree with you that it does not seem like a big change, I'll keep the docs PR open until a more experienced contributor will give some feedback.
I added the feature request label because it might actually be worthwhile exploring implementing this kind of replacement in the future. I agree that in the near term clarifying the docs is the best next step.
Activity
joyeecheung commentedon Mar 12, 2025
It looks like either a misunderstanding of what the doc says, or that the doc not being clear enough that the argument is not a pattern that will be filled by Node.js. The doc specifically says:
which is not to be interpreted as "if it IS specified, Node.js will fill in the blank using a user-provided pattern". Rather, it means "if it IS specified, the name provided will be used as-is".
joyeecheung commentedon Mar 12, 2025
labeling good first issue, I think it should be fixed by clarifying the docs that what's expected in the OP is not going to happen instead.
BourgoisMickael commentedon Mar 13, 2025
@joyeecheung could we have it as a feature to be able to use a pattern with placeholder in the name ?
Otherwise, using it with the cluster module, each process would overwrite the same file.
cecia234 commentedon Mar 13, 2025
@BourgoisMickael I was writing the docs and trying out the parameter myself. Calling
node --cpu-prof --cpu-prof-name 'CPU.${pid}.cpuprofile'I obtain the same output as you, but callingnode --cpu-prof --cpu-prof-name "CPU.${pid}.cpuprofile"(using double quotes) actually outputs a file with the pid in the name. Could you try it? Please note that I'm on windows at the moment.EDIT: after trying it on wsl, using double quotes I get a file with the name
CPU..cpuprofile, so the behaviour could be OS dependent.BourgoisMickael commentedon Mar 13, 2025
@cecia234 The
${}syntax is a parameter substitution/expansion in shell (https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html).Using double quotes or no quotes will trigger the substitution and replace it with the value of the variable
pidor an empty string.So on linux you end up sending
--cpu-prof-name CPU..cpuprofileto the process. Hence the use of single quotes to send the literal string${pid}as argumen without shell substitution.It doesn't seem like a big change to be able to handle pattern as name if it's already available when name is not provided
cecia234 commentedon Mar 13, 2025
Oof, I didn't know that I'm sorry.
I agree with you that it does not seem like a big change, I'll keep the docs PR open until a more experienced contributor will give some feedback.
jasnell commentedon Mar 13, 2025
I added the
feature requestlabel because it might actually be worthwhile exploring implementing this kind of replacement in the future. I agree that in the near term clarifying the docs is the best next step.6 remaining items
cli: clarify --cpu-prof-name allowed values
cli: clarify --cpu-prof-name allowed values
cli: clarify --cpu-prof-name allowed values
cli: clarify --cpu-prof-name allowed values
cli: clarify --cpu-prof-name allowed values
cli: clarify --cpu-prof-name allowed values
theanarkh commentedon May 10, 2025
You can submit an PR directly !
cli: support `${pid}` placeholder in --cpu-prof-name
cli: support `${pid}` placeholder in --cpu-prof-name
cli: support `${pid}` placeholder in --cpu-prof-name