Expand description
Opt-in wall-time accounting at solver phase boundaries.
Inclusive phases nest; only exclusive times can be added. One collector can be shared by callers on different threads, with a separate stack per thread. No lock or clock read is required inside a numerical cell/PCG iteration.
Enable it with Control::with_profiling
and read the Profile with
Control::profile after the solve.
The CLI’s profile command writes the same record into its
cfd-craft.native-profile/0.1 envelope; its JSON schema is the
phase_profile_schema of cfd-craft describe. See the
profiling guide.
use cfd_craft::{case::Case, solver::{self, Control}};
let case: Case = serde_json::from_str(json).unwrap();
let control = Control::new(30.0).with_profiling();
let result = solver::run(&case, &control, None)?;
let profile = control.profile()?.expect("profiling enabled");
assert_eq!(profile.phases["step"].calls, 3);
// Exclusive times add up; inclusive times nest and must not be summed.
let total: f64 = profile.phases.values().map(|p| p.exclusive_s).sum();
assert!((total - profile.accounted_exclusive_s).abs() < 1e-12);
// Attempted pressure work covers at least the retained iterations.
assert!(profile.phases["pressure_solve"].work_units >= result.summary.pressure_iterations as u64);Structs§
- Phase
Timing - Accumulated time and work of one phase over all its calls.
- Profile
- A phase profile (schema
cfd-craft.phase-profile/0.1): wall time and work per solver phase. Only exclusive times may be added. Work includes failed attempts, so it can exceed the counters of the retained state. - Span
- A scoped timer; disabled spans do not read a clock or acquire a lock. Dropping on an error path retains the attempted phase and its work.
Enums§
- Phase
- A measured solver phase. Its snake_case name (for example
pressure_solve) is the key inProfile::phases. Phases nest: an enclosing phase’s inclusive time contains its subphases.