Crate jvm_hprof

Source
Expand description

A library for parsing hprof files.

See parse_hprof to get started, or see the examples in the repo.

§Examples

Iterating across all records to count how many of each record type there are (adapted from the analyze_hprof example’s record-counts subcommand):

use std::{fs, collections};
use jvm_hprof::{Hprof, parse_hprof, RecordTag, EnumIterable};

fn count_records(file: fs::File) {
    let memmap = unsafe { memmap::MmapOptions::new().map(&file) }.unwrap();

    let hprof: Hprof = parse_hprof(&memmap[..]).unwrap();

    // start with zero counts for all types
    let mut counts = RecordTag::iter()
        .map(|r| (r, 0_u64))
        .collect::<collections::HashMap<RecordTag, u64>>();

    // overwrite zeros with real counts for each record that exists in the hprof
    hprof
        .records_iter()
        .map(|r| r.unwrap().tag())
        .for_each(|tag| {
            counts.entry(tag).and_modify(|c| *c += 1).or_insert(1);
        });

    let mut counts: Vec<(RecordTag, u64)> = counts
        .into_iter()
        .collect::<Vec<(jvm_hprof::RecordTag, u64)>>();

    // highest count on top
    counts.sort_unstable_by_key(|&(_, count)| count);
    counts.reverse();

    for (tag, count) in counts {
        println!("{:?}: {}", tag, count);
    }
}

Modules§

heap_dump
Sub records contained in crate::HeapDumpSegment records.

Structs§

Header
Basic metadata about the hprof
HeapDumpSegment
Contents of a Record with tag RecordTag::HeapDump or RecordTag::HeapDumpSegment.
Hprof
The top level of data loaded from an .hprof file.
Id
Ids are used to identify many things in an hprof file: objects, classes, utf8 blobs, etc.
Ids
Iterator that parses ids.
LoadClass
Contents of a Record with tag RecordTag::LoadClass.
Record
The next level down from the Hprof in the hierarchy of data.
RecordTagIter
Records
Iterator over the Record data in an hprof.
Serial
An alternate means of identification used in parallel with Id.
StackFrame
Contents of a Record with tag RecordTag::StackFrame.
StackTrace
Contents of a Record with tag RecordTag::StackTrace.
SubRecords
Iterator over heap_dump::SubRecord data.
Utf8
Contents of a Record with tag RecordTag::Utf8.

Enums§

IdSize
Hprof ids can be 32 or 64 bit, depending on the system and JVM that the hprof was captured on.
LineNum
A line referenced from a stack frame.
RecordTag
Indicates what type of data is contained in a particular Record.

Traits§

EnumIterable
Allow iterating over enum variants for enums that have #[derive(EnumIter)].

Functions§

parse_hprof
Entry point for parsing.