7 releases

new 0.1.6 Nov 21, 2024
0.1.5 Oct 2, 2024
0.1.4 Nov 25, 2021
0.1.3 Mar 11, 2021
0.1.2 Apr 4, 2020

#59 in Profiling

Download history 4112/week @ 2024-08-04 2123/week @ 2024-08-11 4643/week @ 2024-08-18 4864/week @ 2024-08-25 4751/week @ 2024-09-01 6124/week @ 2024-09-08 5396/week @ 2024-09-15 6378/week @ 2024-09-22 5608/week @ 2024-09-29 5840/week @ 2024-10-06 9843/week @ 2024-10-13 8602/week @ 2024-10-20 3991/week @ 2024-10-27 3697/week @ 2024-11-03 1662/week @ 2024-11-10 2568/week @ 2024-11-17

12,099 downloads per month
Used in 3 crates (via tract)

MIT/Apache

20KB
355 lines

Instrumentation Probe for Readings

Readings goal is to make process vital metrics intrumentation as easy as possible.

This is the instrumentation library that must be embedded in the client code.

Please refer to the Readings

// this is optional but the cost may be worth it. YMMV. It instruments
// Rust global allocator.
readings_probe::instrumented_allocator!();

fn main() -> readings_probe::ReadingsResult<()> {
    // setup the probe
    let mut probe =
        readings_probe::Probe::new(std::fs::File::create("readings.out").unwrap()).unwrap();

    // We will use an AtomicI64 to communicate a user-defined metrics ("progress") to the probe.
    let progress = probe.register_i64("progress".to_string())?;

    // Starts the probe (1sec i a lot. heartbeat can be realistically set as low as a few millis).
    probe.spawn_heartbeat(std::time::Duration::from_millis(1000))?;

    // do some stuff, update progress
    let percent_done = 12;
    progress.store(percent_done, std::sync::atomic::Ordering::Relaxed);

    // do more stuff, log an event
    probe.log_event("about to get crazy")?;

    // still more stuff, and another event
    probe.log_event("done")?;
    Ok(())
}

Dependencies

~0.3–1MB
~18K SLoC