# Debugging Ditto

Running the command `deno task debug` will start the Ditto server in debug mode, making it possible to inspect with Chromium-based browsers by visiting `chrome://inspect`.

From there, go to the "Performance" tab and click "Start profiling". Perform the actions you want to profile, then click "Stop profiling". You can then inspect the call stack and see where the time is being spent.

## Remote debugging

If the Ditto server is on a separate machine, you will first need to put it into debug mode. Edit its systemd file (usually located at `/etc/systemd/system/ditto.service`) and change `deno task start` to `deno task debug` in the `ExecStart` line. Then run `systemctl daemon-reload` and `systemctl restart ditto`.

To access the debugger remotely, you can use SSH port forwarding. Run this command on your local machine, replacing `<user>@<host>` with the SSH login for the remote machine:

```sh
ssh -L 9229:localhost:9229 <user>@<host>
```

Then, in Chromium, go to `chrome://inspect` and the Ditto server should be available.

## SQL performance

To track slow queries, first set `DEBUG=ditto:sql` in the environment so only SQL logs are shown.

Then, grep for any logs above 0.001s:

```sh
journalctl -fu ditto | grep -v '(0.00s)'
```
