| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent df608e0 commit c1e4f73
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,7 +35,7 @@ const { | |||
| 35 | 35 | SymbolToStringTag, | |
| 36 | 36 | } = primordials; | |
| 37 | 37 | ||
| 38 | - const { trace } = internalBinding('trace_events'); | ||
| 38 | + const { trace, nodeTraceEventCategory, kTraceCount } = require('internal/trace_events'); | ||
| 39 | 39 | const { | |
| 40 | 40 | codes: { | |
| 41 | 41 | ERR_CONSOLE_WRITABLE_STREAM, | |
@@ -59,9 +59,6 @@ const { | |||
| 59 | 59 | const { | |
| 60 | 60 | isTypedArray, isSet, isMap, isSetIterator, isMapIterator, | |
| 61 | 61 | } = require('internal/util/types'); | |
| 62 | - const { | ||
| 63 | - CHAR_UPPERCASE_C: kTraceCount, | ||
| 64 | - } = require('internal/constants'); | ||
| 65 | 62 | const kCounts = Symbol('counts'); | |
| 66 | 63 | const { time, timeLog, timeEnd, kNone } = require('internal/util/debuglog'); | |
| 67 | 64 | const { channel } = require('diagnostics_channel'); | |
@@ -72,7 +69,7 @@ const onError = channel('console.error'); | |||
| 72 | 69 | const onInfo = channel('console.info'); | |
| 73 | 70 | const onDebug = channel('console.debug'); | |
| 74 | 71 | ||
| 75 | - const kTraceConsoleCategory = 'node,node.console'; | ||
| 72 | + const kTraceConsoleCategory = nodeTraceEventCategory('node.console'); | ||
| 76 | 73 | ||
| 77 | 74 | const kMaxGroupIndentation = 1000; | |
| 78 | 75 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,9 @@ module.exports = { | |||
| 9 | 9 | CHAR_UPPERCASE_Z: 90, /* Z */ | |
| 10 | 10 | CHAR_LOWERCASE_Z: 122, /* z */ | |
| 11 | 11 | CHAR_UPPERCASE_C: 67, /* C */ | |
| 12 | + CHAR_UPPERCASE_B: 66, /* B */ | ||
| 12 | 13 | CHAR_LOWERCASE_B: 98, /* b */ | |
| 14 | + CHAR_UPPERCASE_E: 69, /* E */ | ||
| 13 | 15 | CHAR_LOWERCASE_E: 101, /* e */ | |
| 14 | 16 | CHAR_LOWERCASE_N: 110, /* n */ | |
| 15 | 17 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,11 +9,13 @@ const { | |||
| 9 | 9 | } = primordials; | |
| 10 | 10 | ||
| 11 | 11 | const { setUnrefTimeout } = require('internal/timers'); | |
| 12 | - const { getCategoryEnabledBuffer, trace } = internalBinding('trace_events'); | ||
| 13 | 12 | const { | |
| 14 | - CHAR_LOWERCASE_B, | ||
| 15 | - CHAR_LOWERCASE_E, | ||
| 16 | - } = require('internal/constants'); | ||
| 13 | + getCategoryEnabledBuffer, | ||
| 14 | + trace, | ||
| 15 | + nodeTraceEventCategory, | ||
| 16 | + kAsyncBegin, | ||
| 17 | + kAsyncEnd, | ||
| 18 | + } = require('internal/trace_events'); | ||
| 17 | 19 | ||
| 18 | 20 | const { URL } = require('internal/url'); | |
| 19 | 21 | const { Buffer } = require('buffer'); | |
@@ -48,14 +50,14 @@ function isTraceHTTPEnabled() { | |||
| 48 | 50 | return httpEnabled[0] > 0; | |
| 49 | 51 | } | |
| 50 | 52 | ||
| 51 | - const traceEventCategory = 'node,node.http'; | ||
| 53 | + const traceEventCategory = nodeTraceEventCategory('node.http'); | ||
| 52 | 54 | ||
| 53 | 55 | function traceBegin(...args) { | |
| 54 | - trace(CHAR_LOWERCASE_B, traceEventCategory, ...args); | ||
| 56 | + trace(kAsyncBegin, traceEventCategory, ...args); | ||
| 55 | 57 | } | |
| 56 | 58 | ||
| 57 | 59 | function traceEnd(...args) { | |
| 58 | - trace(CHAR_LOWERCASE_E, traceEventCategory, ...args); | ||
| 60 | + trace(kAsyncEnd, traceEventCategory, ...args); | ||
| 59 | 61 | } | |
| 60 | 62 | ||
| 61 | 63 | function ipToInt(ip) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,56 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const { getCategoryEnabledBuffer, trace, usePerfetto } = internalBinding('trace_events'); | ||
| 4 | + const { | ||
| 5 | + CHAR_UPPERCASE_B, | ||
| 6 | + CHAR_LOWERCASE_B, | ||
| 7 | + CHAR_UPPERCASE_C, | ||
| 8 | + CHAR_LOWERCASE_E, | ||
| 9 | + CHAR_UPPERCASE_E, | ||
| 10 | + CHAR_LOWERCASE_N, | ||
| 11 | + } = require('internal/constants'); | ||
| 12 | + | ||
| 13 | + let nodeTraceEventCategory; | ||
| 14 | + if (usePerfetto) { | ||
| 15 | + nodeTraceEventCategory = (category) => `${category}`; | ||
| 16 | + } else { | ||
| 17 | + nodeTraceEventCategory = (category) => `node,${category}`; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + // The async events describe the execution of a single asynchronous operation, and are | ||
| 21 | + // used to measure the time spent in a single asynchronous operation. | ||
| 22 | + // Async events may overlap with each other. Different events do not have | ||
| 23 | + // to be nested, or FILO (first in last out). | ||
| 24 | + // TODO(legendecas): V8 `trace` API does not support async marks in perfetto yet. | ||
| 25 | + const kAsyncBegin = usePerfetto ? CHAR_UPPERCASE_B : CHAR_LOWERCASE_B; | ||
| 26 | + const kAsyncEnd = usePerfetto ? CHAR_UPPERCASE_E : CHAR_LOWERCASE_E; | ||
| 27 | + | ||
| 28 | + // The sync events describe the execution of a single thread, and are | ||
| 29 | + // used to measure the time spent in a function. | ||
| 30 | + // Sync events must be nested, and are FILO (first in last out), in a stack | ||
| 31 | + // manner. | ||
| 32 | + const kSyncBegin = CHAR_UPPERCASE_B; | ||
| 33 | + const kSyncEnd = CHAR_UPPERCASE_E; | ||
| 34 | + | ||
| 35 | + // Counter events track a named numeric value as it changes over time. Each | ||
| 36 | + // event records the value at a point in time, and the trace viewer renders the | ||
| 37 | + // series as a graph. | ||
| 38 | + // TODO(legendecas): V8 `trace` API does not support count marks in perfetto yet. | ||
| 39 | + const kTraceCount = usePerfetto ? CHAR_LOWERCASE_N : CHAR_UPPERCASE_C; | ||
| 40 | + | ||
| 41 | + // Instant events mark a single moment in time. They have no duration and do | ||
| 42 | + // not need to be paired or nested. | ||
| 43 | + const kTraceInstant = CHAR_LOWERCASE_N; | ||
| 44 | + | ||
| 45 | + module.exports = { | ||
| 46 | + usePerfetto, | ||
| 47 | + getCategoryEnabledBuffer, | ||
| 48 | + trace, | ||
| 49 | + nodeTraceEventCategory, | ||
| 50 | + kAsyncBegin, | ||
| 51 | + kAsyncEnd, | ||
| 52 | + kSyncBegin, | ||
| 53 | + kSyncEnd, | ||
| 54 | + kTraceCount, | ||
| 55 | + kTraceInstant, | ||
| 56 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,20 +7,18 @@ const { | |||
| 7 | 7 | Symbol, | |
| 8 | 8 | } = primordials; | |
| 9 | 9 | ||
| 10 | - const { trace } = internalBinding('trace_events'); | ||
| 10 | + const { | ||
| 11 | + trace, | ||
| 12 | + nodeTraceEventCategory, | ||
| 13 | + kAsyncBegin, | ||
| 14 | + kAsyncEnd, | ||
| 15 | + kSyncBegin, | ||
| 16 | + kSyncEnd, | ||
| 17 | + } = require('internal/trace_events'); | ||
| 11 | 18 | const async_wrap = internalBinding('async_wrap'); | |
| 12 | 19 | const async_hooks = require('async_hooks'); | |
| 13 | - const { | ||
| 14 | - CHAR_LOWERCASE_B, | ||
| 15 | - CHAR_LOWERCASE_E, | ||
| 16 | - } = require('internal/constants'); | ||
| 17 | 20 | ||
| 18 | - // Use small letters such that chrome://tracing groups by the name. | ||
| 19 | - // The behavior is not only useful but the same as the events emitted using | ||
| 20 | - // the specific C++ macros. | ||
| 21 | - const kBeforeEvent = CHAR_LOWERCASE_B; | ||
| 22 | - const kEndEvent = CHAR_LOWERCASE_E; | ||
| 23 | - const kTraceEventCategory = 'node,node.async_hooks'; | ||
| 21 | + const kTraceEventCategory = nodeTraceEventCategory('node.async_hooks'); | ||
| 24 | 22 | ||
| 25 | 23 | const kEnabled = Symbol('enabled'); | |
| 26 | 24 | ||
@@ -45,7 +43,7 @@ function createHook() { | |||
| 45 | 43 | if (nativeProviders.has(type)) return; | |
| 46 | 44 | ||
| 47 | 45 | typeMemory.set(asyncId, type); | |
| 48 | - trace(kBeforeEvent, kTraceEventCategory, | ||
| 46 | + trace(kAsyncBegin, kTraceEventCategory, | ||
| 49 | 47 | type, asyncId, | |
| 50 | 48 | { | |
| 51 | 49 | triggerAsyncId, | |
@@ -57,21 +55,21 @@ function createHook() { | |||
| 57 | 55 | const type = typeMemory.get(asyncId); | |
| 58 | 56 | if (type === undefined) return; | |
| 59 | 57 | ||
| 60 | - trace(kBeforeEvent, kTraceEventCategory, `${type}_CALLBACK`, asyncId); | ||
| 58 | + trace(kSyncBegin, kTraceEventCategory, `${type}_CALLBACK`, asyncId); | ||
| 61 | 59 | }, | |
| 62 | 60 | ||
| 63 | 61 | after(asyncId) { | |
| 64 | 62 | const type = typeMemory.get(asyncId); | |
| 65 | 63 | if (type === undefined) return; | |
| 66 | 64 | ||
| 67 | - trace(kEndEvent, kTraceEventCategory, `${type}_CALLBACK`, asyncId); | ||
| 65 | + trace(kSyncEnd, kTraceEventCategory, `${type}_CALLBACK`, asyncId); | ||
| 68 | 66 | }, | |
| 69 | 67 | ||
| 70 | 68 | destroy(asyncId) { | |
| 71 | 69 | const type = typeMemory.get(asyncId); | |
| 72 | 70 | if (type === undefined) return; | |
| 73 | 71 | ||
| 74 | - trace(kEndEvent, kTraceEventCategory, type, asyncId); | ||
| 72 | + trace(kAsyncEnd, kTraceEventCategory, type, asyncId); | ||
| 75 | 73 | ||
| 76 | 74 | // Cleanup asyncId to type map | |
| 77 | 75 | typeMemory.delete(asyncId); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,13 +14,15 @@ const { | |||
| 14 | 14 | StringPrototypeToLowerCase, | |
| 15 | 15 | StringPrototypeToUpperCase, | |
| 16 | 16 | } = primordials; | |
| 17 | - const { | ||
| 18 | - CHAR_LOWERCASE_B: kTraceBegin, | ||
| 19 | - CHAR_LOWERCASE_E: kTraceEnd, | ||
| 20 | - CHAR_LOWERCASE_N: kTraceInstant, | ||
| 21 | - } = require('internal/constants'); | ||
| 22 | 17 | const { inspect, format, formatWithOptions } = require('internal/util/inspect'); | |
| 23 | - const { getCategoryEnabledBuffer, trace } = internalBinding('trace_events'); | ||
| 18 | + const { | ||
| 19 | + getCategoryEnabledBuffer, | ||
| 20 | + trace, | ||
| 21 | + nodeTraceEventCategory, | ||
| 22 | + kAsyncBegin, | ||
| 23 | + kAsyncEnd, | ||
| 24 | + kTraceInstant, | ||
| 25 | + } = require('internal/trace_events'); | ||
| 24 | 26 | ||
| 25 | 27 | // `debugImpls` and `testEnabled` are deliberately not initialized so any call | |
| 26 | 28 | // to `debuglog()` before `initializeDebugEnv()` is called will throw. | |
@@ -246,7 +248,7 @@ function time(timesStore, traceCategory, implementation, timerFlags, logLabel = | |||
| 246 | 248 | ||
| 247 | 249 | if ((timerFlags & kSkipTrace) === 0) { | |
| 248 | 250 | traceLabel = safeTraceLabel(traceLabel); | |
| 249 | - trace(kTraceBegin, traceCategory, traceLabel, 0); | ||
| 251 | + trace(kAsyncBegin, traceCategory, traceLabel, 0); | ||
| 250 | 252 | } | |
| 251 | 253 | ||
| 252 | 254 | timesStore.set(logLabel, process.hrtime()); | |
@@ -286,7 +288,7 @@ function timeEnd( | |||
| 286 | 288 | ||
| 287 | 289 | if ((timerFlags & kSkipTrace) === 0) { | |
| 288 | 290 | traceLabel = safeTraceLabel(traceLabel); | |
| 289 | - trace(kTraceEnd, traceCategory, traceLabel, 0); | ||
| 291 | + trace(kAsyncEnd, traceCategory, traceLabel, 0); | ||
| 290 | 292 | } | |
| 291 | 293 | ||
| 292 | 294 | timesStore.delete(logLabel); | |
@@ -385,7 +387,7 @@ function debugWithTimer(set, cb) { | |||
| 385 | 387 | ); | |
| 386 | 388 | } | |
| 387 | 389 | ||
| 388 | - const traceCategory = `node,node.${StringPrototypeToLowerCase(set)}`; | ||
| 390 | + const traceCategory = nodeTraceEventCategory(`node.${StringPrototypeToLowerCase(set)}`); | ||
| 389 | 391 | let traceCategoryBuffer; | |
| 390 | 392 | let debugLogCategoryEnabled = false; | |
| 391 | 393 | let timerFlags = kNone; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1322,9 +1322,6 @@ void DefineTraceConstants(Local<Object> target) { | |||
| 1322 | 1322 | NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_MEMORY_DUMP); | |
| 1323 | 1323 | NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_MARK); | |
| 1324 | 1324 | NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_CLOCK_SYNC); | |
| 1325 | - NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_ENTER_CONTEXT); | ||
| 1326 | - NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_LEAVE_CONTEXT); | ||
| 1327 | - NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_LINK_IDS); | ||
| 1328 | 1325 | } | |
| 1329 | 1326 | ||
| 1330 | 1327 | void CreatePerContextProperties(Local<Object> target, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -188,6 +188,14 @@ void NodeCategorySet::Initialize(Local<Object> target, | |||
| 188 | 188 | .Check(); | |
| 189 | 189 | target->Set(context, trace, | |
| 190 | 190 | binding->Get(context, trace).ToLocalChecked()).Check(); | |
| 191 | + | ||
| 192 | + Local<String> use_perfetto = | ||
| 193 | + FIXED_ONE_BYTE_STRING(env->isolate(), "usePerfetto"); | ||
| 194 | + #if defined(V8_USE_PERFETTO) | ||
| 195 | + target->Set(context, use_perfetto, v8::True(isolate)).Check(); | ||
| 196 | + #else | ||
| 197 | + target->Set(context, use_perfetto, v8::False(isolate)).Check(); | ||
| 198 | + #endif | ||
| 191 | 199 | } | |
| 192 | 200 | ||
| 193 | 201 | void NodeCategorySet::RegisterExternalReferences( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -118,6 +118,7 @@ expected.beforePreExec = new Set([ | |||
| 118 | 118 | 'NativeModule internal/net', | |
| 119 | 119 | 'NativeModule internal/dns/utils', | |
| 120 | 120 | 'NativeModule internal/modules/esm/get_format', | |
| 121 | + 'NativeModule internal/trace_events', | ||
| 121 | 122 | ]); | |
| 122 | 123 | ||
| 123 | 124 | expected.atRunTime = new Set([ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments