Skip to content

Add a debugMode flag to log queries to the performance timeline #229

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

Merged
merged 4 commits into from
Jul 25, 2024

Conversation

rkistner
Copy link
Contributor

@rkistner rkistner commented Jul 16, 2024

This displays all SQL queries on the performance timeline. Currently only implemented in the Web SDK.

This excludes the time waiting for the global transaction lock, but includes all overhead in worker communication. This means you won't see concurrent queries in most cases.

This includes internal statements from PowerSync, including queries saving sync data, and begin/commit statements. It does not include internal statements from powersync-sqlite-core.

TODO:

  • The flag currently defaults to false if process.env.NODE_ENV == 'production', similar to what React does. All other cases default to true. Should we perhaps be more conservative and require explicit opt-in, since the queries could be considered semi-sensitive data? Updated default to false, requiring explicit opt-in for now.

Example of the diagnostics app during initial sync:

image

@rkistner rkistner requested a review from stevensJourney July 16, 2024 12:03
Copy link

changeset-bot bot commented Jul 16, 2024

🦋 Changeset detected

Latest commit: 05f3dbd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@powersync/common Minor
@powersync/web Minor
django-react-native-todolist Patch
react-native-supabase-group-chat Patch
react-native-supabase-todolist Patch
@powersync/react-native Patch
angular-supabase-todolist Patch
example-capacitor Patch
example-electron Patch
example-nextjs Patch
example-vite Patch
react-multi-client Patch
react-supabase-todolist Patch
vue-supabase-todolist Patch
yjs-react-supabase-text-collab Patch
diagnostics-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

stevensJourney
stevensJourney previously approved these changes Jul 16, 2024
Copy link
Collaborator

@stevensJourney stevensJourney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM . This is an awesome feature.

@rkistner rkistner merged commit 6c1c83f into main Jul 25, 2024
2 checks passed
@rkistner rkistner deleted the query-timeline branch July 25, 2024 11:51
@guillempuche
Copy link
Contributor

Is it documented?

@rkistner
Copy link
Contributor Author

@guillempuche It's not properly documented yet, but you can see how it's used in the diagnostics app:

export const db = new PowerSyncDatabase({
database: {
dbFilename: 'example.db',
debugMode: true
},
schema: schemaManager.buildSchema()
});

I'd recommend using something like this to only enable debugMode in development:

debugMode: process.env.NODE_ENV != 'production'

The feature just displays queries in the "Performance" tab of Chrome's developer tools (after recording) - see the screenshots above.

@guillempuche
Copy link
Contributor

Thanks Ralf @rkistner

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

Successfully merging this pull request may close these issues.

3 participants