deb: record per-phase build timings, shown by pkh deb profile

Time every Phase the build flow announces through enter_phase — the
chroot bootstrap (tarball download, extraction, finalization), the
apt phases, patch application, the build and binary steps and the
artifact retrieval — and land the ordered profile in the record's
manifest of every run, failed builds included: their profile ends
at the phase the error propagated out of.

Timing rides the enter_phase choke point instead of new measurement
sites, so a phase added later profiles itself. The manifest field
is additive (serde default, skipped when absent), so older manifests
keep loading without a schema bump. The coarse timings stay the
source of the deb list columns: they measure the apt transactions
themselves, where the profile measures whole phases.

pkh deb profile renders a record's profile through the same
read-only record discovery as pkh deb log — the newest record of
the tree, or an id prefix as shown by pkh deb list — so
record_for_log becomes the neutral find_record. Phase keys are
storage names, distinct from the display labels; Phase::from_key
turns them back and a test keeps both in sync.
This commit is contained in:
vhaudiquet committed 2026-10-02 14:17:15 +02:00
1 parent 7055d69152
commit 2ab2ff91e9
8 files changed
+552 -38

No files matched your search

+29 -7
View File
@@ -1,6 +1,6 @@
use crate::context::{self, Context, ContextConfig};
use crate::deb::session::{self, Session};
use crate::deb::{Phase, enter_phase};
use crate::deb::{BuildProfiler, Phase, enter_phase};
use crate::interrupt::CleanupHookGuard;
use crate::report::BuildView;
use directories::ProjectDirs;
@@ -511,14 +511,20 @@ impl EphemeralContextGuard {
/// * `arch` - Optional target architecture. If provided and different from host,
/// downloads a chroot for that architecture (uses qemu_binfmt transparently)
/// * `base_ctx` - The base context to use for creating the chroot
/// * `profiler` - The per-phase build profile to feed (the chroot
/// bootstrap's phases of the record's `pkh deb profile`)
pub async fn new_with_context(
series: &str,
arch: Option<&str>,
mirror: Option<&str>,
base_ctx: Arc<Context>,
view: &dyn BuildView,
profiler: &mut BuildProfiler,
) -> Result<Self, Box<dyn Error>> {
Self::new_internal(None, series, arch, mirror, base_ctx, view, false, None).await
Self::new_internal(
None, series, arch, mirror, base_ctx, view, false, None, profiler,
)
.await
}
/// Create the ephemeral build context inside `session`'s chroot.
@@ -536,6 +542,8 @@ impl EphemeralContextGuard {
/// * `ccache_dir` - The shared ccache directory to mount at the
/// chroot's `/var/cache/pkh-ccache` (`pkh deb` computes it from the
/// build identity; `None` leaves the chroot unshared)
/// * `profiler` - The per-phase build profile to feed (the chroot
/// bootstrap's phases of the record's `pkh deb profile`)
#[allow(clippy::too_many_arguments)]
pub async fn new_for_session(
session: Session,
@@ -546,6 +554,7 @@ impl EphemeralContextGuard {
view: &dyn BuildView,
keep_upper: bool,
ccache_dir: Option<&Path>,
profiler: &mut BuildProfiler,
) -> Result<Self, Box<dyn Error>> {
Self::new_internal(
Some(session),
@@ -556,6 +565,7 @@ impl EphemeralContextGuard {
view,
keep_upper,
ccache_dir,
profiler,
)
.await
}
@@ -570,6 +580,7 @@ impl EphemeralContextGuard {
view: &dyn BuildView,
keep_upper: bool,
ccache_dir: Option<&Path>,
profiler: &mut BuildProfiler,
) -> Result<Self, Box<dyn Error>> {
// Save the globally-installed context so Drop can restore exactly
// this handle: concurrent builds install their own ephemeral
@@ -638,6 +649,7 @@ impl EphemeralContextGuard {
base_ctx.clone(),
view,
ccache_dir,
profiler,
)
.await
{
@@ -711,6 +723,7 @@ impl EphemeralContextGuard {
Arc::clone(&self.ephemeral_ctx)
}
#[allow(clippy::too_many_arguments)]
async fn download_and_extract_chroot(
series: &str,
arch: Option<&str>,
@@ -719,6 +732,7 @@ impl EphemeralContextGuard {
ctx: Arc<context::Context>,
view: &dyn BuildView,
ccache_dir: Option<&Path>,
profiler: &mut BuildProfiler,
) -> Result<Option<fs::File>, Box<dyn Error>> {
// The chroot is per-run scratch: nothing is reused, so never
// extract over stale content.
@@ -778,7 +792,7 @@ impl EphemeralContextGuard {
series,
arch
);
enter_phase(view, Phase::PreparingChroot);
enter_phase(view, Phase::PreparingChroot, profiler);
Self::download_chroot_tarball(series, arch, mirror, &tarball_path, ctx, view).await?;
} else {
log::debug!(
@@ -790,12 +804,19 @@ impl EphemeralContextGuard {
// Extract tarball to chroot directory
log::debug!("Extracting chroot tarball to {}...", chroot_path.display());
enter_phase(view, Phase::ExtractingChroot);
enter_phase(view, Phase::ExtractingChroot, profiler);
Self::extract_tarball(&tarball_path, chroot_path, view)?;
// Create device nodes, bind-mount /proc and share the apt cache
let apt_cache_lock =
Self::finalize_chroot(series, arch, chroot_path, ctx_for_devices, view, ccache_dir)?;
let apt_cache_lock = Self::finalize_chroot(
series,
arch,
chroot_path,
ctx_for_devices,
view,
ccache_dir,
profiler,
)?;
// The bootstrap's tarball digest is recorded by the caller (the
// record's fork gate compares it against the cache later).
@@ -814,13 +835,14 @@ impl EphemeralContextGuard {
ctx: Arc<context::Context>,
view: &dyn BuildView,
ccache_dir: Option<&Path>,
profiler: &mut BuildProfiler,
) -> Result<Option<fs::File>, Box<dyn Error>> {
if !Self::device_nodes_ready(chroot_path) {
// The tar crate materializes the tarball's device entries as
// empty regular files (see [Self::DEVICE_NODES]), so readiness
// is keyed on the nodes being char devices, not on presence.
log::debug!("Creating device nodes in chroot...");
enter_phase(view, Phase::FinalizingChroot);
enter_phase(view, Phase::FinalizingChroot, profiler);
Self::create_device_nodes(chroot_path, ctx.clone())?;
}