Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cfeed2b

Browse filesBrowse files
jasnelltargos
authored andcommitted
trace_events: add support for builtin trace
PR-URL: #21899 Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
1 parent b56c8ad commit cfeed2b
Copy full SHA for cfeed2b

File tree

Expand file treeCollapse file tree

4 files changed

+126
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+126
-3
lines changed
Open diff view settings
Collapse file

‎benchmark/misc/trace.js‎

Copy file name to clipboard
+75Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
5+
const bench = common.createBenchmark(main, {
6+
n: [100000],
7+
method: ['trace', 'emit', 'isTraceCategoryEnabled', 'categoryGroupEnabled']
8+
}, {
9+
flags: ['--expose-internals', '--trace-event-categories', 'foo']
10+
});
11+
12+
const {
13+
trace,
14+
isTraceCategoryEnabled,
15+
emit,
16+
categoryGroupEnabled
17+
} = process.binding('trace_events');
18+
19+
const {
20+
TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent
21+
} = process.binding('constants').trace;
22+
23+
function doEmit(n) {
24+
bench.start();
25+
for (var i = 0; i < n; i++) {
26+
emit(kBeforeEvent, 'foo', 'test', 0, 'arg1', 1);
27+
}
28+
bench.end(n);
29+
}
30+
31+
function doTrace(n) {
32+
bench.start();
33+
for (var i = 0; i < n; i++) {
34+
trace(kBeforeEvent, 'foo', 'test', 0, 'test');
35+
}
36+
bench.end(n);
37+
}
38+
39+
function doIsTraceCategoryEnabled(n) {
40+
bench.start();
41+
for (var i = 0; i < n; i++) {
42+
isTraceCategoryEnabled('foo');
43+
isTraceCategoryEnabled('bar');
44+
}
45+
bench.end(n);
46+
}
47+
48+
function doCategoryGroupEnabled(n) {
49+
bench.start();
50+
for (var i = 0; i < n; i++) {
51+
categoryGroupEnabled('foo');
52+
categoryGroupEnabled('bar');
53+
}
54+
bench.end(n);
55+
}
56+
57+
function main({ n, method }) {
58+
switch (method) {
59+
case '':
60+
case 'trace':
61+
doTrace(n);
62+
break;
63+
case 'emit':
64+
doEmit(n);
65+
break;
66+
case 'isTraceCategoryEnabled':
67+
doIsTraceCategoryEnabled(n);
68+
break;
69+
case 'categoryGroupEnabled':
70+
doCategoryGroupEnabled(n);
71+
break;
72+
default:
73+
throw new Error(`Unexpected method "${method}"`);
74+
}
75+
}
Collapse file

‎src/node_constants.cc‎

Copy file name to clipboardExpand all lines: src/node_constants.cc
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,35 @@ void DefineDLOpenConstants(Local<Object> target) {
12821282
#endif
12831283
}
12841284

1285+
void DefineTraceConstants(Local<Object> target) {
1286+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_BEGIN);
1287+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_END);
1288+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_COMPLETE);
1289+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_INSTANT);
1290+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_ASYNC_BEGIN);
1291+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_ASYNC_STEP_INTO);
1292+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_ASYNC_STEP_PAST);
1293+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_ASYNC_END);
1294+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN);
1295+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_NESTABLE_ASYNC_END);
1296+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT);
1297+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_FLOW_BEGIN);
1298+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_FLOW_STEP);
1299+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_FLOW_END);
1300+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_METADATA);
1301+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_COUNTER);
1302+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_SAMPLE);
1303+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_CREATE_OBJECT);
1304+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_SNAPSHOT_OBJECT);
1305+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_DELETE_OBJECT);
1306+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_MEMORY_DUMP);
1307+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_MARK);
1308+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_CLOCK_SYNC);
1309+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_ENTER_CONTEXT);
1310+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_LEAVE_CONTEXT);
1311+
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_LINK_IDS);
1312+
}
1313+
12851314
} // anonymous namespace
12861315

12871316
void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
@@ -1315,6 +1344,10 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
13151344
CHECK(dlopen_constants->SetPrototype(env->context(),
13161345
Null(env->isolate())).FromJust());
13171346

1347+
Local<Object> trace_constants = Object::New(isolate);
1348+
CHECK(trace_constants->SetPrototype(env->context(),
1349+
Null(env->isolate())).FromJust());
1350+
13181351
DefineErrnoConstants(err_constants);
13191352
DefineWindowsErrorConstants(err_constants);
13201353
DefineSignalConstants(sig_constants);
@@ -1323,6 +1356,7 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
13231356
DefineCryptoConstants(crypto_constants);
13241357
DefineZlibConstants(zlib_constants);
13251358
DefineDLOpenConstants(dlopen_constants);
1359+
DefineTraceConstants(trace_constants);
13261360

13271361
// Define libuv constants.
13281362
NODE_DEFINE_CONSTANT(os_constants, UV_UDP_REUSEADDR);
@@ -1334,6 +1368,7 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
13341368
target->Set(OneByteString(isolate, "fs"), fs_constants);
13351369
target->Set(OneByteString(isolate, "crypto"), crypto_constants);
13361370
target->Set(OneByteString(isolate, "zlib"), zlib_constants);
1371+
target->Set(OneByteString(isolate, "trace"), trace_constants);
13371372
}
13381373

13391374
} // namespace node
Collapse file

‎src/node_trace_events.cc‎

Copy file name to clipboardExpand all lines: src/node_trace_events.cc
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ void Initialize(Local<Object> target,
232232

233233
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "CategorySet"),
234234
category_set->GetFunction());
235+
236+
Local<String> isTraceCategoryEnabled =
237+
FIXED_ONE_BYTE_STRING(env->isolate(), "isTraceCategoryEnabled");
238+
Local<String> trace = FIXED_ONE_BYTE_STRING(env->isolate(), "trace");
239+
240+
// Grab the trace and isTraceCategoryEnabled intrinsics from the binding
241+
// object and expose those to our binding layer.
242+
Local<Object> binding = context->GetExtrasBindingObject();
243+
target->Set(context, isTraceCategoryEnabled,
244+
binding->Get(context, isTraceCategoryEnabled).ToLocalChecked())
245+
.FromJust();
246+
target->Set(context, trace,
247+
binding->Get(context, trace).ToLocalChecked()).FromJust();
235248
}
236249

237250
} // namespace node
Collapse file

‎test/parallel/test-binding-constants.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-binding-constants.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const constants = process.binding('constants');
55
const assert = require('assert');
66

77
assert.deepStrictEqual(
8-
Object.keys(constants).sort(), ['crypto', 'fs', 'os', 'zlib']
8+
Object.keys(constants).sort(), ['crypto', 'fs', 'os', 'trace', 'zlib']
99
);
1010

1111
assert.deepStrictEqual(
@@ -26,6 +26,6 @@ function test(obj) {
2626
}
2727

2828
[
29-
constants, constants.crypto, constants.fs, constants.os, constants.zlib,
30-
constants.os.dlopen, constants.os.errno, constants.os.signals
29+
constants, constants.crypto, constants.fs, constants.os, constants.trace,
30+
constants.zlib, constants.os.dlopen, constants.os.errno, constants.os.signals
3131
].forEach(test);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.