<blake3pp/trace.hpp>¶
Where a file pipeline's time goes: one record per I/O window, and on request one per working agent per window. update_file(), update_stream() and write_file() over a scheduler fill them when a trace_buffer is set in their options and never otherwise, at a cost of one branch per window; with a buffer set, a handful of clock reads per window and per agent.
The library records; it never allocates, formats or writes. The caller provides the storage, reads it back after the call, and turns it into whatever it needs (blake3pp_bench_file writes Chrome trace JSON). Storage that runs out costs a counted drop, never a stall or a wrong digest. The finest timed unit is one part, a subtree of at least 16 chunks; nothing below that is instrumented.
diagnose_read() and diagnose_write(), at the end of this header, read a finished run's driver_stats and say which side of the pipeline it was waiting on. Call either once per run; neither formats nor prints.
Standard library only, C++20.
agent_record¶
struct blake3pp::agent_record;
One piece of a window's work on one agent: a bulk invocation that compressed at least one part, or the fold of the window's chaining values that ran on the agent that finished last (parts == 0), or on the write side one window's fill.
Opt-in: written only when the trace_buffer was given agent storage.
Data members¶
window¶
std::uint64_t window;
window_record::index of the window this belongs to.
t_begin¶
trace_clock::time_point t_begin;
The first part started (the same clock as window_record).
busy¶
std::chrono::nanoseconds busy;
From the first part starting to the last part ending.
min_part¶
std::chrono::nanoseconds min_part;
The shortest part this invocation compressed.
max_part¶
std::chrono::nanoseconds max_part;
The longest part this invocation compressed.
parts¶
std::uint32_t parts;
Parts this invocation compressed; zero marks the fold that followed the bulk, whose busy is the fold's own time.
part_chunks¶
std::uint32_t part_chunks;
Chunks per part (the same for every part of a window).
cpu¶
std::uint32_t cpu;
The CPU the invocation ran on at t_begin: sched_getcpu() on Linux and FreeBSD, processor group x 64 + number on Windows; UINT32_MAX where the platform cannot say.
file¶
std::uint32_t file;
window_record::file of the window this belongs to.
bands¶
struct blake3pp::bands;
The bands a share of a resource is read in. Every entry point below takes these, so a caller can set its own. They are not calibrated on a thread count: 64% pool-busy is a starving pool on 32 threads while 88% on 16 is already near its ceiling, so a single cut on the pool figure misreads a small machine. The bands apply to each side separately and the reading comes from comparing the two, which is scale-free. Where a figure lands between the bands the run gets no label.
Data members¶
saturated¶
double saturated = 0.90;
At or above this a resource was the wall for the run.
idle¶
double idle = 0.80;
Below this it plainly was not.
tie¶
double tie = 0.05;
Two shares closer than this are the same figure.
buffer_tracer¶
struct blake3pp::buffer_tracer;
Constants¶
traced¶
static constexpr bool traced = true;
Member functions¶
buffer¶
constexpr trace_buffer * buffer() const noexcept;
Data members¶
buf¶
trace_buffer * buf = nullptr;
Not owned: the buffer has to outlive every operation started with this tracer, and nothing reads its records until they have completed.
diagnosis¶
struct blake3pp::diagnosis;
The figures a reading is made from, and the reading.
Member functions¶
measured¶
constexpr bool measured() const noexcept;
Whether there was anything to read: a run with no transfer landed never reached the pipeline.
long_enough¶
constexpr bool long_enough() const noexcept;
Whether the run turned its queue over often enough to be read. A run of a few transfers is its own ramp and drain: the first transfers are served alone and the last leave the queue emptying, so every share here is a transient. Four turns of the queue is the floor.
Data members¶
label¶
bottleneck label = bottleneck::undecided;
first¶
bottleneck first = bottleneck::undecided;
With label == undecided, the two the run could not separate.
second¶
bottleneck second = bottleneck::undecided;
pool_busy¶
double pool_busy = 0.0;
Compressing (reading) or filling (writing), over the pool's whole capacity for the run: 1.0 is every thread busy start to finish.
fill_busy¶
double fill_busy = 0.0;
Writing, the same time over the windows in flight rather than over the machine: one window is one fill task, so this is the share of the generator's actual parallelism that was used.
device_depth¶
unsigned device_depth = 0;
The transfers the I/O engine could have at the device at once, which is what device_queued is a share OF.
The same as depth wherever an asynchronous engine carried the run: the queue the pipeline asked for is the queue the device got. Lower where threads of the driver's own carried it, because then the device sees as many transfers as there are threads however deep the pipeline queued -- and a run read against depth there would be reported as a full queue the device never had.
mean_lane_wait¶
std::chrono::duration<double, std::nano> mean_lane_wait {};
How long a transfer waited for one of those threads before it started, per transfer. None of the device is in it, so this is the measure of too few threads and not of a device that is the wall, and it is directly comparable with mean_service: the two are the wait and the work of the same transfer. Zero wherever an asynchronous engine carried the run.
Per transfer rather than as a share of the wall clock, because the waits of transfers queued together overlap: their sum exceeds the wall clock whenever more than one is waiting, so a share of it means nothing.
device_queued¶
double device_queued = 0.0;
How full the device's queue was, as a share of device_depth: 1.0 reads as a queue that was full for the run, 1/depth as a device that served every transfer alone.
Computed as the summed transfer time over depth times the wall clock, the average transfers outstanding over the slots there were, with one correction: a run whose mean per-transfer time is within bands::tie of its own minimum (device_unqueued) is read as one unqueued slot, whatever the slots showed. The minimum is the only baseline the mean can be read against, since a queue's latency is proportional to its depth; the share of slots is what the minimum alone cannot give, since a device that saturates below the depth in force serves no transfer alone after the first. Both are inferences from the run's timings; the device's internal queue is not observed.
device_busy¶
double device_busy = 0.0;
Writing, the share of the windows in flight the device held, which is directly comparable with fill_busy: a window is either being filled or being written, so the two shares are of the same thing. Not set on the read side, where the pool's capacity and the device's queue are separate resources with no common denominator.
starved¶
double starved = 0.0;
The driver with a window it could not use.
Reading this is structural and says little (see driver_stats::starved); writing it is the generator being behind.
transfers¶
std::uint64_t transfers = 0;
mean_service¶
std::chrono::duration<double, std::nano> mean_service {};
min_service¶
std::chrono::nanoseconds min_service {};
depth¶
std::uint64_t depth = 0;
windows_used¶
std::uint64_t windows_used = 0;
windows_planned¶
std::uint64_t windows_planned = 0;
window_bytes¶
std::size_t window_bytes = 0;
bytes_in_flight¶
std::uint64_t bytes_in_flight = 0;
Nominal bytes outstanding at the device: device_depth times the window. Actual occupancy is lower while the queue ramps up or drains and for a short final window. Reported because the depth alone does not state what a device responds to: four 8 MiB reads outstanding are 32 MiB and four 64 MiB reads are 256, and a striped volume answers the two differently (docs/pipeline.md, "Admission, and the two bounds"). A device-limited reading is a reading at this number.
device_unqueued¶
bool device_unqueued = false;
Heuristic: the run's mean per-transfer time is within bands::tie of its own minimum, which the classifier reads as a device that queued nothing behind any transfer and had capacity to spare.
The device's internal queue is not observed; a device whose latency does not grow with its queue reads the same way.
arena_is_depth¶
bool arena_is_depth = false;
Reading: the run filled its arena and the arena is no wider than the queue depth, so every window the pool holds is a read slot the device cannot use. Always true on the write side, where the two are the same number.
driver_stats¶
struct blake3pp::driver_stats;
What the thread driving the pipeline spent its own time on. The stage shares of a window do not sum to the wall clock once several windows are in flight, so this is the number that says whether the driver is the bottleneck: busy against parked is the thread's own split, and the loop counters say what it was doing when it was busy.
Written only by the driver thread, and only while it is inside its own loop.
The layout is not stable before 1.0: fields may be added, widened or moved between versions. Read them by name, through the build that wrote the record.
Data members¶
busy¶
std::chrono::nanoseconds busy;
Time the driver spent outside a blocking poll: submitting, reaping, running completions and inserting into the reducer.
parked¶
std::chrono::nanoseconds parked;
Time the driver spent inside a blocking poll, waiting for a read or for a window to come back from the pool. The two waits are summed: this field answers whether the driver thread is the bottleneck, and for that it does not matter which of them it was waiting on. device_wait and starved separate them.
iterations¶
std::uint64_t iterations;
Times round the loop: one drain, one round of starts, one flush and one poll each.
polls¶
std::uint64_t polls;
poll() calls, blocking and not.
blocking_polls¶
std::uint64_t blocking_polls;
Of those, the ones that blocked.
wakes¶
std::uint64_t wakes;
Blocking polls released without a completion of their own: a wake from a thread handing a finished window back. One per window is the expected shape; many more means the driver is being woken while it still had work in hand.
queue_runs¶
std::uint64_t queue_runs;
Completions run off the run queue: one per window coming back from the pool, plus any deferred failure.
admission_stalls¶
std::uint64_t admission_stalls;
Windows the scope held back because the reducer had no node free.
max_pending¶
std::uint64_t max_pending;
The most subtrees the reducer held at once: how far ahead of the tree the reads ran, and what the node storage has to cover.
max_reads_in_flight¶
std::uint64_t max_reads_in_flight;
The most reads submitted and not yet landed at once: what the device saw, bounded by the queue depth.
max_windows_in_flight¶
std::uint64_t max_windows_in_flight;
The most windows in flight at once -- reading, on the pool or waiting to reduce -- bounded by the window objects the plan allocated.
read_backend¶
std::array<char, max_read_backend_length+1> read_backend;
The rung the reads actually engaged, NUL-padded: "io_uring+direct", "pread", "readfile" and the rest, with the reason appended when an asynchronous engine was asked for and refused.
Copied rather than referenced, so it outlives the file. Read it through read_backend(), which trims the padding.
transfers_landed¶
std::uint64_t transfers_landed;
Windows whose transfer landed: reads on a read run, writes on a write one. Counted on every run, traced or not.
transfer_bytes¶
std::uint64_t transfer_bytes;
Bytes those transfers moved.
device_wait¶
std::chrono::nanoseconds device_wait;
Summed time the device had the transfers, stamped by whoever performed each one: submission to completion for an asynchronous engine, and around the transfer itself on a thread of the driver's own, which leaves that thread's own queueing outside (lane_wait). NOT a span of the pipeline's timeline. Admission-to-landing contains the device's time but is not it, and the difference goes both ways: it overstates wherever a transfer waits in a queue of the driver's, and understates wherever a driver fills a window before the pipeline asks for it. The per-window spans are in the window records, under their own names.
A driver that cannot attribute (a span in memory, a stream) leaves the admission-to-landing span here instead, and device_depth is then zero.
NEVER divide this by the wall clock. Transfers overlap the pipeline's own work by design -- read-ahead means the transfer for window k+1 runs while the pool hashes window k -- so the sum exceeds the wall clock legitimately and a share of it is meaningless. Divide by transfers_landed for the mean per-transfer latency, and by the wall clock TIMES device_depth for how full the device's queue was, which is what diagnosis::device_queued is.
starved¶
std::chrono::nanoseconds starved;
Time the pipeline could not use a window it already had, for the one reason more depth cannot fix. Reading, that is bytes left and no free window on the pool -- the hash behind the device. Writing, it is the opposite event: the driver with nothing to write because every window is still being generated. Counted on every run.
Reading, this is NOT a measure of how starved the pool was. It counts "no free window", which fires structurally whenever the arena is no wider than the queue depth, so it is nonzero on a run that is purely hash-limited: a 64 MiB x depth 16 arm at 96% agent_busy still showed 1.33 s of it. Read it as "the arena is not wider than the depth" and use agent_busy for the hash side. Writing it is the clean signal it reads like, because there the windows in flight are the generator's parallelism.
queue_depth_final¶
std::uint64_t queue_depth_final;
The queue depth the run finished on: the geometry to pass back as queue_depth to repeat it.
queue_depth_peak¶
std::uint64_t queue_depth_peak;
The deepest queue depth the run reached.
agent_busy¶
std::chrono::nanoseconds agent_busy;
Summed over every window and every agent that took part: time the pool spent compressing on a read run, filling on a write one. Divided by the wall clock and the thread count it is the pool's busy share, which is the hash side's answer to the question device_wait answers for the device. Counted on every run that passes a trace buffer, whether or not it asked for per-window records.
starved is not the same measure and does not substitute for it: see the note on that field.
device_wait_min¶
std::chrono::nanoseconds device_wait_min;
The shortest of those per-transfer times. Zero when nothing landed, and zero where the driver cannot attribute.
It is the baseline the mean is read against. A queue's latency is proportional to its depth by construction, so device_wait / transfers_landed alone cannot say whether the device was the constraint. A mean near depth times this reads as a queue that was full for the run; a mean near this reads as a device with nothing queued behind each transfer. Both are inferences from the run's own timings, not observations of the device's queue. Counted on every run, at one comparison per transfer.
device_depth¶
std::uint64_t device_depth;
The most transfers the I/O engine could have at the device at once: the queue depth in force where an asynchronous engine carried the run, and the threads serving the synchronous rung where it did not (one on Windows, whose synchronous threads share one handle). Zero where the driver cannot say, and the depth in force stands.
What the device's queue is read against, so a rung that serves four transfers at a time is not reported as a full queue of thirty-two. Counted on every run.
lane_wait¶
std::chrono::nanoseconds lane_wait;
Time transfers spent waiting for one of those threads before they started, with none of the device in it. Nonzero only where the transfers were served by threads of the driver's own, and a measure of too few of them rather than of a device that is the wall: the device's time is already outside this. Counted on every run.
null_tracer¶
struct blake3pp::null_tracer;
How a pipeline run records, decided by type.
The blocking entry points take a trace_buffer* in their options and choose between the two policies below at run time, once per call. A sender cannot: its operation state is a type fixed when the receiver is connected, so the senders in <blake3pp/async_io.hpp> take the policy as an argument instead. null_tracer is the default and records nothing, at no cost; buffer_tracer records into the buffer it names.
blake3pp::trace_buffer trace(windows);
auto s = blake3pp::async::async_update_file(ctx, h, path, sched, {},
blake3pp::buffer_tracer{&trace});
Constants¶
traced¶
static constexpr bool traced = false;
Member functions¶
buffer¶
constexpr trace_buffer * buffer() const noexcept;
trace_buffer¶
class blake3pp::trace_buffer;
Caller-owned storage for the records of one or more pipeline runs, handed in through the options' trace field (file_io_options, stream_io_options, file_write_options).
Records are claimed in order until the storage is full; every claim beyond that is counted as a drop. Window records are claimed by the thread driving the pipeline; agent records by any thread, through one atomic increment. A claimed record has exactly one writer, and nothing reads the records until the call has returned.
std::vector<blake3pp::window_record> windows(file_bytes / window_bytes + 1);
blake3pp::trace_buffer trace(windows);
blake3pp::update_file(h, path, {.trace = &trace});
for (const auto& w : trace.windows()) {
// w.t_ready - w.t_wait_begin: the wait for the read
}
Member functions¶
trace_buffer¶
explicit trace_buffer(std::span<window_record> windows, std::span<agent_record> agents={}) noexcept;
| Parameter | |
|---|---|
windows |
Storage for window records; one per window. |
agents |
Storage for agent records; empty leaves agent recording off (wants_agents() is false). |
trace_buffer¶
trace_buffer(const trace_buffer &)=delete;
operator=¶
trace_buffer & operator=(const trace_buffer &)=delete;
claim_window¶
window_record * claim_window() noexcept;
The next window record, zeroed, or nullptr when the storage is full (counted in dropped_windows()).
One thread claims window records.
claim_agent¶
agent_record * claim_agent() noexcept;
The next agent record, zeroed, or nullptr when the storage is full (counted in dropped_agents()) or when no agent storage was given (not counted).
Any thread. Once full, the storage stays full until clear(): later claims are refused without advancing the claim index.
wants_agents¶
bool wants_agents() const noexcept;
Whether agent records are wanted: agent storage was given.
now¶
trace_clock::time_point now() const noexcept;
The current instant on the records' clock.
epoch¶
trace_clock::time_point epoch() const noexcept;
When the buffer was built: a zero a reader of the records may measure from, as the Chrome trace writer does.
clear() keeps it.
windows¶
std::span<const window_record> windows() const noexcept;
The window records claimed so far, in claim order.
agents¶
std::span<const agent_record> agents() const noexcept;
The agent records claimed so far, in claim order.
driver¶
const driver_stats & driver() const noexcept;
Where the driver thread's own time went. Only the pipeline path fills in the counters; the sequential window loop, which has no driver thread, records only the read backend and leaves the rest zeroed.
driver¶
driver_stats & driver() noexcept;
The driver's own record, for the thread that owns the loop.
dropped_windows¶
std::uint64_t dropped_windows() const noexcept;
Window claims refused for lack of storage.
dropped_agents¶
std::uint64_t dropped_agents() const noexcept;
Agent claims refused for lack of storage.
clear¶
void clear() noexcept;
Forgets every record and drop; the epoch stays, so later timestamps remain comparable with earlier ones. Not concurrent with writers.
tracer¶
concept blake3pp::tracer;
What the pipeline asks of a tracing policy: whether its runs are instrumented, decided at compile time, and the buffer they record into.
window_record¶
struct blake3pp::window_record;
One I/O window from the reader handing it out to the reader taking it back.
Constants¶
flag_parallel¶
static constexpr std::uint32_t flag_parallel = 1u <<0;
Bit in flags: the window was fanned out over the scheduler.
flag_last¶
static constexpr std::uint32_t flag_last = 1u <<1;
Bit in flags: the window reaches the end of the file.
flag_short_first¶
static constexpr std::uint32_t flag_short_first = 1u <<2;
Bit in flags: the short window that brings a hasher already part-way through a message back onto a window boundary.
flag_part_run¶
static constexpr std::uint32_t flag_part_run = 1u <<3;
Bit in flags: the window reached the tree as the decomposition of a run of parts rather than as one subtree, because it is neither a whole window of the grid nor one that starts where a node of that size may start.
Only a stream sets it (blake3ppsum's -): a producer that ran dry before filling a window ends it early, and the window after that one is short in turn, bringing the grid back onto its boundary. Both carry this. How many windows ended that way is stream_report::short_flushes.
Data members¶
index¶
std::uint64_t index;
Position of the window within this call, from 0.
bytes¶
std::uint64_t bytes;
Bytes in the window.
t_wait_begin¶
trace_clock::time_point t_wait_begin;
Before the pipeline asked the reader for the window.
t_ready¶
trace_clock::time_point t_ready;
The reader handed the window out; its bytes are in memory.
t_joined¶
trace_clock::time_point t_joined;
The compute is done: every agent has joined, or hasher::update() returned when the window was hashed inline.
t_absorbed¶
trace_clock::time_point t_absorbed;
The chaining values are in the hasher. Equals t_joined for an inline window, which has no separate absorb step.
t_released¶
trace_clock::time_point t_released;
The window's buffer is back with the reader.
agent_busy¶
std::chrono::nanoseconds agent_busy;
Summed over the agents that took part: time spent compressing.
agents_active¶
std::uint32_t agents_active;
Bulk invocations that compressed at least one part.
flags¶
std::uint32_t flags;
flag_parallel, flag_last, flag_short_first, flag_part_run.
slot¶
std::uint32_t slot;
Which window object -- buffer, part table and operation cell -- carried this window. The pipeline reuses a fixed set of them, so this is the track a window's phases belong on when several are in flight; zero on the sequential path, which has one.
file¶
std::uint32_t file;
The file's index in a many-files operation (async_update_files), which fills one buffer with every file's windows; zero for a single file. Files from index UINT32_MAX on all carry UINT32_MAX.
Types¶
trace_clock¶
using trace_clock = std::chrono::steady_clock;
The clock every record is stamped on. Instants are its time_points, absolute (CLOCK_MONOTONIC on Linux), so they join with timestamps other tools take on the same clock; a difference is a duration.
Constants¶
max_read_backend_length¶
constexpr std::size_t max_read_backend_length = 63;
The longest name driver_stats::read_backend holds.
Each engine bounds the read names it can produce, its refusal reasons' numbers at their widest, and asserts at compile time that they fit.
Functions¶
read_backend¶
std::string_view read_backend(const driver_stats &d) noexcept;
The engaged read rung as text; empty when nothing recorded one.
set_read_backend¶
void set_read_backend(driver_stats &d, std::string_view name) noexcept;
Records name in d.
Every engine's read names fit, which each one asserts at compile time; a longer name from elsewhere is cut to the field.
to_string¶
const char * to_string(bottleneck b) noexcept;
b as text: "hash-limited", "device-limited", "arena-limited", "in-flight-limited", "generator-limited", "undecided".
These strings are API. They are what blake3ppsum and blake3ppgen print under --diag, alongside the read-backend strings of read_backend(), which are already read out of benchmark output by hand and by script. A string changes only when the value it names changes meaning.
diagnose_read¶
diagnosis diagnose_read(const driver_stats &d, std::chrono::duration<double, std::nano> wall, unsigned threads, unsigned planned, std::size_t window, bands b={}) noexcept;
A read run's reading. Three facts decide it, in this order: the pool's busy share, the device's queue, and whether the arena is wider than that queue.
The third is a relation and not a size. The windows beyond the reads are what the pool draws on while the device serves the next ones, so where there are none the pool runs dry whenever a window is out. That is also the only case driver_stats::starved can fire in, which is why that counter reads "the arena is not wider than the
depth" and not "the pool starved" -- a purely hash-limited run shows most of its wall clock in it.
It is read last because a device whose queue was full for the run is the wall whatever the arena's width: widening the arena then only buffers. So the arena reading is what is left when neither end was busy and every window the run had was out.
Where the arena was NOT the run's bound and neither end was busy, the fourth reading applies: the device served every transfer as if it were alone, so what the run never had more of is bytes outstanding -- the depth times the window.
Each figure has a band it is read in, and a run that lands in one gets no label: the two candidates are named instead. A figure near its ceiling without reaching it does not say which of itself and the arena the run was waiting on, and on a narrow machine the answer is often neither.
// The plan the run will make, for the arena's width and the window.
const blake3pp::file_io_probe plan = blake3pp::probe_file_io(path);
std::vector<blake3pp::window_record> windows(count);
blake3pp::trace_buffer trace(windows);
const auto t0 = std::chrono::steady_clock::now();
blake3pp::update_file(h, path, sched, {.trace = &trace});
const auto wall = std::chrono::steady_clock::now() - t0;
const auto d = blake3pp::diagnose_read(trace.driver(), wall, threads,
plan.windows, plan.window_bytes);
std::puts(blake3pp::to_string(d.label));
| Parameter | |
|---|---|
d |
The run's counters. |
wall |
Wall clock the caller measured around the call. |
threads |
The compute pool's width. |
planned |
Window objects the plan allocated, which is the arena's width in windows. |
window |
Bytes per window, after the pipeline's rounding. |
b |
The bands each share is read in. |
diagnose_write¶
diagnosis diagnose_write(const driver_stats &d, std::chrono::duration<double, std::nano> wall, unsigned threads, std::size_t window, bands b={}) noexcept;
A write run's reading. The directions are not symmetrical. Writing, the pool FILLS windows and the device drains them, and one window is one fill task, so the windows in flight are the generator's parallelism as well as the device's queue -- the arena and the depth are the same number and there is no third reading between them. The two candidates are the generator and the device, and they share the same windows, so their shares sum to at most one and the reading is which of them held the windows longer.
The windows in flight come from driver_stats::queue_depth_final.
| Parameter | |
|---|---|
d |
The run's counters. |
wall |
Wall clock the caller measured around the call. |
threads |
The compute pool's width. |
window |
Bytes per window, after the pipeline's rounding. |
b |
The bands each share is read in. |
Enumerations¶
bottleneck¶
enum class bottleneck {
hash,
device,
arena,
in_flight,
generator,
undecided
};
What a finished pipeline run was limited by.
The first four are read runs, the fifth is the write side's name for the first, and undecided carries two candidates the run could not separate (diagnosis::first and diagnosis::second).
Enumerators are appended, never inserted, reordered or renamed, the same rule detail/arch.def and detail/io/io_engine.def follow: a caller may switch over this against a library build it did not compile.