feat: report OpenCV runtime settings for performance debugging
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -28,6 +28,9 @@ struct PreviewFrame {
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user