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>
impl<'a> Record<'a>
Sourcepub fn as_utf_8(&self) -> Option<Result<Utf8<'a>, Err<(&'_ [u8], ErrorKind)>>>
pub fn as_utf_8(&self) -> Option<Result<Utf8<'a>, Err<(&'_ [u8], ErrorKind)>>>
Returns Some
if the tag is RecordTag::Utf8 and None
otherwise.
Sourcepub fn as_load_class(
&self,
) -> Option<Result<LoadClass, Err<(&'_ [u8], ErrorKind)>>>
pub fn as_load_class( &self, ) -> Option<Result<LoadClass, Err<(&'_ [u8], ErrorKind)>>>
Returns Some
if the tag is RecordTag::LoadClass and None
otherwise.
Sourcepub fn as_stack_frame(
&self,
) -> Option<Result<StackFrame, Err<(&'_ [u8], ErrorKind)>>>
pub fn as_stack_frame( &self, ) -> Option<Result<StackFrame, Err<(&'_ [u8], ErrorKind)>>>
Returns Some
if the tag is RecordTag::StackFrame and None
otherwise.
Sourcepub fn as_stack_trace(
&self,
) -> Option<Result<StackTrace<'a>, Err<(&'_ [u8], ErrorKind)>>>
pub fn as_stack_trace( &self, ) -> Option<Result<StackTrace<'a>, Err<(&'_ [u8], ErrorKind)>>>
Returns Some
if the tag is RecordTag::StackTrace and None
otherwise.
Sourcepub fn as_heap_dump_segment(
&self,
) -> Option<Result<HeapDumpSegment<'a>, Err<(&'_ [u8], ErrorKind)>>>
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.