Struct Record

Source
pub struct Record<'a> { /* private fields */ }
Expand description

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§

Source§

impl<'a> Record<'a>

Source

pub fn tag(&self) -> RecordTag

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

Source

pub fn micros_since_header_ts(&self) -> u32

Microseconds since the timestamp in the header

Source§

impl<'a> Record<'a>

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Trait Implementations§

Source§

impl<'a> Clone for Record<'a>

Source§

fn clone(&self) -> Record<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Record<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Record<'a>

§

impl<'a> RefUnwindSafe for Record<'a>

§

impl<'a> Send for Record<'a>

§

impl<'a> Sync for Record<'a>

§

impl<'a> Unpin for Record<'a>

§

impl<'a> UnwindSafe for Record<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.