2121
2222'use strict' ;
2323
24+ const { trace } = internalBinding ( 'trace_events' ) ;
2425const {
2526 isStackOverflowError,
2627 codes : {
@@ -37,6 +38,12 @@ const {
3738} = util . types ;
3839const kCounts = Symbol ( 'counts' ) ;
3940
41+ const kTraceConsoleCategory = 'node,node.console' ;
42+ const kTraceCount = 'C' . charCodeAt ( 0 ) ;
43+ const kTraceBegin = 'b' . charCodeAt ( 0 ) ;
44+ const kTraceEnd = 'e' . charCodeAt ( 0 ) ;
45+ const kTraceInstant = 'n' . charCodeAt ( 0 ) ;
46+
4047const {
4148 keys : ObjectKeys ,
4249 values : ObjectValues ,
@@ -230,13 +237,15 @@ Console.prototype.dir = function dir(object, options) {
230237Console . prototype . time = function time ( label = 'default' ) {
231238 // Coerces everything other than Symbol to a string
232239 label = `${ label } ` ;
240+ trace ( kTraceBegin , kTraceConsoleCategory , `time::${ label } ` , 0 ) ;
233241 this . _times . set ( label , process . hrtime ( ) ) ;
234242} ;
235243
236244Console . prototype . timeEnd = function timeEnd ( label = 'default' ) {
237245 // Coerces everything other than Symbol to a string
238246 label = `${ label } ` ;
239247 const hasWarned = timeLogImpl ( this , 'timeEnd' , label ) ;
248+ trace ( kTraceEnd , kTraceConsoleCategory , `time::${ label } ` , 0 ) ;
240249 if ( ! hasWarned ) {
241250 this . _times . delete ( label ) ;
242251 }
@@ -246,6 +255,7 @@ Console.prototype.timeLog = function timeLog(label, ...data) {
246255 // Coerces everything other than Symbol to a string
247256 label = `${ label } ` ;
248257 timeLogImpl ( this , 'timeLog' , label , data ) ;
258+ trace ( kTraceInstant , kTraceConsoleCategory , `time::${ label } ` , 0 ) ;
249259} ;
250260
251261// Returns true if label was not found
@@ -306,6 +316,7 @@ Console.prototype.count = function count(label = 'default') {
306316 else
307317 count ++ ;
308318 counts . set ( label , count ) ;
319+ trace ( kTraceCount , kTraceConsoleCategory , `count::${ label } ` , 0 , count ) ;
309320 this . log ( `${ label } : ${ count } ` ) ;
310321} ;
311322
@@ -315,6 +326,7 @@ Console.prototype.count = function count(label = 'default') {
315326// the counter from being a memory leak.
316327Console . prototype . countReset = function countReset ( label = 'default' ) {
317328 const counts = this [ kCounts ] ;
329+ trace ( kTraceCount , kTraceConsoleCategory , `count::${ label } ` , 0 , 0 ) ;
318330 counts . delete ( `${ label } ` ) ;
319331} ;
320332
0 commit comments