21
21
22
22
'use strict' ;
23
23
24
+ const { trace } = internalBinding ( 'trace_events' ) ;
24
25
const {
25
26
isStackOverflowError,
26
27
codes : {
@@ -37,6 +38,12 @@ const {
37
38
} = util . types ;
38
39
const kCounts = Symbol ( 'counts' ) ;
39
40
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
+
40
47
const {
41
48
keys : ObjectKeys ,
42
49
values : ObjectValues ,
@@ -232,13 +239,15 @@ Console.prototype.time = function time(label = 'default') {
232
239
process . emitWarning ( `Label '${ label } ' already exists for console.time()` ) ;
233
240
return ;
234
241
}
242
+ trace ( kTraceBegin , kTraceConsoleCategory , `time::${ label } ` , 0 ) ;
235
243
this . _times . set ( label , process . hrtime ( ) ) ;
236
244
} ;
237
245
238
246
Console . prototype . timeEnd = function timeEnd ( label = 'default' ) {
239
247
// Coerces everything other than Symbol to a string
240
248
label = `${ label } ` ;
241
249
const hasWarned = timeLogImpl ( this , 'timeEnd' , label ) ;
250
+ trace ( kTraceEnd , kTraceConsoleCategory , `time::${ label } ` , 0 ) ;
242
251
if ( ! hasWarned ) {
243
252
this . _times . delete ( label ) ;
244
253
}
@@ -248,6 +257,7 @@ Console.prototype.timeLog = function timeLog(label, ...data) {
248
257
// Coerces everything other than Symbol to a string
249
258
label = `${ label } ` ;
250
259
timeLogImpl ( this , 'timeLog' , label , data ) ;
260
+ trace ( kTraceInstant , kTraceConsoleCategory , `time::${ label } ` , 0 ) ;
251
261
} ;
252
262
253
263
// Returns true if label was not found
@@ -308,6 +318,7 @@ Console.prototype.count = function count(label = 'default') {
308
318
else
309
319
count ++ ;
310
320
counts . set ( label , count ) ;
321
+ trace ( kTraceCount , kTraceConsoleCategory , `count::${ label } ` , 0 , count ) ;
311
322
this . log ( `${ label } : ${ count } ` ) ;
312
323
} ;
313
324
@@ -318,7 +329,7 @@ Console.prototype.countReset = function countReset(label = 'default') {
318
329
process . emitWarning ( `Count for '${ label } ' does not exist` ) ;
319
330
return ;
320
331
}
321
-
332
+ trace ( kTraceCount , kTraceConsoleCategory , `count:: ${ label } ` , 0 , 0 ) ;
322
333
counts . delete ( `${ label } ` ) ;
323
334
} ;
324
335
0 commit comments