Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.7k
sqlite: add diagnostic channel#62241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| 'use strict'; | ||
| const common = require('../common.js'); | ||
| const sqlite = require('node:sqlite'); | ||
| const dc = require('node:diagnostics_channel'); | ||
| const assert = require('node:assert'); | ||
| const bench = common.createBenchmark(main, { | ||
| n: [1e5], | ||
| mode: ['none', 'subscribed', 'unsubscribed'], | ||
| }); | ||
| function main(conf) { | ||
| const { n, mode } = conf; | ||
| const db = new sqlite.DatabaseSync(':memory:'); | ||
| db.exec('CREATE TABLE t (x INTEGER)'); | ||
| const insert = db.prepare('INSERT INTO t VALUES (?)'); | ||
| let subscriber; | ||
| if (mode === 'subscribed') { | ||
| subscriber = () => {}; | ||
| dc.subscribe('sqlite.db.query', subscriber); | ||
| } else if (mode === 'unsubscribed') { | ||
| subscriber = () => {}; | ||
| dc.subscribe('sqlite.db.query', subscriber); | ||
| dc.unsubscribe('sqlite.db.query', subscriber); | ||
| } | ||
| // mode === 'none': no subscription ever made | ||
| let result; | ||
| bench.start(); | ||
| for (let i = 0; i < n; i++) { | ||
| result = insert.run(i); | ||
| } | ||
| bench.end(n); | ||
| if (mode === 'subscribed') { | ||
| dc.unsubscribe('sqlite.db.query', subscriber); | ||
| } | ||
| assert.ok(result !== undefined); | ||
| } |
araujogui marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -127,10 +127,38 @@ void BindingData::Deserialize(Local<Context> context, | ||
| CHECK_NOT_NULL(binding); | ||
| } | ||
| void BindingData::SetChannelStatusCallback(uint32_t index, | ||
| ChannelStatusCallback cb) { | ||
| channel_status_callbacks_[index] = std::move(cb); | ||
| } | ||
| void BindingData::NotifyChannelActive(const FunctionCallbackInfo<Value>& args) { | ||
| Realm* realm = Realm::GetCurrent(args); | ||
| BindingData* binding = realm->GetBindingData<BindingData>(); | ||
| if (binding == nullptr) return; | ||
| CHECK(args[0]->IsUint32()); | ||
| uint32_t index = args[0].As<v8::Uint32>()->Value(); | ||
| auto it = binding->channel_status_callbacks_.find(index); | ||
| if (it != binding->channel_status_callbacks_.end()) it->second(true); | ||
| } | ||
araujogui marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| void BindingData::NotifyChannelInactive( | ||
| const FunctionCallbackInfo<Value>& args) { | ||
| Realm* realm = Realm::GetCurrent(args); | ||
| BindingData* binding = realm->GetBindingData<BindingData>(); | ||
| if (binding == nullptr) return; | ||
| CHECK(args[0]->IsUint32()); | ||
| uint32_t index = args[0].As<v8::Uint32>()->Value(); | ||
| auto it = binding->channel_status_callbacks_.find(index); | ||
| if (it != binding->channel_status_callbacks_.end()) it->second(false); | ||
| } | ||
araujogui marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data, | ||
| Local<ObjectTemplate> target) { | ||
| Isolate* isolate = isolate_data->isolate(); | ||
| SetMethod(isolate, target, "linkNativeChannel", LinkNativeChannel); | ||
| SetMethod(isolate, target, "notifyChannelActive", NotifyChannelActive); | ||
| SetMethod(isolate, target, "notifyChannelInactive", NotifyChannelInactive); | ||
| } | ||
| void BindingData::CreatePerContextProperties(Local<Object> target, | ||
| @@ -145,6 +173,8 @@ void BindingData::CreatePerContextProperties(Local<Object> target, | ||
| void BindingData::RegisterExternalReferences( | ||
| ExternalReferenceRegistry* registry) { | ||
| registry->Register(LinkNativeChannel); | ||
| registry->Register(NotifyChannelActive); | ||
| registry->Register(NotifyChannelInactive); | ||
| } | ||
| Channel::Channel(Environment* env, | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,6 +4,7 @@ | ||
| #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
| #include <cinttypes> | ||
| #include <functional> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
| @@ -52,6 +53,14 @@ class BindingData : public SnapshotableObject { | ||
| static void LinkNativeChannel( | ||
| const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| using ChannelStatusCallback = std::function<void(bool is_active)>; | ||
| void SetChannelStatusCallback(uint32_t index, ChannelStatusCallback cb); | ||
| static void NotifyChannelActive( | ||
| const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| static void NotifyChannelInactive( | ||
| const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| static void CreatePerIsolateProperties(IsolateData* isolate_data, | ||
| v8::Local<v8::ObjectTemplate> target); | ||
| static void CreatePerContextProperties(v8::Local<v8::Object> target, | ||
| @@ -62,6 +71,7 @@ class BindingData : public SnapshotableObject { | ||
| private: | ||
| InternalFieldInfo* internal_field_info_ = nullptr; | ||
| std::unordered_map<uint32_t, ChannelStatusCallback> channel_status_callbacks_; | ||
| }; | ||
araujogui marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| class Channel : public BaseObject { | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.