Skip to content

Enabling pprof#524

Draft
WendelHime wants to merge 7 commits into
mainfrom
enabling-pprof
Draft

Enabling pprof#524
WendelHime wants to merge 7 commits into
mainfrom
enabling-pprof

Conversation

@WendelHime

Copy link
Copy Markdown
Contributor

No description provided.

myleshorton and others added 7 commits June 10, 2026 12:30
Radiance is compiled into the host app via gomobile, so there's no
process to attach a profiler to and no on-device profiling hook. Add a
loopback pprof/HTTP server gated behind RADIANCE_PPROF_ADDR — off by
default (nothing registered, no port opened) so it ships safely in
release builds. Set it to e.g. localhost:6060 to capture CPU/heap
profiles of the running client, notably the broflake / Unbounded WebRTC
relay whose cost is otherwise invisible:

    RADIANCE_PPROF_ADDR=localhost:6060 <app>
    go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30

Bound to loopback only and served from a dedicated mux (not
DefaultServeMux) so the debug handlers can't leak off-device or onto
another server in the process.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Hard-refuse any RADIANCE_PPROF_ADDR that isn't loopback (empty host,
  0.0.0.0, or a public IP) instead of trusting the caller. pprof exposes
  goroutine stacks and can be driven to burn CPU, so it must never bind
  off-device.
- Register the server's Close in shutdownFuncs so a Start/Close cycle
  (re-init, tests, in-process clients) frees the port and stops the
  goroutine. Previously it leaked and the next Start would hit "address
  already in use".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add an env.Pprof key and have startDebugServer read the address through
the radiance env package instead of os.Getenv directly. env.Get already
honours an OS env var, a .env file in the working dir, and runtime
env.Set (incl. the IPC SetEnv path) — the latter two are what let the
profiler be enabled on sandboxed macOS/iOS system extensions, which don't
inherit the launching shell's environment.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add telemetry/procmetrics, started from the sing-box tunnel process so
the metrics describe the process that actually runs the proxy. On
macOS/iOS that is the network-extension process, not the control
process.

RSS (via gopsutil) is the only signal that captures the WATER WASM
outbound's linear memory, which wazero maps off the Go heap and so never
appears in runtime.MemStats. Also emits process.cpu.time (user/system)
and process.runtime.go.* (heap, goroutines, GC).

Metrics flow through the existing OpenTelemetry meter provider and stay
inert until telemetry is configured. Per-outbound throughput is already
covered by the downlink_bytes/uplink_bytes metrics in connections.go.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants