fix: add model loading progress logs

Log each ONNX model load with name, features, batch_size, and elapsed time.
Makes the 39s startup gap visible instead of silent.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
DaLaw2 2026-04-03 19:52:51 +08:00
parent c1f7a0aedd
commit 82d2f53b4b
2 changed files with 24 additions and 1 deletions

View File

@ -1,9 +1,13 @@
use std::path::PathBuf;
use std::time::Instant;
use macros::log;
use tract_onnx::prelude::*;
use crate::infrastructure::app_config::AppConfig;
use crate::model::detection::ml_detection::RunnableModel;
use crate::model::error::ml::MLError;
use crate::model::log::ml::MLLog;
use crate::model::system::config::MLInferenceConfig;
pub struct MLModels {
@ -36,13 +40,26 @@ impl MLModels {
fn loader(model: &str, features: usize, batch_size: usize) -> Result<RunnableModel, MLError> {
let model_path = PathBuf::from("models").join(model);
log!(MLLog::ModelLoading(
model.to_string(),
features,
batch_size
));
let start = Instant::now();
let load = || -> Result<RunnableModel, Box<dyn std::error::Error>> {
let mut model = onnx().model_for_path(&model_path)?;
model.set_input_fact(0, f32::fact([batch_size, features]).into())?;
Ok(model.into_optimized()?.into_runnable()?)
};
load().map_err(|_| MLError::ModelLoadFailed(model_path))
let result = load().map_err(|_| MLError::ModelLoadFailed(model_path));
let elapsed_ms = start.elapsed().as_millis() as u64;
log!(MLLog::ModelLoadComplete(model.to_string(), elapsed_ms));
result
}
pub fn get_model_info(&self, name: &str) -> String {

View File

@ -45,6 +45,12 @@ loggable! {
#[error("ML circuit breaker RESET: inference re-enabled after {cooldown_secs}s cooldown")]
CircuitBreakerReset { cooldown_secs: u64 } => tracing::Level::WARN,
#[error("Loading ONNX model '{name}' (features={features}, batch_size={batch_size})...")]
ModelLoading { name: String, features: usize, batch_size: usize } => tracing::Level::INFO,
#[error("Model '{name}' loaded and optimized in {elapsed_ms}ms")]
ModelLoadComplete { name: String, elapsed_ms: u64 } => tracing::Level::INFO,
#[error("Model watcher started, monitoring models/ for .onnx changes")]
ModelWatcherStarted => tracing::Level::INFO,