GeezerVison is showing github.com — trace_events: add support for builtin trace · nodejs/node@cfeed2b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +75Lines changed: 75 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboardExpand all lines: src/node_constants.cc +35Lines changed: 35 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1282,6 +1282,35 @@ void DefineDLOpenConstants(Local<Object> target) { | 1282 | 1282 | #endif | 1283 | 1283 | } | 1284 | 1284 |
| | 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 | + | 1285 | 1314 | } // anonymous namespace | 1286 | 1315 |
| 1287 | 1316 | void DefineConstants(v8::Isolate* isolate, Local<Object> target) { | @@ -1315,6 +1344,10 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) { | 1315 | 1344 | CHECK(dlopen_constants->SetPrototype(env->context(), | 1316 | 1345 | Null(env->isolate())).FromJust()); | 1317 | 1346 |
| | 1347 | + Local<Object> trace_constants = Object::New(isolate); | | 1348 | + CHECK(trace_constants->SetPrototype(env->context(), | | 1349 | + Null(env->isolate())).FromJust()); | | 1350 | + | 1318 | 1351 | DefineErrnoConstants(err_constants); | 1319 | 1352 | DefineWindowsErrorConstants(err_constants); | 1320 | 1353 | DefineSignalConstants(sig_constants); | @@ -1323,6 +1356,7 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) { | 1323 | 1356 | DefineCryptoConstants(crypto_constants); | 1324 | 1357 | DefineZlibConstants(zlib_constants); | 1325 | 1358 | DefineDLOpenConstants(dlopen_constants); | | 1359 | + DefineTraceConstants(trace_constants); | 1326 | 1360 |
| 1327 | 1361 | // Define libuv constants. | 1328 | 1362 | NODE_DEFINE_CONSTANT(os_constants, UV_UDP_REUSEADDR); | @@ -1334,6 +1368,7 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) { | 1334 | 1368 | target->Set(OneByteString(isolate, "fs"), fs_constants); | 1335 | 1369 | target->Set(OneByteString(isolate, "crypto"), crypto_constants); | 1336 | 1370 | target->Set(OneByteString(isolate, "zlib"), zlib_constants); | | 1371 | + target->Set(OneByteString(isolate, "trace"), trace_constants); | 1337 | 1372 | } | 1338 | 1373 |
| 1339 | 1374 | } // namespace node |
Collapse file Copy file name to clipboardExpand all lines: src/node_trace_events.cc +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -232,6 +232,19 @@ void Initialize(Local<Object> target, | 232 | 232 |
| 233 | 233 | target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "CategorySet"), | 234 | 234 | 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(); | 235 | 248 | } | 236 | 249 |
| 237 | 250 | } // namespace node | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-binding-constants.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,7 +5,7 @@ const constants = process.binding('constants'); | 5 | 5 | const assert = require('assert'); | 6 | 6 |
| 7 | 7 | assert.deepStrictEqual( | 8 | | - Object.keys(constants).sort(), ['crypto', 'fs', 'os', 'zlib'] | | 8 | + Object.keys(constants).sort(), ['crypto', 'fs', 'os', 'trace', 'zlib'] | 9 | 9 | ); | 10 | 10 |
| 11 | 11 | assert.deepStrictEqual( | @@ -26,6 +26,6 @@ function test(obj) { | 26 | 26 | } | 27 | 27 |
| 28 | 28 | [ | 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 | 31 | 31 | ].forEach(test); |
|