GeezerVison is showing github.com — src: add C++ support for diagnostics channels · nodejs/node@46ee1ed
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 clipboardExpand all lines: lib/diagnostics_channel.js +15-1Lines changed: 15 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,6 +31,9 @@ const { | 31 | 31 |
| 32 | 32 | const { triggerUncaughtException } = internalBinding('errors'); | 33 | 33 |
| | 34 | +const dc_binding = internalBinding('diagnostics_channel'); | | 35 | +const { subscribers: subscriberCounts } = dc_binding; | | 36 | + | 34 | 37 | const { WeakReference } = require('internal/util'); | 35 | 38 |
| 36 | 39 | // Can't delete when weakref count reaches 0 as it could increment again. | @@ -108,6 +111,7 @@ class ActiveChannel { | 108 | 111 | this._subscribers = ArrayPrototypeSlice(this._subscribers); | 109 | 112 | ArrayPrototypePush(this._subscribers, subscription); | 110 | 113 | channels.incRef(this.name); | | 114 | + if (this._index !== undefined) subscriberCounts[this._index]++; | 111 | 115 | } | 112 | 116 |
| 113 | 117 | unsubscribe(subscription) { | @@ -120,14 +124,18 @@ class ActiveChannel { | 120 | 124 | ArrayPrototypePushApply(this._subscribers, after); | 121 | 125 |
| 122 | 126 | channels.decRef(this.name); | | 127 | + if (this._index !== undefined) subscriberCounts[this._index]--; | 123 | 128 | maybeMarkInactive(this); | 124 | 129 |
| 125 | 130 | return true; | 126 | 131 | } | 127 | 132 |
| 128 | 133 | bindStore(store, transform) { | 129 | 134 | const replacing = this._stores.has(store); | 130 | | - if (!replacing) channels.incRef(this.name); | | 135 | + if (!replacing) { | | 136 | + channels.incRef(this.name); | | 137 | + if (this._index !== undefined) subscriberCounts[this._index]++; | | 138 | + } | 131 | 139 | this._stores.set(store, transform); | 132 | 140 | } | 133 | 141 |
| @@ -139,6 +147,7 @@ class ActiveChannel { | 139 | 147 | this._stores.delete(store); | 140 | 148 |
| 141 | 149 | channels.decRef(this.name); | | 150 | + if (this._index !== undefined) subscriberCounts[this._index]--; | 142 | 151 | maybeMarkInactive(this); | 143 | 152 |
| 144 | 153 | return true; | @@ -183,6 +192,9 @@ class Channel { | 183 | 192 | this._subscribers = undefined; | 184 | 193 | this._stores = undefined; | 185 | 194 | this.name = name; | | 195 | + if (typeof name === 'string') { | | 196 | + this._index = dc_binding.getOrCreateChannelIndex(name); | | 197 | + } | 186 | 198 |
| 187 | 199 | channels.set(name, this); | 188 | 200 | } | @@ -434,6 +446,8 @@ function tracingChannel(nameOrChannels) { | 434 | 446 | return new TracingChannel(nameOrChannels); | 435 | 447 | } | 436 | 448 |
| | 449 | +dc_binding.linkNativeChannel((name) => channel(name)); | | 450 | + | 437 | 451 | module.exports = { | 438 | 452 | channel, | 439 | 453 | hasSubscribers, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/process/pre_execution.js +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -124,6 +124,8 @@ function prepareExecution(options) { | 124 | 124 | // Process initial diagnostic reporting configuration, if present. | 125 | 125 | initializeReport(); | 126 | 126 |
| | 127 | + setupDiagnosticsChannel(); | | 128 | + | 127 | 129 | // Load permission system API | 128 | 130 | initializePermission(); | 129 | 131 |
| @@ -604,6 +606,14 @@ function initializeClusterIPC() { | 604 | 606 | } | 605 | 607 | } | 606 | 608 |
| | 609 | +function setupDiagnosticsChannel() { | | 610 | + // Re-link native channels after snapshot deserialization since | | 611 | + // JS references are cleared during serialization. | | 612 | + const dc = require('diagnostics_channel'); | | 613 | + const dc_binding = internalBinding('diagnostics_channel'); | | 614 | + dc_binding.linkNativeChannel((name) => dc.channel(name)); | | 615 | +} | | 616 | + | 607 | 617 | function initializePermission() { | 608 | 618 | const permission = getOptionValue('--permission'); | 609 | 619 | if (permission) { | |
Collapse file Copy file name to clipboardExpand all lines: node.gyp +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 133 | 133 | 'src/node_main_instance.cc', | 134 | 134 | 'src/node_messaging.cc', | 135 | 135 | 'src/node_metadata.cc', | | 136 | + 'src/node_diagnostics_channel.cc', | 136 | 137 | 'src/node_modules.cc', | 137 | 138 | 'src/node_options.cc', | 138 | 139 | 'src/node_os.cc', | | 270 | 271 | 'src/node_messaging.h', | 271 | 272 | 'src/node_metadata.h', | 272 | 273 | 'src/node_mutex.h', | | 274 | + 'src/node_diagnostics_channel.h', | 273 | 275 | 'src/node_modules.h', | 274 | 276 | 'src/node_object_wrap.h', | 275 | 277 | 'src/node_options.h', | |
Collapse file Copy file name to clipboardExpand all lines: src/base_object_types.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,7 @@ namespace node { | 10 | 10 | // what the class passes to SET_BINDING_ID(), the second argument should match | 11 | 11 | // the C++ class name. | 12 | 12 | #define SERIALIZABLE_BINDING_TYPES(V) \ | | 13 | + V(diagnostics_channel_binding_data, diagnostics_channel::BindingData) \ | 13 | 14 | V(encoding_binding_data, encoding_binding::BindingData) \ | 14 | 15 | V(fs_binding_data, fs::BindingData) \ | 15 | 16 | V(mksnapshot_binding_data, mksnapshot::BindingData) \ | |
Collapse file Copy file name to clipboardExpand all lines: src/node_binding.cc +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 48 | 48 | V(constants) \ | 49 | 49 | V(contextify) \ | 50 | 50 | V(credentials) \ | | 51 | + V(diagnostics_channel) \ | 51 | 52 | V(encoding_binding) \ | 52 | 53 | V(errors) \ | 53 | 54 | V(fs) \ | |
Collapse file Copy file name to clipboardExpand all lines: src/node_binding.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,6 +49,7 @@ static_assert(static_cast<int>(NM_F_LINKED) == | 49 | 49 | V(blob) \ | 50 | 50 | V(builtins) \ | 51 | 51 | V(contextify) \ | | 52 | + V(diagnostics_channel) \ | 52 | 53 | V(encoding_binding) \ | 53 | 54 | V(fs) \ | 54 | 55 | V(fs_dir) \ | |
|