4 releases

0.1.3 Aug 22, 2018
0.1.2 Aug 8, 2018
0.1.1 Jul 10, 2018
0.1.0 Nov 22, 2017

#43 in Debugging

Download history 31/week @ 2018-05-31 30/week @ 2018-06-07 28/week @ 2018-06-14 58/week @ 2018-06-21 61/week @ 2018-06-28 23/week @ 2018-07-05 51/week @ 2018-07-12 49/week @ 2018-07-19 36/week @ 2018-07-26 59/week @ 2018-08-02 56/week @ 2018-08-09 24/week @ 2018-08-16 34/week @ 2018-08-23

179 downloads per month

MIT/Apache

29KB
701 lines

rstack

CircleCI

Documentation

Remote stack tracing.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Retrieve stack traces of all threads of the process.

This is implemented using the rstack crate, which itself uses libunwind's ability to trace remote processes using ptrace. Because processes cannot ptrace themselves, we're forced to use spawn a child process which does that work.

Example

extern crate rstack_self;

use std::env;
use std::process::Command;
use std::thread;

fn main() {
    if env::args_os().count() > 1 {
        let _ = rstack_self::child();
        return;
    }

    // spawn a second thread just for fun
    thread::spawn(background_thread);

    let exe = env::current_exe().unwrap();
    let trace = rstack_self::trace(Command::new(exe).arg("child")).unwrap();

    println!("{:#?}", trace);
}

fn background_thread() {
    loop {
        thread::park();
    }
}

Dependencies

~2MB
~38K SLoC