[−][src]Struct jvm_hprof::Record
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]
&self
) -> Option<Result<LoadClass, Err<(&'_ [u8], ErrorKind)>>>
Returns Some
if the tag is RecordTag::LoadClass and None
otherwise.
pub fn as_stack_frame(
&self
) -> Option<Result<StackFrame, Err<(&'_ [u8], ErrorKind)>>>
[src]
&self
) -> Option<Result<StackFrame, Err<(&'_ [u8], ErrorKind)>>>
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]
&self
) -> Option<Result<StackTrace<'a>, Err<(&'_ [u8], ErrorKind)>>>
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]
&self
) -> Option<Result<HeapDumpSegment<'a>, Err<(&'_ [u8], ErrorKind)>>>
Returns Some
if the tag is RecordTag::HeapDump or RecordTag::HeapDumpSegment and
None
otherwise.
Trait Implementations
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,