Sim::step phase timing and the CPU-profile bench driver (#147 step 3.1)

Mod side: Sim::step times plan_step, adapt, step_drones, step_moves,
update_sight, step_sams and record, plus the whole step and its untimed
remainder, through sim::profile. The simulation stays SDK-independent (also
built as airdef-core): the adapter installs the host monotonic clock
(game.monotonic-nanos) in init, native tests use std::time::Instant. The
counters are fixed-size, per-thread, read no randomness and change no
decision; /airdef stats reports them as PROFILE chat lines, reset per world.

Driver: raid_bench gains --scheduler in-frame|server-thread (the two
single-player paths, measured separately), HORIZON_MOD_CPU_PROFILE=1, the
per-tick mod-path spans joined to the frame trace (per-frame totals, >25/33 ms
counts, what the worst CPU frames carry), and the mod phase profile read at
idle and battle end with the battle delta. report.json carries mod_cpu,
mod_cpu_ticks, mod_phases_* and the derived correlation. Tests for the new
helpers.

Engine gitlink: mod-path CPU spans + game.monotonic-nanos (API level 32).

Co-Authored-By: Kimi Code <noreply@moonshot.ai>
This commit is contained in:
2026-11-21 12:29:22 +03:00
parent c08b737296
commit 92c058f606
6 changed files with 368 additions and 28 deletions
+12 -8
View File
@@ -41,6 +41,7 @@ pub mod outcome;
mod units;
pub mod why;
pub mod world;
pub mod profile;
#[cfg(test)]
mod balance;
#[cfg(test)]
@@ -1752,25 +1753,27 @@ impl Sim {
});
}
/// One game tick.
/// One game tick. The named phases are timed for the CPU profile (#147 step
/// 3.1); the timing reads no randomness and changes no decision.
pub fn step(&mut self, ground: &mut Ground, player: Option<DVec3>, out: &mut Out) {
profile::begin_step();
self.tick += 1;
self.plan_step(Some(&mut *ground), out);
self.adapt();
profile::time(profile::PLAN, || self.plan_step(Some(&mut *ground), out));
profile::time(profile::ADAPT, || self.adapt());
self.step_refresh(out);
self.step_settling(ground);
self.release_queue(ground, out);
self.begin_recording_if_active();
self.step_drones(ground, player, out);
profile::time(profile::DRONES, || self.step_drones(ground, player, out));
self.step_recon(out);
self.step_later(ground, player, out);
self.step_moves(ground, out);
profile::time(profile::MOVES, || self.step_moves(ground, out));
self.step_supply(out);
self.step_ew(out);
self.update_sight(ground);
profile::time(profile::SIGHT, || self.update_sight(ground));
self.step_lights(ground, out);
self.prepare_ground_strikes(out);
self.step_sams(ground, out);
profile::time(profile::SAMS, || self.step_sams(ground, out));
self.step_missiles(ground, out);
self.step_strikes(ground, player, out);
self.step_fx(ground, out);
@@ -1779,9 +1782,10 @@ impl Sim {
self.step_wrecks(out);
self.step_fires(ground, out);
self.report_wave(out);
self.record();
profile::time(profile::RECORD, || self.record());
let now = self.tick;
self.blasts.retain(|b| now - b.start < b.life as u64);
profile::end_step();
}
// ------------------------------------------------ drones