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

#640 in Parser implementations

Download history 12/week @ 2024-07-01 59/week @ 2024-07-29 34/week @ 2024-09-23 5/week @ 2024-10-07 22/week @ 2024-10-14

61 downloads per month

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.4–1MB
~22K SLoC