Skip to content

Statistics, profiling, and cost models ​

Start with final event counts to establish what a run did, then enable selected timing sites to investigate where it waited or worked. Keep inputs, access order, schemas, consumer work and execution settings fixed when comparing runs.

Choose a measurement

Always-on counters ​

Every successful run returns RunStats, even when profiling is disabled.

FieldInterpretation
elapsedWorker and plan-thread wall time after setup
setup_elapsedFrame sizing and shared-state setup before execution
countersAccesses, decoded rows, hits, admissions, bytes, and stalls
ioRequest counts, requested and returned bytes, request-size buckets
peak_spanLargest access lead past the execution frontier
cache_bytes, private_bytesFrame reservations
outputsPer-schema access, decode, row-hit, and process counts
profileTiming report when enabled
onlineOnline compiler statistics when used

counters.accesses counts one delivery per schema per position. It is not the number of distinct cells or batches. Multiple schemas of one position can share one decode. page_hits count page uses served by cached frames; row_hits refer to decoded input rows.

Live Run::snapshot() exposes published counters. Use final statistics after successful completion for reporting. Workers publish every 1024 completed positions, so a small or recently started run can still show zero counters. Snapshots are not a simultaneous observation of all threads.

The loading example requests five positions through two schemas. It asserts stats.counters.accesses == 10, although there are only five logical output rows. stats.outputs follows schema order: each schema receives five accesses. Global decoded_rows counts shared decoding once; per-output counts credit each schema using that decode, so their sum can differ from the global count.

io.read_bytes counts bytes returned to the application, including reads served by the OS page cache. It is not physical-device traffic. io.sizes groups requests by pages: 1, 2, 3–4, 5–8, 9–16, 17–32, and 33+. See memory and performance for reservation and measurement boundaries.

Enable selected timing sites ​

Configure the mask when constructing the loader; no Cargo feature is needed:

rust
use cellpack::loader::LoaderConfig;
use cellpack::prof::SiteMask;

let config = LoaderConfig {
    profile: Some(SiteMask::parse(&["io", "cpu", "wait"])?),
    ..LoaderConfig::default()
};

This fragment fits into the complete loading program. SiteMask::ALL selects every site; narrow the mask once you know which stage you want to investigate.

GroupMain coverage
ioSubmit, reap, I/O wait, request latency
cpuDecode, row admission/gather, map, process
waitFrame, plan, window, and output waits; idle
plannerAccess generation, row/page selection, freezing, and publication
calibrateSites used by cost calibration workflows

Individual names such as decode, process, and wait.gen are also accepted. prof::SITES describes each site's name, record kind, parent, and per-schema detail. Names are case-sensitive. worker is both a site and a declared group; parsing that name selects the site first, timing worker lifetime only. Use explicit groups for stage coverage, or expand the worker group's member list from prof::GROUPS as shown in the prof reference.

Untimed and timed implementations are compiled together. profile = None selects the untimed implementation. A timed implementation checks the selected site mask; disabled sites avoid clock reads. Instrumentation still changes the workload, so assess its overhead before interpreting performance. Some(SiteMask::NONE) still selects the timed implementation with an empty mask; use None for the untimed baseline.

Diagnose a limiting stage ​

Follow the waiting or work
Output wait

Check consumer speed and retained batch leases.

Plan wait

Inspect compiler settings, lookahead horizon and compiler CPU capacity.

Frame wait

Inspect dependency distance, cache admission and storage latency.

Decode time

Evaluate data layout, kernels and decoded-row reuse.

Map or process time

Inspect panel width, conversion and callback work.

I/O wait

Compare request sizes, storage limits and concurrency.

Timing sites can overlap. Summing nested durations does not reconstruct wall time.

Read the enabled site reports alongside counters:

ObservationNext check
wait.ring growsConsumer progress and batch leases; I/O concurrency cannot free held slots
wait.plan growsOnline planner progress and plan.* timing
wait.window growsExecution window and the oldest unfinished position
wait.gen growsThe access admitting the required cached frame and its I/O completion
decode, map or process dominatesStored layout, output dimensions, conversions and process details
io.wait or io.latency growsBackend, request sizes, storage state and CPU scheduling

These are leads, not standalone diagnoses. Pread completes reads inside issue; it does not have the same submit/reap/wait breakdown as Uring. io.latency measures queueing through completion harvest, including software delay, rather than device-only latency.

After consuming a run, inspect its returned stats:

rust
if let Some(report) = &stats.profile {
    if let Some(site) = report.site("decode") {
        println!("decode: {} calls, {:?} total", site.calls, site.time);
    }
    if let Some(site) = report.site("process") {
        for detail in &site.details {
            println!("process key {}: {} calls, {:?}", detail.key, detail.calls, detail.time);
        }
    }
}

Expect an entry for each enabled site, including zero-call sites; durations depend on the workload. report.site(name) == None means the site was not selected or its name is unknown, rather than proving it took no time.

Site durations sum intervals across threads and can exceed run wall time. Parent/child intervals also overlap. self_time subtracts only recorded direct children; it changes with the mask and is not CPU utilization. Histogram pairs contain a bucket lower bound in nanoseconds and a count, not exact latencies.

Cost model ​

CostModel expresses device request capacity, byte bandwidth, worker physical cores, memory bandwidth, and operation costs in core-seconds. Its output entries follow schema order. Loader::plan_options starts with NVMe default costs based on Loader::cores(); replace them with measurements for your machine and workload.

For a priced window, let R be requests, B storage bytes, C core-seconds, M cached-row memory bytes, and s the non-overlap share:

d=max(R/IOPS,B/BW),c=C/coresT=max(max(d,c)+smin(d,c), M/memory_BW).

This is the current CostModel::seconds model, not measured runtime. service exposes each resource's service time; prices derives marginal costs used by planning decisions. Row gather/admission and process costs must match the actual routes and schema behavior.

to_bytes / from_bytes serialize the binary cost model. Optional serde enables Serde integration for applications that manage structured calibration records. The Rust core does not automatically discover or calibrate your hardware.

Use cache planning to apply a cost model. The opt reference owns exact fields and serialization contracts; Python cost tools provide optional collection and calibration workflows.

API: RunStats, SiteMask, ProfileReport, CostModel.