CPU session with duration_secs reports less than the requested duration (two clocks race)

Aperta
#67 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

Read lsp-profiler-dotnet's cpu.rs attach and wait_for_stop flow alongside lsp-profiler's session.rs CpuSession::new and recorded_secs(). Trace how the two timers and receiver closure determine the reported duration, then check existing CPU session tests. Done means a session started with a duration of 2 seconds reports the requested duration when it stops automatically, while still handling target exits correctly.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Summary

A CPU session started with duration_secs: 2 reports duration_secs of ~1.946 instead of 2. Seen consistently on 0.10.1 with the prebuilt osx-arm64 engine (2/2 runs).

Mechanism

Two clocks measure the same duration:

  • lsp-profiler-dotnet cpu.rs attach spawns forward(...) right after await_attached. wait_for_stop starts its own tokio::time::Instant and closes the sample sink when limit elapses.
  • lsp-profiler session.rs CpuSession::new sets started_at = Instant::now() only after attach returns, which is later.

So the forwarder's timer expires first and closes the receiver. ended() returns true through receiver.is_closed(), and recorded_secs() returns elapsed.min(limit) with elapsed ≈ limit − (attach→session gap), for example 1.9457 s.

Repro

A consumer e2e test (SharpLsp profiler-lsp-cpu-e2e, "a duration on start stops the session by itself"):

  1. cpu.start { pid, duration_secs: 2 } against a busy .NET process.
  2. Poll cpu.list until the session is gone.
  3. cpu.stop { session_id }.

Expected: duration_secs == 2 ([PROF-CPU-SESSIONS] duration).
Actual: 1.945700541, 1.947925084.

Suggested fix

Use one clock. Either hand the session's started_at (or the deadline) to the forwarder, or have recorded_secs() return limit when the session ended because its duration elapsed rather than because the target exited.

Lingua principale
Rust
Stelle
9
Fork
0
Merge medio
2h 28m
PR unite (30g)
25

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Nimblesite/lspkit

Tutte le issue di Nimblesite/lspkit

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.