-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
console: implement timeLog method #21312
Conversation
lib/console.js
Outdated
@@ -234,6 +234,19 @@ Console.prototype.time = function time(label = 'default') { | |||
this._times.set(label, process.hrtime()); | |||
}; | |||
|
|||
Console.prototype.timeLog = function timeLog(label = 'default', ...data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the function name printed in the process warning, couldn't Console.prototype.timeEnd()
be updated to call this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Barring spec changes, this looks great.
doc/api/console.md
Outdated
* `label` {string} **Default:** `'default'` | ||
* `...data` {any} | ||
|
||
For a timer that was previously started by calling [`console.time()`)][], prints |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra parenthesis in [`console.time()`)][]
.
doc/api/console.md
Outdated
|
||
```js | ||
console.time('process'); | ||
const value = expensiveProcess1(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment that value
is 42
here? Otherwise, it is a bit unexpected below.
doc/api/console.md
Outdated
console.time('process'); | ||
const value = expensiveProcess1(); | ||
console.timeLog('process', value); | ||
// Prints process: 365.227ms 42 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a bit confusing. Maybe something like // Prints "process: 365.227ms 42".
?
Should we document the separator that joins several |
doc/api/console.md
Outdated
@@ -392,6 +392,25 @@ are identified by a unique `label`. Use the same `label` when calling | |||
[`console.timeEnd()`][] to stop the timer and output the elapsed time in | |||
milliseconds to `stdout`. Timer durations are accurate to the sub-millisecond. | |||
|
|||
### console.timeLog([label][, ...data]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this should go after ### console.timeEnd(label)
section ABC-wise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No strong opinion but this document doesn't seem to follow the ABC rule and I went for the spec order. It's also the order in which you call the methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All console.
methods seem to be in ABC order according to the TOC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I didn't see that inspector methods were in another section
@cjihrig I refactored the common code in a separate function. PTAL.
I don't know. It's just using |
@targos Then we can land as is and if anybody is sure how to document this (if needed), this can be done in another PR) |
console.timeLog('process', value); | ||
// Prints "process: 365.227ms 42". | ||
doExpensiveProcess2(value); | ||
console.timeEnd('process'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will print a warning about no process label
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not supposed to. timeLog
shouldn't clear the timer.
lib/console.js
Outdated
this.log('%s: %sms', label, ms.toFixed(3)); | ||
this._times.delete(label); | ||
}; | ||
this.log('%s: %sms', label, ms.toFixed(3), ...data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I personally would prefer to just check if data is undefined by adding a if / else
but as the function is not hot, that is just a non-blocking recommendation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that 👍
Looks like this failed across the board. |
Upstream PR landed: https://console.spec.whatwg.org/#timelog |
CI before landing: https://ci.nodejs.org/job/node-test-pull-request/15728/ |
Landed in b016745 |
Refs: whatwg/console#138 PR-URL: #21312 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Refs: whatwg/console#138 PR-URL: #21312 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Notable changes: * console: * The `console.timeLog()` method has been implemented. (#21312) * deps: * Upgrade to libuv 1.22.0. (#21731) * Upgrade to ICU 62.1 (Unicode 11, CLDR 33.1). (#21728) * http: * Added support for passing both `timeout` and `agent` options to `http.request`. (#21204) * napi: * Added experimental support for functions dealing with bigint numbers. (#21226) * process: * The `process.hrtime.bigint()` method has been implemented. (#21256) * Added the `--title` command line argument to set the process title on startup. (#21477) * trace_events: * Added process_name metadata. (#21477)
Notable changes: * console: * The `console.timeLog()` method has been implemented. (#21312) * deps: * Upgrade to libuv 1.22.0. (#21731) * Upgrade to ICU 62.1 (Unicode 11, CLDR 33.1). (#21728) * http: * Added support for passing both `timeout` and `agent` options to `http.request`. (#21204) * napi: * Added experimental support for functions dealing with bigint numbers. (#21226) * process: * The `process.hrtime.bigint()` method has been implemented. (#21256) * Added the `--title` command line argument to set the process title on startup. (#21477) * trace_events: * Added process_name metadata. (#21477) * Added new collaborators * codebytere - Shelley Vohr PR-URL: #21851
Notable changes: * console: * The `console.timeLog()` method has been implemented. (#21312) * deps: * Upgrade to libuv 1.22.0. (#21731) * Upgrade to ICU 62.1 (Unicode 11, CLDR 33.1). (#21728) * http: * Added support for passing both `timeout` and `agent` options to `http.request`. (#21204) * inspector: * Expose the original console API in `require('inspector').console`. (#21659) * napi: * Added experimental support for functions dealing with bigint numbers. (#21226) * process: * The `process.hrtime.bigint()` method has been implemented. (#21256) * Added the `--title` command line argument to set the process title on startup. (#21477) * trace_events: * Added process_name metadata. (#21477) * Added new collaborators * codebytere - Shelley Vohr PR-URL: #21851
Notable changes: * console: * The `console.timeLog()` method has been implemented. (#21312) * deps: * Upgrade to libuv 1.22.0. (#21731) * Upgrade to ICU 62.1 (Unicode 11, CLDR 33.1). (#21728) * http: * Added support for passing both `timeout` and `agent` options to `http.request`. (#21204) * inspector: * Expose the original console API in `require('inspector').console`. (#21659) * napi: * Added experimental support for functions dealing with bigint numbers. (#21226) * process: * The `process.hrtime.bigint()` method has been implemented. (#21256) * Added the `--title` command line argument to set the process title on startup. (#21477) * trace_events: * Added process_name metadata. (#21477) * Added new collaborators * codebytere - Shelley Vohr PR-URL: #21851
Refs: whatwg/console#138
Marking blocked until the spec PR lands.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes