/// <summary> /// Loads a memory snapshot from the specified 'filePath' and stores the result in 'snapshot'. /// </summary> /// <param name="filePath">Absolute file path</param> public bool LoadFromFile(string filePath) { busyString = "Loading"; using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open)) { using (var reader = new System.IO.BinaryReader(fileStream)) { try { PackedMemorySnapshotHeader.Read(reader, out header, out busyString); if (!header.isValid) { throw new Exception("Invalid header."); } PackedNativeType.Read(reader, out nativeTypes, out busyString); PackedNativeUnityEngineObject.Read(reader, out nativeObjects, out busyString); PackedGCHandle.Read(reader, out gcHandles, out busyString); PackedConnection.Read(reader, out connections, out busyString); PackedMemorySection.Read(reader, out managedHeapSections, out busyString); PackedManagedType.Read(reader, out managedTypes, out busyString); PackedVirtualMachineInformation.Read(reader, out virtualMachineInformation, out busyString); } catch (System.Exception e) { Debug.LogException(e); return(false); } } } return(true); }
public static void Write(System.IO.BinaryWriter writer, PackedVirtualMachineInformation value) { writer.Write(k_Version); writer.Write(value.pointerSize); writer.Write(value.objectHeaderSize); writer.Write(value.arrayHeaderSize); writer.Write(value.arrayBoundsOffsetInHeader); writer.Write(value.arraySizeOffsetInHeader); writer.Write(value.allocationGranularity); writer.Write(value.heapFormatVersion); }
/// <summary> /// Converts an Unity PackedMemorySnapshot to our own format. /// </summary> public static PackedMemorySnapshot FromMemoryProfiler(MemorySnapshotProcessingArgs args) { var source = args.source; var value = new PackedMemorySnapshot(); try { VerifyMemoryProfilerSnapshot(source); value.busyString = "Loading Header"; value.header = PackedMemorySnapshotHeader.FromMemoryProfiler(); value.busyString = string.Format("Loading {0} Native Types", source.nativeTypes.Length); value.nativeTypes = PackedNativeType.FromMemoryProfiler(source.nativeTypes); value.busyString = string.Format("Loading {0} Native Objects", source.nativeObjects.Length); value.nativeObjects = PackedNativeUnityEngineObject.FromMemoryProfiler(source.nativeObjects); value.busyString = string.Format("Loading {0} GC Handles", source.gcHandles.Length); value.gcHandles = PackedGCHandle.FromMemoryProfiler(source.gcHandles); value.busyString = string.Format("Loading {0} Object Connections", source.connections.Length); if (args.excludeNativeFromConnections) { value.connections = ConnectionsFromMemoryProfilerWithoutNativeHACK(value, source); } else { value.connections = PackedConnection.FromMemoryProfiler(source.connections); } value.busyString = string.Format("Loading {0} Managed Heap Sections", source.managedHeapSections.Length); value.managedHeapSections = PackedMemorySection.FromMemoryProfiler(source.managedHeapSections); value.busyString = string.Format("Loading {0} Managed Types", source.typeDescriptions.Length); value.managedTypes = PackedManagedType.FromMemoryProfiler(source.typeDescriptions); value.busyString = "Loading VM Information"; value.virtualMachineInformation = PackedVirtualMachineInformation.FromMemoryProfiler(source.virtualMachineInformation); } catch (System.Exception e) { Debug.LogException(e); value = null; throw; } return(value); }
public static PackedVirtualMachineInformation FromMemoryProfiler(UnityEditor.MemoryProfiler.VirtualMachineInformation source) { var value = new PackedVirtualMachineInformation { pointerSize = source.pointerSize, objectHeaderSize = source.objectHeaderSize, arrayHeaderSize = source.arrayHeaderSize, arrayBoundsOffsetInHeader = source.arrayBoundsOffsetInHeader, arraySizeOffsetInHeader = source.arraySizeOffsetInHeader, allocationGranularity = source.allocationGranularity, heapFormatVersion = source.heapFormatVersion, }; return(value); }
/// <summary> /// Saves the specfified memory snapshot as a file, using the specified 'filePath'. /// </summary> public void SaveToFile(string filePath) { using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.OpenOrCreate)) { using (var writer = new System.IO.BinaryWriter(fileStream)) { PackedMemorySnapshotHeader.Write(writer, header); PackedNativeType.Write(writer, nativeTypes); PackedNativeUnityEngineObject.Write(writer, nativeObjects); PackedGCHandle.Write(writer, gcHandles); PackedConnection.Write(writer, connections); PackedMemorySection.Write(writer, managedHeapSections); PackedManagedType.Write(writer, managedTypes); PackedVirtualMachineInformation.Write(writer, virtualMachineInformation); } } }
public static PackedVirtualMachineInformation FromMemoryProfiler(UnityEditor.Profiling.Memory.Experimental.PackedMemorySnapshot snapshot) { var source = snapshot.virtualMachineInformation; var value = new PackedVirtualMachineInformation { pointerSize = source.pointerSize, objectHeaderSize = source.objectHeaderSize, arrayHeaderSize = source.arrayHeaderSize, arrayBoundsOffsetInHeader = source.arrayBoundsOffsetInHeader, arraySizeOffsetInHeader = source.arraySizeOffsetInHeader, allocationGranularity = source.allocationGranularity, heapFormatVersion = 2019, }; return(value); }
public static void Read(System.IO.BinaryReader reader, out PackedVirtualMachineInformation value, out string stateString) { value = new PackedVirtualMachineInformation(); stateString = "Loading VM Information"; var version = reader.ReadInt32(); if (version >= 1) { value.pointerSize = reader.ReadInt32(); value.objectHeaderSize = reader.ReadInt32(); value.arrayHeaderSize = reader.ReadInt32(); value.arrayBoundsOffsetInHeader = reader.ReadInt32(); value.arraySizeOffsetInHeader = reader.ReadInt32(); value.allocationGranularity = reader.ReadInt32(); value.heapFormatVersion = reader.ReadInt32(); } }