[][src]Crate py_spy

py-spy: a sampling profiler for python programs

This crate lets you use py-spy as a rust library, and gather stack traces from your python process programmatically.

Example:

fn print_python_stacks(pid: py_spy::Pid) -> Result<(), failure::Error> {
    // Create a new PythonSpy object with the default config options
    let config = py_spy::Config::default();
    let mut process = py_spy::PythonSpy::new(pid, &config)?;

    // get stack traces for each thread in the process
    let traces = process.get_stack_traces()?;

    // Print out the python stack for each thread
    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(())
}

Modules

sampler
timer

Structs

Config

Options on how to collect samples from a python process

Frame

Information about a single function call in a stack trace

PythonSpy

Lets you retrieve stack traces of a running python program

StackTrace

Call stack for a single python thread

Type Definitions

Pid