Documentation ¶
Overview ¶
core is a package for parsing JVM .hprof files.
Models are based on the following JDK source: https://github.com/openjdk/jdk/blob/c1e39faaa99ee62ff626ffec9f978ed0f8ffaca1/src/hotspot/share/services/heapDumper.cpp
It contains basic utility primitives that should be used to parse the given .hprof dump in the form of io.Reader. Functions in this packages are not aware of the position in the input, they are simple primitives to parse structures that .hprof could contain. The whole structure of .hprof file is written in code comment at the link above.
Index ¶
- Constants
- type FileHeader
- type HprofFrame
- type HprofGcClassDump
- type HprofGcClassDumpConstantPoolRecord
- type HprofGcClassDumpInstanceDumpHeader
- type HprofGcClassDumpInstanceFieldsRecord
- type HprofGcClassDumpStaticFieldsRecord
- type HprofGcObjArrayDumpHeader
- type HprofGcPrimArrayDumpHeader
- type HprofGcRootJavaFrame
- type HprofGcRootJniGlobal
- type HprofGcRootJniLocal
- type HprofGcRootStickyClass
- type HprofGcRootThreadObj
- type HprofLoadClass
- type HprofTrace
- type HprofUtf8
- type Identifier
- type JavaType
- type JavaValue
- type LineNumber
- type PrimitiveParser
- func (parser *PrimitiveParser) ParseByteSeq(n int) ([]byte, error)
- func (parser *PrimitiveParser) ParseIdentifier() (Identifier, error)
- func (parser *PrimitiveParser) ParseInt32() (int32, error)
- func (parser *PrimitiveParser) ParseJavaType() (JavaType, error)
- func (parser *PrimitiveParser) ParseJavaValue(ty JavaType) (JavaValue, error)
- func (parser *PrimitiveParser) ParseLineNumber() (LineNumber, error)
- func (parser *PrimitiveParser) ParseUint16() (uint16, error)
- func (parser *PrimitiveParser) ParseUint32() (uint32, error)
- func (parser *PrimitiveParser) ParseUint8() (uint8, error)
- type RecordHeader
- type RecordParser
- func (parser *RecordParser) ParseHprofFrame() (HprofFrame, error)
- func (parser *RecordParser) ParseHprofGcClassDump() (HprofGcClassDump, error)
- func (parser *RecordParser) ParseHprofGcClassDumpInstanceDumpHeader() (HprofGcClassDumpInstanceDumpHeader, error)
- func (parser *RecordParser) ParseHprofGcObjArrayDumpHeader() (HprofGcObjArrayDumpHeader, error)
- func (parser *RecordParser) ParseHprofGcPrimArrayDumpHeader() (HprofGcPrimArrayDumpHeader, error)
- func (parser *RecordParser) ParseHprofGcRootJavaFrame() (HprofGcRootJavaFrame, error)
- func (parser *RecordParser) ParseHprofGcRootJniGlobal() (HprofGcRootJniGlobal, error)
- func (parser *RecordParser) ParseHprofGcRootJniLocal() (HprofGcRootJniLocal, error)
- func (parser *RecordParser) ParseHprofGcRootStickyClass() (HprofGcRootStickyClass, error)
- func (parser *RecordParser) ParseHprofGcRootThreadObj() (HprofGcRootThreadObj, error)
- func (parser *RecordParser) ParseHprofLoadClass() (HprofLoadClass, error)
- func (parser *RecordParser) ParseHprofTrace() (HprofTrace, error)
- func (parser *RecordParser) ParseHprofUtf8(remaining uint32) (HprofUtf8, error)
- func (parser *RecordParser) ParseRecordHeader() (RecordHeader, error)
- func (parser *RecordParser) ParseSubRecordHeader() (SubRecordHeader, error)
- func (parser *RecordParser) ReadBytes(n int) ([]byte, error)
- type SizeInfo
- type SubRecordHeader
- type SubRecordType
- type Tag
Constants ¶
const (
ValidProfileVersion = "JAVA PROFILE 1.0.2"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileHeader ¶
func ParseFileHeader ¶
func ParseFileHeader(heapDump io.Reader) (FileHeader, error)
ParseFileHeader reads the header of .hprof file.
type HprofFrame ¶
type HprofFrame struct { StackFrameId Identifier MethodNameId Identifier MethodSignatureId Identifier SourceFileNameId Identifier ClassSerialNumber uint32 LineNumber LineNumber }
type HprofGcClassDump ¶
type HprofGcClassDump struct { ClassObjectId Identifier StackTraceSerialNumber uint32 SuperclassObjectId Identifier ClassloaderObjectId Identifier SignersObjectId Identifier ProtectionDomainObjectId Identifier InstanceSize int32 SizeOfConstantPool uint16 ConstantPoolRecords []HprofGcClassDumpConstantPoolRecord NumberOfStaticFields uint16 StaticFieldRecords []HprofGcClassDumpStaticFieldsRecord NumberOfInstanceFields uint16 InstanceFieldRecords []HprofGcClassDumpInstanceFieldsRecord }
type HprofGcClassDumpInstanceDumpHeader ¶
type HprofGcClassDumpInstanceDumpHeader struct { ObjectId Identifier StackTraceSerialNumber uint32 ClassObjectId Identifier NumberOfBytesThatFollow uint32 }
type HprofGcClassDumpInstanceFieldsRecord ¶
type HprofGcClassDumpInstanceFieldsRecord struct { InstanceFieldName Identifier Ty JavaType }
type HprofGcClassDumpStaticFieldsRecord ¶
type HprofGcClassDumpStaticFieldsRecord struct { StaticFieldName Identifier Ty JavaType Value JavaValue }
type HprofGcObjArrayDumpHeader ¶
type HprofGcObjArrayDumpHeader struct { ArrayObjectId Identifier StackTraceSerialNumber uint32 NumberOfElements uint32 ArrayClassId Identifier }
type HprofGcPrimArrayDumpHeader ¶
type HprofGcPrimArrayDumpHeader struct { ArrayObjectId Identifier StackTraceSerialNumber uint32 NumberOfElements uint32 ElementType JavaType }
type HprofGcRootJavaFrame ¶
type HprofGcRootJavaFrame struct { ObjectId Identifier ThreadSerialNumber uint32 FrameNumberInStackTrace uint32 }
type HprofGcRootJniGlobal ¶
type HprofGcRootJniGlobal struct { ObjectId Identifier JniGlobalRefId Identifier }
type HprofGcRootJniLocal ¶
type HprofGcRootJniLocal struct { ObjectId Identifier ThreadSerialNumber uint32 FrameNumberInStackTrace uint32 }
type HprofGcRootStickyClass ¶
type HprofGcRootStickyClass struct {
ObjectId Identifier
}
type HprofGcRootThreadObj ¶
type HprofGcRootThreadObj struct { ThreadObjectId Identifier ThreadSequenceNumber uint32 StackTraceSequenceNumber uint32 }
type HprofLoadClass ¶
type HprofLoadClass struct { ClassSerialNumber uint32 ClassObjectId Identifier StackTraceSerialNumber uint32 ClassNameId Identifier }
type HprofTrace ¶
type HprofTrace struct { StackTraceSerialNumber uint32 ThreadSerialNumber uint32 NumberOfFrames uint32 StackFrameIds []Identifier }
type HprofUtf8 ¶
type HprofUtf8 struct { Identifier Identifier Characters string }
type Identifier ¶
type Identifier uint64
Identifier represents Java identifier. uint64 is used to store it because actual size can be 4 or 8 bytes.
type JavaType ¶
type JavaType uint8
JavaType if representation of Java types with string values for readability.
type JavaValue ¶
JavaValue wraps type of the constant and the value converted to corresponding Go type.
func (JavaValue) ToObject ¶
func (jv JavaValue) ToObject() (Identifier, error)
type LineNumber ¶
type LineNumber int32
LineNumber is the wrapper for int32 with verbose values for some constants (Unknown, CompiledMethod, NativeMethod). It's stringified integer if > 0.
const ( Unknown LineNumber = -1 CompiledMethod LineNumber = -2 NativeMethod LineNumber = -3 )
func (LineNumber) String ¶
func (l LineNumber) String() string
type PrimitiveParser ¶
type PrimitiveParser struct {
// contains filtered or unexported fields
}
PrimitiveParser is a parser that allows to read low-level primitives like u1, u2, u4, etc. numbers and other types that presented in heap dump.
func NewPrimitiveParser ¶
func NewPrimitiveParser(heapDump io.Reader, idSize uint32) *PrimitiveParser
func (*PrimitiveParser) ParseByteSeq ¶
func (parser *PrimitiveParser) ParseByteSeq(n int) ([]byte, error)
ParseByteSeq reads n bytes from underlying reader
func (*PrimitiveParser) ParseIdentifier ¶
func (parser *PrimitiveParser) ParseIdentifier() (Identifier, error)
ParseIdentifier reads JVM identifier that can be 32 or 64 bit value. It depends on the machine on which JVM runs.
func (*PrimitiveParser) ParseInt32 ¶
func (parser *PrimitiveParser) ParseInt32() (int32, error)
ParseInt32 reads 32-bit signed (i4) number.
func (*PrimitiveParser) ParseJavaType ¶
func (parser *PrimitiveParser) ParseJavaType() (JavaType, error)
ParseJavaType reads JavaType which is 8-bit unsigned under the hood.
func (*PrimitiveParser) ParseJavaValue ¶
func (parser *PrimitiveParser) ParseJavaValue(ty JavaType) (JavaValue, error)
ParseJavaValue reads JavaValue of given JavaType and stores it in struct along with the type for future use.
func (*PrimitiveParser) ParseLineNumber ¶
func (parser *PrimitiveParser) ParseLineNumber() (LineNumber, error)
ParseLineNumber reads LineNumber which is 32-bit signed under the hood.
func (*PrimitiveParser) ParseUint16 ¶
func (parser *PrimitiveParser) ParseUint16() (uint16, error)
ParseUint16 reads 16-bit unsigned (u2) number.
func (*PrimitiveParser) ParseUint32 ¶
func (parser *PrimitiveParser) ParseUint32() (uint32, error)
ParseUint32 reads 32-bit unsigned (u4) number.
func (*PrimitiveParser) ParseUint8 ¶
func (parser *PrimitiveParser) ParseUint8() (uint8, error)
ParseUint8 reads 8-bit unsigned (u1) number.
type RecordHeader ¶
type RecordParser ¶
type RecordParser struct {
// contains filtered or unexported fields
}
RecordParser is used to parse HprofRecords from raw heap dump.
func NewRecordParser ¶
func NewRecordParser(heapDump io.Reader, idSize uint32) *RecordParser
func (*RecordParser) ParseHprofFrame ¶
func (parser *RecordParser) ParseHprofFrame() (HprofFrame, error)
ParseHprofFrame reads HPROF_FRAME record.
func (*RecordParser) ParseHprofGcClassDump ¶
func (parser *RecordParser) ParseHprofGcClassDump() (HprofGcClassDump, error)
ParseHprofGcClassDump reads HPROF_GC_CLASS_DUMP sub-record.
func (*RecordParser) ParseHprofGcClassDumpInstanceDumpHeader ¶
func (parser *RecordParser) ParseHprofGcClassDumpInstanceDumpHeader() (HprofGcClassDumpInstanceDumpHeader, error)
ParseHprofGcClassDumpInstanceDumpHeader reads "header" information from HPROF_GC_INSTANCE_DUMP. It does not read array of instance field values, so ParseHprofGcClassDumpInstanceDumpRecord does.
func (*RecordParser) ParseHprofGcObjArrayDumpHeader ¶
func (parser *RecordParser) ParseHprofGcObjArrayDumpHeader() (HprofGcObjArrayDumpHeader, error)
ParseHprofGcObjArrayDumpHeader reads "header" information from HPROF_GC_OBJ_ARRAY_DUMP. It does not read array of elements, so ParseHprofGcObjArrayDumpRecord does.
func (*RecordParser) ParseHprofGcPrimArrayDumpHeader ¶
func (parser *RecordParser) ParseHprofGcPrimArrayDumpHeader() (HprofGcPrimArrayDumpHeader, error)
ParseHprofGcPrimArrayDumpHeader reads "header" information from HPROF_GC_PRIM_ARRAY_DUMP. It does not read array of elements, so ParseHprofGcPrimArrayDumpRecord does.
func (*RecordParser) ParseHprofGcRootJavaFrame ¶
func (parser *RecordParser) ParseHprofGcRootJavaFrame() (HprofGcRootJavaFrame, error)
ParseHprofGcRootJavaFrame reads HPROF_GC_ROOT_JAVA_FRAME sub-record.
func (*RecordParser) ParseHprofGcRootJniGlobal ¶
func (parser *RecordParser) ParseHprofGcRootJniGlobal() (HprofGcRootJniGlobal, error)
ParseHprofGcRootJniGlobal reads HPROF_GC_ROOT_JNI_GLOBAL sub-record.
func (*RecordParser) ParseHprofGcRootJniLocal ¶
func (parser *RecordParser) ParseHprofGcRootJniLocal() (HprofGcRootJniLocal, error)
ParseHprofGcRootJniLocal reads HPROF_GC_ROOT_JNI_LOCAL sub-record.
func (*RecordParser) ParseHprofGcRootStickyClass ¶
func (parser *RecordParser) ParseHprofGcRootStickyClass() (HprofGcRootStickyClass, error)
ParseHprofGcRootStickyClass reads HPROF_GC_ROOT_STICKY_CLASS sub-record.
func (*RecordParser) ParseHprofGcRootThreadObj ¶
func (parser *RecordParser) ParseHprofGcRootThreadObj() (HprofGcRootThreadObj, error)
ParseHprofGcRootThreadObj reads HPROF_GC_ROOT_THREAD_OBJ sub-record.
func (*RecordParser) ParseHprofLoadClass ¶
func (parser *RecordParser) ParseHprofLoadClass() (HprofLoadClass, error)
ParseHprofLoadClass reads HPROF_LOAD_CLASS record.
func (*RecordParser) ParseHprofTrace ¶
func (parser *RecordParser) ParseHprofTrace() (HprofTrace, error)
ParseHprofTrace reads HPROF_TRACE record.
func (*RecordParser) ParseHprofUtf8 ¶
func (parser *RecordParser) ParseHprofUtf8(remaining uint32) (HprofUtf8, error)
ParseHprofUtf8 reads HPROF_UTF8 record
func (*RecordParser) ParseRecordHeader ¶
func (parser *RecordParser) ParseRecordHeader() (RecordHeader, error)
ParseRecordHeader reads the header of Hprof records which contain information about record's TAG and remaining bytes.
func (*RecordParser) ParseSubRecordHeader ¶
func (parser *RecordParser) ParseSubRecordHeader() (SubRecordHeader, error)
ParseSubRecordHeader reads the type of the sub-record inside HPROF_HEAP_DUMP_SEGMENT.
type SizeInfo ¶
type SizeInfo struct {
// contains filtered or unexported fields
}
func NewSizeInfo ¶
type SubRecordHeader ¶
type SubRecordHeader struct {
SubRecordType SubRecordType
}
type SubRecordType ¶
type SubRecordType byte
const ( HprofGcRootJniGlobalType SubRecordType = 0x01 HprofGcRootJniLocalType SubRecordType = 0x02 HprofGcRootJavaFrameType SubRecordType = 0x03 HprofGcRootStickyClassType SubRecordType = 0x05 HprofGcRootThreadObjType SubRecordType = 0x08 HprofGcClassDumpType SubRecordType = 0x20 HprofGcInstanceDumpType SubRecordType = 0x21 HprofGcObjArrayDumpType SubRecordType = 0x22 HprofGcPrimArrayDumpType SubRecordType = 0x23 )
const ( HprofHeapDumpEndSubRecord SubRecordType = 0x2c HprofHeapDumpSegmentSubRecord SubRecordType = 0x1c )
these duplicated tags from Tags to be able to exit parse subrecords loop.
func (SubRecordType) String ¶
func (s SubRecordType) String() string