summaryrefslogtreecommitdiff
path: root/lib/console.js
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2018-10-16 13:57:24 -0700
committerJames M Snell <jasnell@gmail.com>2018-10-18 15:00:29 -0700
commit9c82a1e7ba8d5ce7e743f99348cf992965594f0a (patch)
tree0798e31149661c2d29181fd1beb14dc4958027d0 /lib/console.js
parentbf7ed80475cfa7ae1ab6086c325f57557b75dffe (diff)
downloadandroid-node-v8-9c82a1e7ba8d5ce7e743f99348cf992965594f0a.tar.gz
android-node-v8-9c82a1e7ba8d5ce7e743f99348cf992965594f0a.tar.bz2
android-node-v8-9c82a1e7ba8d5ce7e743f99348cf992965594f0a.zip
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 <luigipinca@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Diffstat (limited to 'lib/console.js')
-rw-r--r--lib/console.js13
1 files changed, 12 insertions, 1 deletions
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}`);
};