Skip to content
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

Allow multiple tracing/profile callbacks #502

Closed
rogerbinns opened this issue Dec 2, 2023 · 1 comment
Closed

Allow multiple tracing/profile callbacks #502

rogerbinns opened this issue Dec 2, 2023 · 1 comment

Comments

@rogerbinns
Copy link
Owner

rogerbinns commented Dec 2, 2023

Currently there can only be one profiler, one authorizer, one collation needed callback etc.

This is especially problematic with the profiler because apswtrace needs it, but if any other code installs a tracer then apswtrace sees nothing.

The simplest approach would be to add a name parameter when they are registered/unregistered. The default is None. Internally APSW would keep a list for the callback and invoke the appropriate ones.

As an example the sqlite3_tracev2 would be a array of:

PyObject *name;
unsigned mask;
PyObject *callback;

Then when a trace event fires the list is traversed and any whose mask matches the event is called.

Some additional things:

  • It is common to remove callbacks while in a callback, so mutating the list while iterating it must work. The simplest thing is to make name and callback be NULL on deletion an never resize the list to be smaller.
  • Use PyObject_RichCompareBool with Py_EQ to see if name matches on register/unregister
  • They should be included during tp_traverse
@rogerbinns rogerbinns changed the title Connection hook to allow multiple auth/profile etc Allow multiple auth/profile etc May 19, 2024
@rogerbinns rogerbinns changed the title Allow multiple auth/profile etc Allow multiple tracing/profile callbacks Oct 7, 2024
@rogerbinns
Copy link
Owner Author

Implemented for sqlite3_trace_v2 calls where I already had to handle thesqlite3_profile deprecation co-existence.

It doesn't make sense for auth - what if one callback says yes and one says no and one says ignore?

The progress callback might be useful, but I'll wait till someone asks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant