-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
sqlite: add trace sql hook #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
base: main
Are you sure you want to change the base?
sqlite: add trace sql hook #62241
Changes from all commits
2ac7a27
349412e
69e5438
27985a1
3c36722
8bfc4fd
c40646d
906ef83
2d36987
89ab713
24f6ea0
File filter
Filter by extension
Conversations
Jump to
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('diagnostics_channel'); | ||
| const assert = require('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); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,12 +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; | ||
| 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); | ||
| } | ||
|
Comment on lines
+135
to
+142
|
||
|
|
||
| void BindingData::NotifyChannelInactive( | ||
| const FunctionCallbackInfo<Value>& args) { | ||
| Realm* realm = Realm::GetCurrent(args); | ||
| BindingData* binding = realm->GetBindingData<BindingData>(); | ||
| if (binding == nullptr) return; | ||
| 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); | ||
| } | ||
|
Comment on lines
+144
to
+152
|
||
|
|
||
| void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data, | ||
| Local<ObjectTemplate> target) { | ||
| Isolate* isolate = isolate_data->isolate(); | ||
| SetMethod( | ||
| isolate, target, "getOrCreateChannelIndex", GetOrCreateChannelIndex); | ||
| SetMethod(isolate, target, "linkNativeChannel", LinkNativeChannel); | ||
| SetMethod(isolate, target, "notifyChannelActive", NotifyChannelActive); | ||
| SetMethod(isolate, target, "notifyChannelInactive", NotifyChannelInactive); | ||
| } | ||
|
|
||
| void BindingData::CreatePerContextProperties(Local<Object> target, | ||
|
|
@@ -148,6 +174,8 @@ void BindingData::RegisterExternalReferences( | |
| ExternalReferenceRegistry* registry) { | ||
| registry->Register(GetOrCreateChannelIndex); | ||
| registry->Register(LinkNativeChannel); | ||
| registry->Register(NotifyChannelActive); | ||
| registry->Register(NotifyChannelInactive); | ||
| } | ||
|
|
||
| Channel::Channel(Environment* env, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.