Module wprof

Module wprof 

Source
Expand description

Public wire-format constants + assertion helpers for the wprof Perfetto-trace artifacts produced by #[ktstr_test(wprof, ...)] tests.

The wprof trace is generated inside the guest VM and shipped to the host via the MsgType::WprofTrace virtq message; a post-drain pre-pass in test_support::eval::run_ktstr_test_inner_impl reassembles the trace via reassemble_wprof_trace and writes a .wprof.pb file per test run under {sidecar_dir()}/{test_name}-{variant_hash:016x}.wprof.pb — the variant hash keys the artifact to the resolved variant so sibling gauntlet presets of the same test do not clobber each other (same convention as the .repro.failure-dump.json sidecar).

Assertions on the .pb MUST run host-side via the #[ktstr_test(post_vm = ...)] callback, NOT inside the guest test body — the test body runs INSIDE the guest VM and the guest mount table does NOT include a virtio-fs mount of the host sidecar directory. A guest-side std::fs::read(...) on the host sidecar path resolves to a host path the guest cannot open and returns ENOENT regardless of whether the host-side write succeeded.

§Drift-safe test naming

Test authors writing post_vm callbacks should derive .wprof.pb paths through the VmResult::wprof_pb_path method on the &VmResult arg rather than recomputing the path with a hardcoded fn-name literal. The method derives the path from the entry name the macro stamped at compile time — a future rename of the test fn surfaces the drift as a None bail rather than a runtime ENOENT against a stale literal.

The high-level VmResult::assert_wprof_pb_landed sugar collapses the recurring post_vm-callback boilerplate into a single method call. Use it as the default; reach for assert_wprof_pb_shape directly only when the callback owns path resolution (e.g. checking a specific .repro.wprof.pb artifact via VmResult::repro_wprof_pb_path).

Constants§

PERFETTO_TRACE_PACKETS_TAG
Perfetto wire-format leading byte: (1 << 3) | 2 == 0x0a for message Trace { repeated TracePacket packets = 1; } (field=1, wire_type=2 length-delimited). Stable across Perfetto’s published schema history.
WPROF_PB_MIN_BYTES
Minimum wprof .pb file size in bytes. wprof’s init_pb_trace emits a ~4 KB interned-string table (CAT + NAME + ANNK + ANNV ranges, ~216 entries × ~20 bytes wire cost) on every capture regardless of trace activity. A smaller file means wprof either aborted before init_pb_trace OR the .pb write/transport truncated.

Functions§

assert_wprof_pb_shape
Verify the wprof .pb at path exists, is at least WPROF_PB_MIN_BYTES bytes, and leads with PERFETTO_TRACE_PACKETS_TAG.