From ef4ae15abb32330533083cb9873b42feb71036df Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 8 Nov 2026 13:43:16 +0100 Subject: [PATCH] feat: report OpenCV runtime settings for performance debugging --- src/diagnostics.rs | 37 +++++++++++++++++++++++++++++++++++++ src/main.rs | 3 +++ 2 files changed, 40 insertions(+) diff --git a/src/diagnostics.rs b/src/diagnostics.rs index e3cc293..95395b8 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -1,6 +1,43 @@ //! Low-overhead, rate-limited timing warnings written to stderr. use std::time::{Duration, Instant}; +/// Log the effective runtime settings, rather than assuming an init script +/// forwarded the requested environment or restarted an existing process. +pub fn log_runtime() -> opencv::Result<()> { + use opencv::core; + eprintln!( + "[performance INFO] pid={} architecture={} debug_assertions={} OPENCV_FOR_THREADS_NUM={:?}", + std::process::id(), + std::env::consts::ARCH, + cfg!(debug_assertions), + std::env::var_os("OPENCV_FOR_THREADS_NUM"), + ); + eprintln!( + "[performance INFO] OpenCV threads={} visible_cpus={} optimized={} cpu_features={}", + core::get_num_threads()?, + core::get_number_of_cpus()?, + core::use_optimized()?, + core::get_cpu_features_line()?, + ); + let build = core::get_build_information()?; + for line in build.lines().map(str::trim).filter(|line| { + [ + "General configuration", + "CPU/HW features:", + "Baseline:", + "Dispatched code generation:", + "Parallel framework:", + "Intel IPP:", + "OpenCL:", + ] + .iter() + .any(|prefix| line.starts_with(prefix)) + }) { + eprintln!("[performance INFO] OpenCV build: {line}"); + } + Ok(()) +} + const LOG_INTERVAL: Duration = Duration::from_secs(5); pub struct SlowLog { diff --git a/src/main.rs b/src/main.rs index 1ba6db6..335dc0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,9 @@ struct PreviewFrame { } fn main() -> Result<(), Box> { + if let Err(error) = diagnostics::log_runtime() { + eprintln!("Failed to read OpenCV runtime diagnostics: {error}"); + } let mut cam = videoio::VideoCapture::new(0, videoio::CAP_V4L2).expect("Failed to get video capture"); let mut frame = Mat::default();