[][src]Struct jvm_hprof::Record

pub struct Record<'a> { /* fields omitted */ }

The next level down from the Hprof in the hierarchy of data.

See RecordTag for the different types of data that can be in a Record.

Performance

Records are generic and lightweight: the parsing done to get a Record is just loading a couple of bytes to get the tag and timestamp, and a slice that contains the "body" of the record, so iterating across all Records without inspecting the body of each one is cheap. Even huge heap dumps might have only tens of thousands of Records.

Since iterating records is very fast but parsing the contents may not be (e.g. a sequence of 2GiB HeapDumpSegment records), records are especially amenable to parallel processing, e.g. with rayon's par_bridge().

Examples

Because enum variants in Rust can't (yet) have methods that exist only for one variant, parsing the body of the record is done via as_* methods like as_utf_8(). If the tag of a given record is [RecordTag::Utf8], then as_utf_8() will return Some(...), and all other as_... will return None, and so forth. So, in practice, this might look like:

use jvm_hprof::{Record, RecordTag, Utf8};

fn print_utf8(record: &Record) {
    match record.tag() {
        RecordTag::Utf8 => {
            // unwrap strips the Option(),
            // which we know is Some because of the tag
            let utf8: Utf8 = record.as_utf_8().unwrap()
                // apply real error handling as needed
                .expect("parsing error -- corrupt hprof? Bug in parser?");

            // build a str from the bytes, validating UTF-8
            let utf_str: &str = utf8.text_as_str()
                .expect("Surely the JVM wouldn't write a Utf8 record with invalid UTF-8");

            println!("utf8 contents: {}", utf_str);
        }
        _ => println!("tag was {:?}, not utf8", record.tag())
    }
}

Implementations

impl<'a> Record<'a>[src]

pub fn tag(&self) -> RecordTag[src]

The tag, which determines which of the as_* methods it is suitable to call.

pub fn micros_since_header_ts(&self) -> u32[src]

Microseconds since the timestamp in the header

impl<'a> Record<'a>[src]

pub fn as_utf_8(&self) -> Option<Result<Utf8<'a>, Err<(&'_ [u8], ErrorKind)>>>[src]

Returns Some if the tag is RecordTag::Utf8 and None otherwise.

pub fn as_load_class(
    &self
) -> Option<Result<LoadClass, Err<(&'_ [u8], ErrorKind)>>>
[src]

Returns Some if the tag is RecordTag::LoadClass and None otherwise.

pub fn as_stack_frame(
    &self
) -> Option<Result<StackFrame, Err<(&'_ [u8], ErrorKind)>>>
[src]

Returns Some if the tag is RecordTag::StackFrame and None otherwise.

pub fn as_stack_trace(
    &self
) -> Option<Result<StackTrace<'a>, Err<(&'_ [u8], ErrorKind)>>>
[src]

Returns Some if the tag is RecordTag::StackTrace and None otherwise.

pub fn as_heap_dump_segment(
    &self
) -> Option<Result<HeapDumpSegment<'a>, Err<(&'_ [u8], ErrorKind)>>>
[src]

Returns Some if the tag is RecordTag::HeapDump or RecordTag::HeapDumpSegment and None otherwise.

Trait Implementations

impl<'a> Clone for Record<'a>[src]

impl<'a> Copy for Record<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Record<'a>[src]

impl<'a> Send for Record<'a>[src]

impl<'a> Sync for Record<'a>[src]

impl<'a> Unpin for Record<'a>[src]

impl<'a> UnwindSafe for Record<'a>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.