py_spy_for_datakit/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_for_datakit::Pid) -> Result<(), anyhow::Error> {
10//! // Create a new PythonSpy object with the default config options
11//! let config = py_spy_for_datakit::Config::default();
12//! let mut process = py_spy_for_datakit::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 config;
33pub mod binary_parser;
34#[cfg(unwind)]
35mod cython;
36#[cfg(unwind)]
37mod native_stack_trace;
38mod python_bindings;
39mod python_interpreters;
40mod python_spy;
41mod python_data_access;
42mod python_threading;
43pub mod sampler;
44mod stack_trace;
45pub mod timer;
46mod utils;
47mod version;
48
49pub use python_spy::PythonSpy;
50pub use config::Config;
51pub use stack_trace::StackTrace;
52pub use stack_trace::Frame;
53pub use remoteprocess::Pid;