use log::error;
fn print_python_stacks(pid: remoteprocess::Pid) -> Result<(), anyhow::Error> {
let config = py_spy::Config::default();
let mut process = py_spy::PythonSpy::new(pid, &config)?;
let traces = process.get_stack_traces()?;
for trace in traces {
println!("Thread {:#X} ({})", trace.thread_id, trace.status_str());
for frame in &trace.frames {
println!("\t {} ({}:{})", frame.name, frame.filename, frame.line);
}
}
Ok(())
}
fn main() {
env_logger::init();
let args: Vec<String> = std::env::args().collect();
let pid = if args.len() > 1 {
args[1].parse().expect("invalid pid")
} else {
error!("you must specify a pid!");
return;
};
if let Err(e) = print_python_stacks(pid) {
error!("failed to print stack traces: {:?}", e);
}
}