11 releases

0.2.5 Oct 18, 2023
0.2.4 Sep 21, 2023
0.2.0 Aug 29, 2023
0.1.4 Jan 4, 2023
0.1.3 Sep 17, 2022

#670 in Parser implementations

Apache-2.0

75KB
2K SLoC

jfrs

CI Crate

Java Flight Recorder reader for Rust

Features

Read events (low-level API)

fn main() {
    let mut reader = JfrReader::new(File::open("/path/to/recording.jfr").unwrap());

    for (reader, chunk) in reader.chunks().flatten() {
        for event in reader.events(&chunk)
            .flatten()
            .filter(|e| e.class.name() == "jdk.ExecutionSample")
        {
            let thread_name = event.value()
                .get_field("sampledThread")
                .and_then(|v| v.get_field("osName"))
                .and_then(|v| <&str>::try_from(v.value).ok())
                .unwrap();
            println!("sampled thread: {}", thread_name);
        }
    }
}

[Experimental] Deserialize events as Rust struct

Note As of now, deserialization performance is very poor. See tuning_notes.md for the details.

Though low-level API provides full functionality to interpret the events as you need, usually we want to map known JFR events to the Rust structure.

jfrs also provides serde-rs based deserialization feature.

fn main() {
    let mut reader = JfrReader::new(File::open("/path/to/recording.jfr").unwrap());

    for (mut reader, chunk) in reader.chunks().flatten() {
        for event in reader.events(&chunk)
            .flatten()
            .filter(|e| e.class.name() == "jdk.ExecutionSample")
        {
            let sample: ExecutionSample = from_event(&event).unwrap();
            println!("sampled thread: {}", sample.sampled_thread.and_then(|t| t.os_name).unwrap());
        }
    }
}

Dependencies

~0.3–1MB
~21K SLoC