From 9c82a1e7ba8d5ce7e743f99348cf992965594f0a Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 16 Oct 2018 13:57:24 -0700 Subject: console: add trace-events for time and count Add the `node.console` trace event category to capture `console.count()`, `console.countReset()`, `console.time()`, `console.timeLog()`, and `console.timeEnd()` to the trace event log. PR-URL: https://github.com/nodejs/node/pull/23703 Reviewed-By: Luigi Pinca Reviewed-By: Richard Lau --- lib/console.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/console.js') diff --git a/lib/console.js b/lib/console.js index c254a3889b..96bd185585 100644 --- a/lib/console.js +++ b/lib/console.js @@ -21,6 +21,7 @@ 'use strict'; +const { trace } = internalBinding('trace_events'); const { isStackOverflowError, codes: { @@ -37,6 +38,12 @@ const { } = util.types; const kCounts = Symbol('counts'); +const kTraceConsoleCategory = 'node,node.console'; +const kTraceCount = 'C'.charCodeAt(0); +const kTraceBegin = 'b'.charCodeAt(0); +const kTraceEnd = 'e'.charCodeAt(0); +const kTraceInstant = 'n'.charCodeAt(0); + const { keys: ObjectKeys, values: ObjectValues, @@ -232,6 +239,7 @@ Console.prototype.time = function time(label = 'default') { process.emitWarning(`Label '${label}' already exists for console.time()`); return; } + trace(kTraceBegin, kTraceConsoleCategory, `time::${label}`, 0); this._times.set(label, process.hrtime()); }; @@ -239,6 +247,7 @@ Console.prototype.timeEnd = function timeEnd(label = 'default') { // Coerces everything other than Symbol to a string label = `${label}`; const hasWarned = timeLogImpl(this, 'timeEnd', label); + trace(kTraceEnd, kTraceConsoleCategory, `time::${label}`, 0); if (!hasWarned) { this._times.delete(label); } @@ -248,6 +257,7 @@ Console.prototype.timeLog = function timeLog(label, ...data) { // Coerces everything other than Symbol to a string label = `${label}`; timeLogImpl(this, 'timeLog', label, data); + trace(kTraceInstant, kTraceConsoleCategory, `time::${label}`, 0); }; // Returns true if label was not found @@ -308,6 +318,7 @@ Console.prototype.count = function count(label = 'default') { else count++; counts.set(label, count); + trace(kTraceCount, kTraceConsoleCategory, `count::${label}`, 0, count); this.log(`${label}: ${count}`); }; @@ -318,7 +329,7 @@ Console.prototype.countReset = function countReset(label = 'default') { process.emitWarning(`Count for '${label}' does not exist`); return; } - + trace(kTraceCount, kTraceConsoleCategory, `count::${label}`, 0, 0); counts.delete(`${label}`); }; -- cgit v1.2.3