Repository navigation
fix(tooling): write the frame trace from a writer thread, not the thread that draws - #2297
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
--tracerun wrote its trace file from the thread that draws. When that write waited on the disk, the trace showed a frame gap the app did not have.sequenceDiagram participant UI as frame thread participant W as rune-trace thread participant F as trace file Note over UI,F: before UI->>F: writeln! through an 8 KiB BufWriter (a write call every frame or two) F-->>UI: returns after the file's lock is free (60 to 220 ms seen) Note over UI,F: after UI->>W: finished line over a channel (never waits) W->>F: write_all, as each line arrives UI->>W: flush at the run's end W-->>UI: every line is in the fileWhat was measured
Recorded launches of an app with
--traceon Windows (off-CPU waits of the frame thread, aligned to the trace's frames):NtWriteFilefromTrace::frame_timed_coreNtWriteFile(the file's NTFS lock while it grows)NtWriteFile(same)NtWriteFilefromTrace::frame_timed_coreThe frames around each gap cost 4 to 7 ms. A frame line is about 5 KiB, so the default 8 KiB buffer made a write call every frame or two.
The change
Trace::outis aTraceOut:writecollects a line and sends it when it ends in a newline; a thread namedrune-traceowns the file and writes each line as it arrives.flushwaits until the file holds every line sent so far.Trace::settle_presentsnow ends with it: a--frames Nrun ends by a fast exit that drops nothing, so this is where its last frames reach the file. Before, such a run lost the buffer's tail (traces of 1,000 frames held 988 to 999).Dropsends what is left, closes the channel and joins the thread.wasm32keeps theBufWriter: no threads, no disk to wait on.What a process that dies leaves behind
write_allas it arrives and keeps no buffer of its own, so the loss is the lines still in the channel: none or one in a healthy run, and as many as the disk was stalled for when it stalls.Cost when
--traceis offNone: the thread and the channel are made in
Trace::open_clock, and aTraceis only made for a trace path (open_trace_if_needed, the headless and virtual-desktop runs).Tests
trace_lines_are_written_by_another_thread_and_a_stalled_disk_holds_no_frame: a sink that holds every write behind a gate; three lines are handed over while it is shut; each line is one write, on the writer's thread.trace_file_holds_every_line_after_a_flush_and_after_the_dropsettled_trace_file_holds_every_frame_while_the_trace_is_still_openNot in this change
Host::replay_window_scriptstill writes the script's lines to stdout from the frame thread (104.6 ms seen when stdout was a file). A runner should give the app a pipe it drains.