Function alloc_track::thread_report

source ·
pub fn thread_report() -> ThreadReport
Expand description

Generate a memory usage report Note that the numbers are not a synchronized snapshot, and have slight timing skew.

Examples found in repository?
examples/example.rs (line 28)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
fn main() {
    let (sender, receiver) = mpsc::channel();
    std::thread::Builder::new()
        .name("thread2".to_string())
        .spawn(move || thread(receiver))
        .unwrap();

    let mut last_print = Instant::now();
    loop {
        let buf = vec![1u8; 1024];
        sender.send(buf).ok();
        std::thread::sleep(Duration::from_millis(100));
        if last_print.elapsed() > Duration::from_secs(10) {
            last_print = Instant::now();
            let report = alloc_track::backtrace_report(|_, _| true);
            println!("BACKTRACES\n{report}");
            let report = alloc_track::thread_report();
            println!("THREADS\n{report}");
        }
    }
}