py_spy/lib.rs
1//! py-spy: a sampling profiler for python programs
2//!
3//! This crate lets you use py-spy as a rust library, and gather stack traces from
4//! your python process programmatically.
5//!
6//! # Example:
7//!
8//! ```rust,no_run
9//! fn print_python_stacks(pid: py_spy::Pid) -> Result<(), anyhow::Error> {
10//! // Create a new PythonSpy object with the default config options
11//! let config = py_spy::Config::default();
12//! let mut process = py_spy::PythonSpy::new(pid, &config)?;
13//!
14//! // get stack traces for each thread in the process
15//! let traces = process.get_stack_traces()?;
16//!
17//! // Print out the python stack for each thread
18//! for trace in traces {
19//! println!("Thread {:#X} ({})", trace.thread_id, trace.status_str());
20//! for frame in &trace.frames {
21//! println!("\t {} ({}:{})", frame.name, frame.filename, frame.line);
22//! }
23//! }
24//! Ok(())
25//! }
26//! ```
27#[macro_use]
28extern crate anyhow;
29#[macro_use]
30extern crate log;
31
32pub mod binary_parser;
33pub mod config;
34#[cfg(target_os = "linux")]
35pub mod coredump;
36#[cfg(feature = "unwind")]
37mod cython;
38pub mod dump;
39#[cfg(feature = "unwind")]
40mod native_stack_trace;
41mod python_bindings;
42mod python_data_access;
43mod python_interpreters;
44pub mod python_process_info;
45pub mod python_spy;
46mod python_threading;
47pub mod sampler;
48pub mod stack_trace;
49pub mod timer;
50mod utils;
51mod version;
52
53pub use config::Config;
54pub use python_spy::PythonSpy;
55pub use remoteprocess::Pid;
56pub use stack_trace::Frame;
57pub use stack_trace::StackTrace;