static public int constructor(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.Profiling.Memory.Experimental.MemoryProfiler o; o = new UnityEngine.Profiling.Memory.Experimental.MemoryProfiler(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
public static void TakeTempSnapshot(Action <string, bool> finishCallback, CaptureFlags captureFlags = CaptureFlags.ManagedObjects | CaptureFlags.NativeObjects) { string[] array = Application.dataPath.Split(new char[] { '/' }); string str = array[array.Length - 2]; string path = Application.temporaryCachePath + "/" + str + ".snap"; MemoryProfiler.TakeSnapshot(path, finishCallback, captureFlags); }
static public int constructor(IntPtr l) { try { UnityEngine.Profiling.Memory.Experimental.MemoryProfiler o; o = new UnityEngine.Profiling.Memory.Experimental.MemoryProfiler(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
private static byte[] PrepareMetadata() { bool flag = MemoryProfiler.createMetaData == null; byte[] result; if (flag) { result = new byte[0]; } else { MetaData metaData = new MetaData(); MemoryProfiler.createMetaData(metaData); bool flag2 = metaData.content == null; if (flag2) { metaData.content = ""; } bool flag3 = metaData.platform == null; if (flag3) { metaData.platform = ""; } int num = 2 * metaData.content.Length; int num2 = 2 * metaData.platform.Length; int num3 = num + num2 + 12; byte[] array = new byte[num3]; int offset = 0; offset = MemoryProfiler.WriteIntToByteArray(array, offset, metaData.content.Length); offset = MemoryProfiler.WriteStringToByteArray(array, offset, metaData.content); offset = MemoryProfiler.WriteIntToByteArray(array, offset, metaData.platform.Length); offset = MemoryProfiler.WriteStringToByteArray(array, offset, metaData.platform); result = array; } return(result); }
public static void TakeSnapshot(string path, Action <string, bool> finishCallback, Action <string, bool, DebugScreenCapture> screenshotCallback, CaptureFlags captureFlags = CaptureFlags.ManagedObjects | CaptureFlags.NativeObjects) { bool flag = MemoryProfiler.isCompiling; if (flag) { UnityEngine.Debug.LogError("Canceling snapshot, there is a compilation in progress."); } else { bool flag2 = MemoryProfiler.m_SnapshotFinished != null; if (flag2) { UnityEngine.Debug.LogWarning("Canceling snapshot, there is another snapshot in progress."); finishCallback(path, false); } else { MemoryProfiler.m_SnapshotFinished += finishCallback; MemoryProfiler.m_SaveScreenshotToDisk += screenshotCallback; MemoryProfiler.StartOperation((uint)captureFlags, MemoryProfiler.m_SaveScreenshotToDisk != null, path, false); } } }
public static bool Convert(UnityEditor.MemoryProfiler.PackedMemorySnapshot snapshot, string writePath) { MemorySnapshotFileWriter writer = null; try { writer = new MemorySnapshotFileWriter(writePath); } catch (Exception e) { Debug.LogError("Failed to create snapshot file: " + e.Message); return(false); } //snapshot version will always be the remap connections version as that is the last change affecting this format writer.WriteEntry(EntryType.Metadata_Version, (uint)FormatHistory.NativeConnectionsAsInstanceIdsVersion); //timestamp with conversion date writer.WriteEntry(EntryType.Metadata_RecordDate, (ulong)DateTime.Now.Ticks); //prepare metadata string platform = "Unknown"; string content = "Converted Snapshot"; int stringDataLength = (platform.Length + content.Length) * sizeof(char); byte[] metaDataBytes = new byte[stringDataLength + (sizeof(int) * 3)]; // add space for serializing the lengths of the strings int offset = 0; offset = ExperimentalMemoryProfiler.WriteIntToByteArray(metaDataBytes, offset, content.Length); offset = ExperimentalMemoryProfiler.WriteStringToByteArray(metaDataBytes, offset, content); offset = ExperimentalMemoryProfiler.WriteIntToByteArray(metaDataBytes, offset, platform.Length); offset = ExperimentalMemoryProfiler.WriteStringToByteArray(metaDataBytes, offset, platform); offset = ExperimentalMemoryProfiler.WriteIntToByteArray(metaDataBytes, offset, 0); // Write metadata writer.WriteEntryArray(EntryType.Metadata_UserMetadata, metaDataBytes); writer.WriteEntry(EntryType.Metadata_CaptureFlags, (UInt32)CaptureFlags.ManagedObjects); //capture just managed // Write managed heap sections for (int i = 0; i < snapshot.managedHeapSections.Length; ++i) { var heapSection = snapshot.managedHeapSections[i]; writer.WriteEntry(EntryType.ManagedHeapSections_StartAddress, heapSection.m_StartAddress); writer.WriteEntryArray(EntryType.ManagedHeapSections_Bytes, heapSection.m_Bytes); } // Write managed types int fieldDescriptionCount = 0; for (int i = 0; i < snapshot.typeDescriptions.Length; ++i) { var type = snapshot.typeDescriptions[i]; writer.WriteEntry(EntryType.TypeDescriptions_Flags, (UInt32)type.m_Flags); writer.WriteEntry(EntryType.TypeDescriptions_BaseOrElementTypeIndex, type.baseOrElementTypeIndex); writer.WriteEntry(EntryType.TypeDescriptions_TypeIndex, type.typeIndex); if (!type.isArray) { var typeFields = type.fields; int[] fieldIndices = new int[typeFields.Length]; for (int j = 0; j < typeFields.Length; ++j) { var field = typeFields[j]; fieldIndices[j] = fieldDescriptionCount; ++fieldDescriptionCount; writer.WriteEntry(EntryType.FieldDescriptions_Offset, field.offset); writer.WriteEntry(EntryType.FieldDescriptions_TypeIndex, field.typeIndex); writer.WriteEntry(EntryType.FieldDescriptions_Name, field.name); writer.WriteEntry(EntryType.FieldDescriptions_IsStatic, field.isStatic); } writer.WriteEntryArray(EntryType.TypeDescriptions_FieldIndices, fieldIndices); writer.WriteEntryArray(EntryType.TypeDescriptions_StaticFieldBytes, type.staticFieldBytes); } else { writer.WriteEntryArray(EntryType.TypeDescriptions_FieldIndices, new int[0]); writer.WriteEntryArray(EntryType.TypeDescriptions_StaticFieldBytes, new byte[0]); } writer.WriteEntry(EntryType.TypeDescriptions_Name, type.name); writer.WriteEntry(EntryType.TypeDescriptions_Assembly, type.assembly); writer.WriteEntry(EntryType.TypeDescriptions_TypeInfoAddress, type.typeInfoAddress); writer.WriteEntry(EntryType.TypeDescriptions_Size, type.size); } //write managed gc handles for (int i = 0; i < snapshot.gcHandles.Length; ++i) { var handle = snapshot.gcHandles[i]; writer.WriteEntry(EntryType.GCHandles_Target, handle.target); } //write managed connections for (int i = 0; i < snapshot.connections.Length; ++i) { var connection = snapshot.connections[i]; writer.WriteEntry(EntryType.Connections_From, connection.from); writer.WriteEntry(EntryType.Connections_To, connection.to); } //write native types for (int i = 0; i < snapshot.nativeTypes.Length; ++i) { var nativeType = snapshot.nativeTypes[i]; writer.WriteEntry(EntryType.NativeTypes_NativeBaseTypeArrayIndex, nativeType.nativeBaseTypeArrayIndex); writer.WriteEntry(EntryType.NativeTypes_Name, nativeType.name); } //write stub root reference for all native objects to point to, as the old format did not capture these writer.WriteEntry(EntryType.NativeRootReferences_AreaName, "Invalid Root"); writer.WriteEntry(EntryType.NativeRootReferences_AccumulatedSize, (ulong)0); writer.WriteEntry(EntryType.NativeRootReferences_Id, (long)0); writer.WriteEntry(EntryType.NativeRootReferences_ObjectName, "Invalid Root Object"); //write native objects for (int i = 0; i < snapshot.nativeObjects.Length; ++i) { var nativeObject = snapshot.nativeObjects[i]; writer.WriteEntry(EntryType.NativeObjects_Name, nativeObject.name); writer.WriteEntry(EntryType.NativeObjects_InstanceId, nativeObject.instanceId); writer.WriteEntry(EntryType.NativeObjects_Size, (ulong)nativeObject.size); writer.WriteEntry(EntryType.NativeObjects_NativeTypeArrayIndex, nativeObject.nativeTypeArrayIndex); writer.WriteEntry(EntryType.NativeObjects_HideFlags, (UInt32)nativeObject.hideFlags); writer.WriteEntry(EntryType.NativeObjects_Flags, (UInt32)nativeObject.m_Flags); writer.WriteEntry(EntryType.NativeObjects_NativeObjectAddress, (ulong)nativeObject.nativeObjectAddress); writer.WriteEntry(EntryType.NativeObjects_RootReferenceId, (long)0); } //write virtual machine information writer.WriteEntry(EntryType.Metadata_VirtualMachineInformation, snapshot.virtualMachineInformation); writer.Close(); return(true); }
public static void TakeSnapshot(string path, Action <string, bool> finishCallback, CaptureFlags captureFlags = CaptureFlags.ManagedObjects | CaptureFlags.NativeObjects) { MemoryProfiler.TakeSnapshot(path, finishCallback, null, captureFlags); }