jfrs

Crates.iojfrs
lib.rsjfrs
version0.2.5
sourcesrc
created_at2022-09-04 08:01:36.315555
updated_at2023-10-18 10:35:32.200604
descriptionJava Flight Recorder reader for Rust
homepage
repositoryhttps://github.com/ocadaruma/jfrs
max_upload_size
id658172
size86,253
Okada Haruki (ocadaruma)

documentation

README

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());
        }
    }
}
Commit count: 79

cargo fmt