use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;
use std::path::Path;
use super::config::PyProfilerConfig;
use super::types::PyProfileReport;
#[pyfunction]
#[pyo3(signature = (path, config=None))]
pub fn analyze_file(
py: Python<'_>,
path: &str,
config: Option<&PyProfilerConfig>,
) -> PyResult<PyProfileReport> {
let profiler = match config {
Some(cfg) => cfg.to_profiler(),
None => crate::api::Profiler::new(),
};
let path = path.to_string();
let report = py
.detach(|| profiler.analyze_file(Path::new(&path)))
.map_err(|e| PyRuntimeError::new_err(format!("Analysis failed: {}", e)))?;
Ok(PyProfileReport::new(report))
}