Uh oh!
There was an error while loading. Please reload this page.
util: add debugtest utility - #33424
Conversation
devsnek
commented
May 15, 2020
I feel like we need better namespacing here. Maybe split into |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
targos
commented
May 15, 2020
Is V8 able to completely eliminate the branch when the value is |
bmeck
commented
May 15, 2020
@devsnek that would be adding an alias to the existing function and i'm not sure what we get except moving a @targos per my testing, yes. I was using: node --allow-natives-syntax --code-comments --print-code --print-code-verbose -e 'const test=require("util").debugtest("foo"); function easy_foo() {if (test) return; return [1,'2',null];};%OptimizeFunctionOnNextCall(easy_foo);easy_foo()' |
Uh oh!
There was an error while loading. Please reload this page.
jasnell
commented
May 15, 2020
There are a couple of possible alternative approaches here, since constdebug=util.debuglog('test');// What debug log currently does...debug('how we do it currently');// Add an additional function off `debug` that invokes the given function// only if the category is enabled.debug.do(()=>{// Do something here})And / Or Another modification we could make here would be similar to what we did on the C++ level const{ debuglog }=require('util');constdebug=debuglog('foo');constobj{[debuglog.debug](){return'abc';}};debug('something happened: %s',obj);This would obviously take a bit of work on the internals to account for the symbol but in the default case (debug off) it would not incur any additional cost. |
bmeck
commented
May 16, 2020
@jasnell per the alternatives:
|
BridgeAR
commented
May 16, 2020
@jasnell@bmeck it is already possible to use constdebug=require('util').debuglog('test')debug('Lazy property inspection: %o',{works: true})// TEST 123456: Lazy property inspection: { works: true }If we want to add more powerful lazy evaluations, I'd favor to use |
jasnell
commented
May 16, 2020
The point about having to use Thinking through it more, @devsnek's comment here #33424 (comment) makes a lot of sense ... that is, replacing the constdebug=util.debug('test');debug('some output: %s','a');debug.do((a)=>{/* ... */},'a');if(debug.enabled){/* ... */} |
I'm not sure on the need for a util.debug: (section: string)=>{log(...): typeofdebuglog,enabled: boolean};Is fine I can move the PR to that, I'm not sure I understand the desire for the namespace itself to be a function. |
jasnell
commented
May 29, 2020
The namespace being a function just makes the transition from the current model a bit easier in my opinion but it's not critical |
bmeck
commented
May 29, 2020
@jasnell If the goal is transition ease; would it make it easier if this was just an alias and we added |
jasnell
commented
May 29, 2020
Yes that works |
Keeping the ENV parsing lazy means |
bmeck
commented
May 29, 2020
I've pushed up changes so that
In both a getter form and a method form V8 does not optimize |
8ae28ff to
2935f72Comparebmeck
commented
Jun 12, 2020
#32260 landed an undocumented API change that causes a callback to be fired with the logger or |
bmeck
commented
Jun 12, 2020
reopening, i misunderstood how that callback works. made a PR to doc it, but this PR still has utility by avoiding the call to the logger in order to set the boolean. |
bmeck
commented
Jun 12, 2020
rebased due to changes with util.debuglog implementation. |
nodejs-github-bot
commented
Aug 7, 2020
bmeck
commented
Aug 10, 2020
Landed in 7f5da53c7972 |
@bmeck I think you've pushed the wrong commits up to master (the ones that were pushed don't appear to have metadata added): |
richardlau
commented
Aug 10, 2020
Looks like @himself65 force pushed them out: https://github.com/orgs/nodejs/teams/collaborators/discussions/105. I'll reopen this one as it will need to be relanded. |
bmeck
commented
Aug 10, 2020
@richardlau i went through git node land so i'm unclear how this occurred, checking my master branch (from which i ran I'm unclear what to do here to reland since my master matches what i expected and i don't want to repush the wrong commits |
PR-URL: nodejs#33424 Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #33424 Reviewed-By: James M Snell <jasnell@gmail.com>
bmeck
commented
Aug 10, 2020
Landed in bcfb176 |
PR-URL: #33424 Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #33424 Reviewed-By: James M Snell <jasnell@gmail.com>


Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesCurrently we have a
debuglogutility to allow logging when debugging. This PR introduces a corollarydebugtestutility to see if something is being debugged rather than logging. This would allow people usingdebuglogstyle conditional debugging to avoid doing unnecessary work such as creating strings etc. For example:Would always stringify the object, even if
foois not being debugged. Additionally, it would allow branching to add additional debugging logic that may be undesirable when not debugging. For example: