tests.tachyon_cast module

Record tests/tachyon-live.cast, the stream Tachyon’s live mode writes.

Tachyon, the sampling profiler of Python 3.15 (python -m profiling.sampling), draws its --live mode with curses, as a full-screen program. This script runs that interface under a pseudo-terminal sized like the screenshots of the Python documentation, and keeps every chunk it writes with the time it arrived, as an asciicast v2 file. tests/test_recording.py replays the file into the animated capture it pins.

The interface is fed synthetic samples of a made-up bakery program instead of a real process. No process memory is read, so no privilege is needed: on macOS, profiling a live process takes sudo. Run it with:

$ uv run --script tests/tachyon_cast.py

The samples come from a seeded generator, but the refreshes follow the wall clock, so two recordings never come out byte for byte the same.

tests.tachyon_cast.CAST = PosixPath('/home/runner/work/click-extra/click-extra/tests/tachyon-live.cast')

Where the recording is written.

tests.tachyon_cast.COLUMNS = 120

Width of the terminal, that of the screenshots in the Python documentation.

Tachyon draws their second % column from 120 columns on, and their missing cumtime column only from 140.

tests.tachyon_cast.ROWS = 47

Height of the terminal, that of the same screenshots.

Their table shows 34 rows, and Tachyon gives it the height less 13.

tests.tachyon_cast.LIVE_SECONDS = 4.0

Seconds of live profiling, the length of the documentation’s own loop.

tests.tachyon_cast.FINISHED_SECONDS = 1.0

Seconds the final screen stays up once profiling ends, before quitting.

tests.tachyon_cast.RATE = 10000

Samples fed per second, Tachyon’s sampling rate in the documentation.

class tests.tachyon_cast.LocationInfo(lineno, end_lineno, col_offset, end_col_offset)

Bases: tuple

Create new instance of LocationInfo(lineno, end_lineno, col_offset, end_col_offset)

col_offset

Alias for field number 2

end_col_offset

Alias for field number 3

end_lineno

Alias for field number 1

lineno

Alias for field number 0

class tests.tachyon_cast.FrameInfo(filename, location, funcname, opcode)

Bases: tuple

Create new instance of FrameInfo(filename, location, funcname, opcode)

filename

Alias for field number 0

funcname

Alias for field number 2

location

Alias for field number 1

opcode

Alias for field number 3

class tests.tachyon_cast.ThreadInfo(thread_id, frame_info, status)

Bases: tuple

Create new instance of ThreadInfo(thread_id, frame_info, status)

frame_info

Alias for field number 1

status

Alias for field number 2

thread_id

Alias for field number 0

class tests.tachyon_cast.InterpreterInfo(interpreter_id, threads)

Bases: tuple

Create new instance of InterpreterInfo(interpreter_id, threads)

interpreter_id

Alias for field number 0

threads

Alias for field number 1

tests.tachyon_cast.frame(location, funcname, name=None)[source]

One frame of a sampled stack.

Parameters:
  • location (str) – file and line, as path:line.

  • funcname (str) – the function’s qualified name.

  • name (str | None) – the instruction executing, for the top frame only.

Return type:

FrameInfo

tests.tachyon_cast.bakery()[source]

The stacks each thread of the bakery samples on, weighted.

Return type:

dict[int, list[tuple[float, list[FrameInfo], int]]]

Returns:

by thread, each stack with its weight and its thread status.

tests.tachyon_cast.child()[source]

Draw Tachyon’s live mode on this terminal, from synthetic samples.

Return type:

None

tests.tachyon_cast.record()[source]

Run child() under a pseudo-terminal and write what it drew.

Return type:

None