Polls sccache's counters every 10 s, keeps a JSON-lines history, and serves the page and its API on 127.0.0.1: one difference-with-reset mechanism behind every range, per-language time saved, problems, a copyable summary, and extra tables for multi-level and distributed caches. The page is embedded from crates/ui/dist when it exists, with a placeholder until then. POST /api/zero refuses foreign Host and Origin headers. Tests run against a stand-in sccache script; sample fixtures for the multi-level and distributed shapes are made up.
61 lines
2.8 KiB
Markdown
61 lines
2.8 KiB
Markdown
# sccache-dash
|
|
|
|
A small Linux program in the manner of Syncthing: one binary that watches the local
|
|
[sccache](https://github.com/mozilla/sccache) compiler cache, remembers what it did, and serves
|
|
a dashboard for it at <http://127.0.0.1:8226>. It listens on this machine only.
|
|
|
|
It asks sccache for its counters every 10 seconds, works out hit rates, time saved and what looks
|
|
wrong, and sends the page one `View` to draw (the contract is `crates/api`).
|
|
|
|
## Install
|
|
|
|
```
|
|
just build # builds the page (trunk) and then the server
|
|
sccache-dash # serves http://127.0.0.1:8226 and opens it
|
|
sccache-dash install # the same, as a systemd user service that starts at login
|
|
sccache-dash uninstall
|
|
```
|
|
|
|
`sccache-dash [--port N] [--no-open]` serves. `install` writes
|
|
`~/.config/systemd/user/sccache-dash.service` with the absolute path of the binary and the `PATH`
|
|
of the shell that ran it, so that `sccache` is found; the service never opens a browser.
|
|
|
|
`SCCACHE_DASH_SCCACHE` names the sccache command when it is not simply `sccache` on `PATH`.
|
|
|
|
Until the page has been built (`crates/ui/dist`), the server serves a placeholder saying so; its
|
|
API answers either way.
|
|
|
|
## Routes
|
|
|
|
| Route | What it does |
|
|
| --- | --- |
|
|
| `GET /api/view?range=1h\|24h\|7d\|30d\|reset` | one `View`: totals, the period before, timing, time saved, languages, buckets, problems, a summary |
|
|
| `GET /api/export` | sccache's current stats exactly as `sccache --show-stats --stats-format json` prints them, as a download |
|
|
| `POST /api/zero` | runs `sccache --zero-stats`; the saved history is kept |
|
|
| `GET /` | the page |
|
|
|
|
`/api/zero` is refused unless the request's `Host` is localhost and, when it has an `Origin`,
|
|
that origin is this server, so a web page elsewhere cannot zero the stats.
|
|
|
|
## Where history lives
|
|
|
|
`$XDG_DATA_HOME/sccache-dash/history.jsonl` (`~/.local/share/...` by default): one compact JSON
|
|
line per reading, oldest first, at most one a minute and only when sccache's counters changed,
|
|
plus one every ten minutes so that time with the service running can be told from time it was
|
|
not. A reading is a few hundred bytes. Lines older than 30 days are deleted at startup and once
|
|
a day. Deleting the file loses the history and nothing else.
|
|
|
|
A counter that goes down means sccache reset its counters (`--zero-stats`, or its server
|
|
restarted): the range counts start again from zero there and the chart marks the spot. The first
|
|
reading ever is a baseline and counts for nothing.
|
|
|
|
## Notes on sccache
|
|
|
|
While sccache's server is running, being asked for its stats every 10 seconds keeps it from its
|
|
10-minute idle shutdown. When it is not running, `sccache --show-stats` does not start it (it
|
|
prints empty counters) and neither does this program; the next compile starts it, as usual.
|
|
|
|
## Licence
|
|
|
|
MIT or Apache-2.0, at your choice (`LICENSE-MIT`, `LICENSE-APACHE`).
|