diff --git a/HeapShot.Reader/Event.cs b/HeapShot.Reader/Event.cs index 8d26847..42b0775 100644 --- a/HeapShot.Reader/Event.cs +++ b/HeapShot.Reader/Event.cs @@ -47,17 +47,18 @@ public enum EventType Heap = 6, Sample = 7, Runtime = 8, - Coverage = 9 + Coverage = 9, + Meta = 10, } public class Backtrace { - public ulong Flags; +// public ulong Flags; public long[] Frame; public Backtrace (LogFileReader reader) { - Flags = reader.ReadULeb128 (); +// Flags = reader.ReadULeb128 (); ulong num = reader.ReadULeb128 (); Frame = new long[num]; for (ulong i = 0; i < num; i++) { @@ -87,6 +88,12 @@ public ulong TimeDiff { public const byte TYPE_GC_HANDLE_CREATED_BT = 6 << 4; public const byte TYPE_GC_HANDLE_DESTROYED_BT = 7 << 4; + public const byte TYPE_GC_FINALIZE_START = 8 << 4; + public const byte TYPE_GC_FINALIZE_END = 9 << 4; + public const byte TYPE_GC_FINALIZE_OBJECT_START = 10 << 4; + public const byte TYPE_GC_FINALIZE_OBJECT_END = 11 << 4; + + public const byte TYPE_SYNC_POINT = 0 << 4; public static Event CreateEvent (LogFileReader reader, EventType type, byte extendedInfo) { switch (type) { @@ -108,8 +115,14 @@ public static Event CreateEvent (LogFileReader reader, EventType type, byte exte case TYPE_GC_HANDLE_DESTROYED: case TYPE_GC_HANDLE_DESTROYED_BT: return HandleDestroyedGcEvent.Read (reader, extendedInfo); - } - throw new InvalidOperationException ("unknown gc type:" + extendedInfo); + case TYPE_GC_FINALIZE_START: + case TYPE_GC_FINALIZE_END: + return HandleFinalizeEvent.Read(reader, extendedInfo); + case TYPE_GC_FINALIZE_OBJECT_START: + case TYPE_GC_FINALIZE_OBJECT_END: + return HandleFinalizeObjectEvent.Read(reader, extendedInfo); + } + throw new InvalidOperationException ("unknown gc type:" + extendedInfo); case EventType.Heap: return HeapEvent.Read (reader, extendedInfo); case EventType.Metadata: @@ -124,8 +137,10 @@ public static Event CreateEvent (LogFileReader reader, EventType type, byte exte return RuntimeEvent.Read (reader, extendedInfo); case EventType.Coverage: return CoverageEvent.Read (reader, extendedInfo); - } - throw new InvalidOperationException ("invalid event type " + type); + case EventType.Meta: + return MetaEvent.Read(reader, extendedInfo); + } + throw new InvalidOperationException ("invalid event type " + type); } public static Event Read (LogFileReader reader) @@ -193,10 +208,12 @@ public override object Accept (EventVisitor visitor) public class GcEvent : Event { - public readonly GcEventType EventType; // GC event (MONO_GC_EVENT_* from profiler.h) - public readonly ulong Generation; // GC generation event refers to - - public enum GcEventType { + //public readonly GcEventType EventType; // GC event (MONO_GC_EVENT_* from profiler.h) + //public readonly ulong Generation; // GC generation event refers to + public readonly GcEventType EventType; // GC event (MONO_GC_EVENT_* from profiler.h) + public readonly byte Generation; // GC generation event refers to + + public enum GcEventType { Start, MarkStart, MarkEnd, @@ -212,11 +229,13 @@ public enum GcEventType { GcEvent (LogFileReader reader) { TimeDiff = reader.ReadULeb128 (); - EventType = (GcEventType) reader.ReadULeb128 (); - Generation = reader.ReadULeb128 (); - } - - public static new Event Read (LogFileReader reader) + //EventType = (GcEventType) reader.ReadULeb128 (); + //Generation = reader.ReadULeb128 (); + EventType = (GcEventType)reader.ReadByte(); + Generation = reader.ReadByte(); + } + + public static new Event Read (LogFileReader reader) { return new GcEvent (reader); } @@ -303,9 +322,47 @@ public override object Accept (EventVisitor visitor) return visitor.Visit (this); } } - - // type == Methadata - public class MetadataEvent : Event + public class HandleFinalizeObjectEvent : Event + { + public readonly long Object; // object pointer differences from obj_base + + HandleFinalizeObjectEvent(LogFileReader reader, byte exinfo) + { + TimeDiff = reader.ReadULeb128(); + Object = reader.ReadSLeb128(); + } + + public static Event Read(LogFileReader reader, byte exinfo) + { + return new HandleFinalizeObjectEvent(reader, exinfo); + } + + public override object Accept(EventVisitor visitor) + { + return visitor.Visit(this); + } + } + public class HandleFinalizeEvent : Event + { + + HandleFinalizeEvent(LogFileReader reader, byte exinfo) + { + TimeDiff = reader.ReadULeb128(); + } + + public static Event Read(LogFileReader reader, byte exinfo) + { + return new HandleFinalizeEvent(reader, exinfo); + } + + public override object Accept(EventVisitor visitor) + { + return visitor.Visit(this); + } + } + + // type == Methadata + public class MetadataEvent : Event { public enum MetaDataType : byte { @@ -321,7 +378,7 @@ public enum MetaDataType : byte public readonly long Pointer; // pointer of the metadata type depending on mtype public readonly long Domain; // domain id as a pointer - public readonly ulong Flags; // must be 0 +// public readonly ulong Flags; // must be 0 public readonly string Name; // full class/image file or thread name public readonly long Image; // MonoImage* as a pointer difference from ptr_base @@ -334,30 +391,32 @@ public enum MetaDataType : byte switch (MType) { case MetaDataType.Class: Image = reader.ReadSLeb128 (); - Flags = reader.ReadULeb128 (); +// Flags = reader.ReadULeb128 (); Name = reader.ReadNullTerminatedString (); break; case MetaDataType.Image: - Flags = reader.ReadULeb128 (); +// Flags = reader.ReadULeb128 (); Name = reader.ReadNullTerminatedString (); break; case MetaDataType.Assembly: - Flags = reader.ReadULeb128 (); +// Flags = reader.ReadULeb128 (); Name = reader.ReadNullTerminatedString (); break; case MetaDataType.Thread: - Flags = reader.ReadULeb128 (); - if (reader.Header.Format < 11 || (reader.Header.Format > 10 && extendedInfo == 0)) { - Name = reader.ReadNullTerminatedString (); - } - break; + // Flags = reader.ReadULeb128 (); + //if (reader.Header.Format < 11 || (reader.Header.Format > 10 && extendedInfo == 0)) { + // Name = reader.ReadNullTerminatedString (); + //} + if (extendedInfo == 0) + Name = reader.ReadNullTerminatedString(); + break; case MetaDataType.Domain: - Flags = reader.ReadULeb128 (); +// Flags = reader.ReadULeb128 (); if (extendedInfo == 0) Name = reader.ReadNullTerminatedString (); break; case MetaDataType.Context: - Flags = reader.ReadULeb128 (); +// Flags = reader.ReadULeb128 (); Domain = reader.ReadSLeb128 (); break; default: @@ -423,10 +482,11 @@ public class ExceptionEvent : Event public const byte TYPE_THROW = 0 << 4; public const byte TYPE_CLAUSE = 1 << 4; public const byte TYPE_EXCEPTION_BT = 1 << 7; - - // Type clause - public readonly ulong ClauseType; // finally/catch/fault/filter - public readonly ulong ClauseNum; // the clause number in the method header + + // Type clause + // public readonly ulong ClauseType; // finally/catch/fault/filter + public readonly byte ClauseType; // finally/catch/fault/filter + public readonly ulong ClauseNum; // the clause number in the method header public readonly long Method; // MonoMethod* as a pointer difference from the last such pointer or the buffer method_base // Type throw @@ -438,7 +498,8 @@ public class ExceptionEvent : Event TimeDiff = reader.ReadULeb128 (); byte subtype = (byte)(exinfo & ~TYPE_EXCEPTION_BT); if (subtype == TYPE_CLAUSE) { - ClauseType = reader.ReadULeb128 (); + //ClauseType = reader.ReadULeb128 (); + ClauseType = reader.ReadByte(); ClauseNum = reader.ReadULeb128 (); Method = reader.ReadSLeb128 (); } else if (subtype == TYPE_THROW) { @@ -534,26 +595,33 @@ public enum EventType HeapEvent (LogFileReader reader, byte exinfo) { - if (exinfo == TYPE_HEAP_START) { + if (exinfo == TYPE_HEAP_START) { Type = EventType.Start; TimeDiff = reader.ReadULeb128 (); } else if (exinfo == TYPE_HEAP_END) { Type = EventType.End; TimeDiff = reader.ReadULeb128 (); } else if (exinfo == TYPE_HEAP_ROOT) { - Type = EventType.Root; + //omanuke + TimeDiff = reader.ReadULeb128(); + + Type = EventType.Root; ulong nroots = reader.ReadULeb128 (); reader.ReadULeb128 (); // gcs - RootRefs = new long [nroots]; + RootRefs = new long [nroots]; RootRefTypes = new RootType [nroots]; RootRefExtraInfos = new ulong [nroots]; for (ulong n=0; n