diff --git a/CHANGELOG.md b/CHANGELOG.md index ab6497cb..4aedd7ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- **`dl` and `dla` keep an event log.** Each launch, session end, `stop`, `kill`, `rm` + and `prune` appends one JSON line to `$XDG_STATE_HOME/devlaunch/events.jsonl` + (`~/.local/state/devlaunch/events.jsonl` by default), with the start's seconds, + whether it was cold, and its stages. `dla` adds `aid_start` and `aid_end` lines. + `DEVLAUNCH_EVENTS=0` turns it off. A line that cannot be written never fails the + command. See [The event log](docs/performance.md#the-event-log). + ## [0.64.3] - 2026-11-18 ### Fixed diff --git a/README.md b/README.md index 1d1a7872..dfd8831a 100644 --- a/README.md +++ b/README.md @@ -566,14 +566,16 @@ Images are yours: `docker system df` is what shows those. | `NVIM_SPLIT=1` | In Herdr, open `$VISUAL`, then `$EDITOR`, or `nvim` in a vertical split beside an agent launched with `dla` or `dl`. Off by default. The agent pane keeps focus. Requires the pane shell installed by `dl --herdr-setup`. See [docs/workspace-tools.md](docs/workspace-tools.md) | | `HERDR_AGENT=` | Written, not read: a `dla` launch that starts an agent, or a `dl -- ` whose command is one, names it here so a session manager can see it. See [docs/workspace-tools.md](docs/workspace-tools.md) | | `DEVLAUNCH_TIMING=1\|json` | Write a timing summary to stderr. See [docs/performance.md](docs/performance.md) | +| `DEVLAUNCH_EVENTS=0` | Do not append to the event log, `$XDG_STATE_HOME/devlaunch/events.jsonl` (`~/.local/state` without it). On by default: one JSON line per launch, stop, kill, remove and prune. See [docs/performance.md](docs/performance.md#the-event-log) | | `DEVPOD_SSH_CONFIG=` | devpod's own, honoured rather than set: it is where `devpod up` publishes host aliases, so it is where `dl` looks for them. See [docs/cli.md](docs/cli.md) | | `CLAUDE_CONFIG_DIR=` | Claude Code's own, honoured rather than set: it is where the host keeps its Claude configuration, so it is where `dl` reads the login to forward. It replaces `~/.claude` rather than being tried before it, exactly as Claude Code treats it. See [docs/workspace-tools.md](docs/workspace-tools.md) | | `DEVLAUNCH_CLAUDE_PROFILES_DIR=` | Where `--claude-profile` looks, and it wins over the row below. For scoping a scratch run away from real credentials | | `CLAUDE_PROFILES_DIR=` | Honoured rather than set: the profile directory `claude-as` manages. Defaults to `~/.claude-profiles`. Nothing `dl` deletes reaches it | Every switch here reads the same values: anything but empty, `0`, `false` or `no` counts as -set. On a "no" variable that means turn it off; on an opt-in one it means turn it on. Eight -rows are not switches and do not follow it: `DEVLAUNCH_AID_AGENT`, `DEVPOD_SSH_CONFIG`, +set. On a "no" variable that means turn it off; on an opt-in one it means turn it on. Nine +rows are not switches and do not follow it: `DEVLAUNCH_EVENTS` is on unless it is `0`, +`false`, `no` or `off`, so an empty value keeps the log on, `DEVLAUNCH_AID_AGENT`, `DEVPOD_SSH_CONFIG`, `CLAUDE_CONFIG_DIR`, `DEVLAUNCH_CLAUDE_PROFILES_DIR` and `CLAUDE_PROFILES_DIR` take a value, `DEVLAUNCH_TIMING` counts only empty and `0` as off, so `false` and `no` turn it on, `DEVLAUNCH_AID_REMOTE_CONTROL` takes `1`/`true`/`on`/`yes` or `0`/`false`/`off`/`no` and refuses anything else rather than guessing, and `HERDR_AGENT` is diff --git a/docs/performance.md b/docs/performance.md index d90cec3b..74d670ae 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -142,8 +142,9 @@ be the cost of starting a bash per stage, which is small. A warm launch makes no ## Measuring launch time Set `DEVLAUNCH_TIMING=1` and a `dl` command ends with one summary on stderr, -naming each subprocess round trip and the total. Unset (or `0`) records nothing -and prints nothing. +naming each subprocess round trip and the total. Unset (or `0`) prints nothing. +The stages are still recorded for [the event log](#the-event-log) unless +`DEVLAUNCH_EVENTS=0`. **Every second quoted in this section came off one host on 2026-08-14, over three sessions that day (`d3b8ffb`, `5510b1e`, `461f740`), and that host was @@ -176,6 +177,62 @@ dl-timing: devpod ssh 1.952s dl-timing: total 2.444s (in-process, excluding interpreter startup) ``` +### The event log + +`DEVLAUNCH_TIMING` answers a question asked before the launch. The event log +answers one asked afterwards: how long did starts take this week, and how many +were cold. Every `dl` and `dla` appends one JSON object per line to +`$XDG_STATE_HOME/devlaunch/events.jsonl`, or `~/.local/state/devlaunch/events.jsonl` +when `XDG_STATE_HOME` is unset. Nobody has to set anything first. +`DEVLAUNCH_EVENTS=0` turns it off. + +A line that cannot be written is dropped and the command goes on. A full disk or +a read-only state directory costs the log and nothing else. Each line is one +append, so two commands at once do not mix their lines. + +| `ev` | Written when | Fields beyond `ts`, `ev`, `ws`, `repo`, `branch` | +|---|---|---| +| `launch` | The workspace is ready and the session is about to start, or an `up`, `code` or `dotfiles` has finished | `cold`, `seconds`, `stages`, `verb` | +| `session_end` | The session a `launch` started has ended | `seconds` (of the session), `exit` | +| `stop`, `kill`, `remove`, `prune` | The verb has finished | `seconds`, `exit` | +| `aid_start` | `dla` has handed its start to `dl` and the workspace is ready | `cold`, `seconds`, `stages`, `agent`, `resume` | +| `aid_end` | `dla` has ended | `seconds`, `exit`, `agent` | + +`ts` is UTC ISO 8601 to the millisecond. `ws` is the workspace id when the launch +knew it, else the target as typed. `repo` and `branch` are set when the target +is `owner/repo@branch`. `cold` is true when the launch's `devpod up` created the +workspace. `seconds` on a `launch` is the wall time from the top of the command, +and `stages` holds the same named stages as the timing document, in seconds. On +an `aid_start`, `stages` holds `dla`'s own steps (`pick`, `pr_lookup`, `prompt`, +`boot_wait`) and `dl`, the launch inside it. The `aid` names are what `dla` was +called before, and what readers of older logs already look for. + +```json +{"ts":"2026-11-21T09:13:05.340Z","ev":"aid_start","ws":"devlaunch-main-3j1t","repo":"blooop/devlaunch","branch":"main","cold":false,"seconds":0.043923,"stages":{"pick":0.00007,"pr_lookup":0.00005,"prompt":1e-6,"dl":0.023009},"agent":"claude","resume":false} +``` + +A picked workspace logs the same lines as a named one. A picked batch (several +rows marked for one verb) writes one line, not one per workspace: the `launch` of +the first workspace that came up, or the `stop`, `kill` or `remove` of the last +one, timed from that workspace's start. + +Three gaps a reader of the log has to allow for: + +- **A closed terminal loses the end line.** When the terminal or pane closes, + `dl` gets SIGHUP (SIGTERM does the same) and its signal handler exits at once + with `_exit(129)`. The handler writes nothing, so the `launch` has no + `session_end` after it, and a `dla` start has no `aid_end`. +- **An interactive `dla` start that creates the workspace logs two `launch` + lines.** The background boot (`dla --boot-up up`) is a process of its + own. It does the create and writes a `launch` with `verb` `up` and `cold` + true. The attach in the foreground then finds the workspace up and writes a + `launch` with `cold` false, and the `aid_start` copies that `false`. Count cold + starts on the interactive path from the boot's `up` line, not from + `aid_start`. +- **`stop`, `kill` and `remove` log the target as typed.** Their `ws` is not + resolved to a workspace id, and `repo` and `branch` are null when the target + is a workspace id rather than `owner/repo`. + ### The same launch, machine-readable `DEVLAUNCH_TIMING=json` swaps that prose for one document on a single diff --git a/rust/devlaunch-core/public-api.rest.txt b/rust/devlaunch-core/public-api.rest.txt index 8b8b815e..04c021e1 100644 --- a/rust/devlaunch-core/public-api.rest.txt +++ b/rust/devlaunch-core/public-api.rest.txt @@ -3560,5 +3560,18 @@ pub fn devlaunch_core::timing::Report::eq(&self, &devlaunch_core::timing::Report impl core::fmt::Debug for devlaunch_core::timing::Report pub fn devlaunch_core::timing::Report::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result impl core::marker::StructuralPartialEq for devlaunch_core::timing::Report -pub fn devlaunch_core::timing::begin() +pub struct devlaunch_core::timing::Ready +pub devlaunch_core::timing::Ready::cold: bool +pub devlaunch_core::timing::Ready::seconds: f64 +pub devlaunch_core::timing::Ready::stages: alloc::vec::Vec<(&'static str, f64)> +pub devlaunch_core::timing::Ready::workspace_id: core::option::Option +impl core::clone::Clone for devlaunch_core::timing::Ready +pub fn devlaunch_core::timing::Ready::clone(&self) -> devlaunch_core::timing::Ready +impl core::cmp::PartialEq for devlaunch_core::timing::Ready +pub fn devlaunch_core::timing::Ready::eq(&self, &devlaunch_core::timing::Ready) -> bool +impl core::fmt::Debug for devlaunch_core::timing::Ready +pub fn devlaunch_core::timing::Ready::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result +impl core::marker::StructuralPartialEq for devlaunch_core::timing::Ready +pub fn devlaunch_core::timing::begin(core::option::Option) pub fn devlaunch_core::timing::emit() -> core::option::Option +pub fn devlaunch_core::timing::ready(core::option::Option<&str>) diff --git a/rust/devlaunch-core/src/flows/launch.rs b/rust/devlaunch-core/src/flows/launch.rs index e93b6ed8..821ba306 100644 --- a/rust/devlaunch-core/src/flows/launch.rs +++ b/rust/devlaunch-core/src/flows/launch.rs @@ -2203,6 +2203,12 @@ fn up_under_stage( // This launch is the one paying for the `up`, so no prewarm saved it from // anything — whether or not one was fired. timing::observe_attach(timing::AttachShape::Miss); + // A create is what the event log calls a cold launch: devpod did not list + // this workspace, so this `up` builds it rather than starting it. + timing::observe_up( + request.naming.identity(), + matches!(request.naming, Naming::Create { .. }), + ); // The build runs for minutes in the foreground; it leads a process group of // its own so a Ctrl-C (or `kill -INT `) tears the whole build down with // `dl` rather than orphaning it holding the launch lock. @@ -4189,6 +4195,9 @@ pub(crate) fn attach_workspace( forward: &mut dyn FnMut(&str), notices: &mut dyn Notices, ) -> Result { + // Ready before the attach stage opens: what follows is the session, which + // lasts as long as somebody works in it and is no part of the start. + timing::ready(Some(workspace_id)); timing::stage_result(timing::Stage::Attach, || { // First, and unconditionally on the way to every session: the terminal is // about to belong to something else, and after that this process may not diff --git a/rust/devlaunch-core/src/timing.rs b/rust/devlaunch-core/src/timing.rs index fcfbfa45..3c277cce 100644 --- a/rust/devlaunch-core/src/timing.rs +++ b/rust/devlaunch-core/src/timing.rs @@ -2,9 +2,11 @@ //! //! Set `DEVLAUNCH_TIMING=1` and every dl process ends with one summary on //! stderr: a `dl-timing: