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

Tracing support for seeing what SQL queries were executed #435

Closed
simonw opened this issue Apr 21, 2019 · 4 comments

Comments

Projects
None yet
1 participant
@simonw
Copy link
Owner

commented Apr 21, 2019

Features like faceting, foreign key expansions and now the inspect-less index view mean Datasette can end up executing a surprisingly large number of SQL queries to render a single page.

Past experience with projects like tikbar have shown that being able to see what actually went into rendering a page can be critical for optimizing performance and generally understanding how everything works.

Support a tracing mode (probably via a ?_trace=1 querystring) which adds information about what is actually going on to both the HTML and the JSON.

@simonw

This comment has been minimized.

Copy link
Owner Author

commented Apr 21, 2019

I built a first version of this in 7d01ca3 which dumped SQL queries out to the terminal logs.

simonw added a commit that referenced this issue Apr 21, 2019

?_trace=1 now adds SQL trace info to JSON/HTML response
Also added documentation for it. Refs #435

simonw added a commit that referenced this issue Apr 21, 2019

@simonw

This comment has been minimized.

Copy link
Owner Author

commented Apr 21, 2019

simonw added a commit that referenced this issue Apr 21, 2019

simonw added a commit that referenced this issue Apr 21, 2019

@simonw simonw added this to the 0.28 milestone May 11, 2019

@simonw

This comment has been minimized.

Copy link
Owner Author

commented May 11, 2019

I don't like the shape of the JSON:

  "_traces": {
    "num_traces": 20,
    "traces": {
      "duration": 0.015190839767456055,
      "queries": [
        [
          "sql",
          [
            "fixtures",
            "select 1 from sqlite_master where type='table' and name=?",
            [
              "facetable.json"
            ]
          ],
          1557599406.7231224,
          1557599406.723611,
          0.4887580871582031
        ],
        [

I want this instead:

  "_traces": {
    "num_traces": 20,
    "sum_duration_ms": 0.015190839767456055,
    "traces": [
      {
        "type": "sql",
        "database": "fixtures",
        "sql": "select 1 from sqlite_master where type='table' and name=?",
        "args": ["facetable.json"],
        "start": 1557599406.7231224,
        "end": 1557599406.723611,
        "duration_ms": 0.4887580871582031
      }

@simonw simonw closed this in a0d4448 May 11, 2019

@simonw

This comment has been minimized.

Copy link
Owner Author

commented May 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.