Exemple #1
0
        /// <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);
        }
Exemple #2
0
        public static         PackedNativeUnityEngineObject[] FromMemoryProfiler(UnityEditor.MemoryProfiler.PackedNativeUnityEngineObject[] source)
        {
            var value = new PackedNativeUnityEngineObject[source.Length];

            for (int n = 0, nend = source.Length; n < nend; ++n)
            {
                value[n] = new PackedNativeUnityEngineObject
                {
                    isPersistent        = source[n].isPersistent,
                    isDontDestroyOnLoad = source[n].isDontDestroyOnLoad,
                    isManager           = source[n].isManager,
                    name                  = source[n].name,
                    instanceId            = source[n].instanceId,
                    size                  = source[n].size,
                    nativeTypesArrayIndex = source[n].nativeTypeArrayIndex,
                    hideFlags             = source[n].hideFlags,
                    nativeObjectAddress   = source[n].nativeObjectAddress,

                    nativeObjectsArrayIndex  = n,
                    managedObjectsArrayIndex = -1,
                };
            }

            return(value);
        }
Exemple #3
0
        public void Inspect(PackedMemorySnapshot snapshot, PackedNativeUnityEngineObject nativeObject)
        {
            m_Snapshot = snapshot;
            m_Object   = nativeObject;

            Reload();
        }
Exemple #4
0
            public bool CanAdd(PackedNativeUnityEngineObject no)
            {
                if (!addAssetObjects && no.isPersistent)
                {
                    return(false);
                }
                if (!addSceneObjects && !no.isPersistent && no.instanceId >= 0)
                {
                    return(false);
                }
                if (!addRuntimeObjects && !no.isPersistent && no.instanceId < 0)
                {
                    return(false);
                }

                var dontDestroy = false;

                if (no.isDontDestroyOnLoad || no.isManager || ((no.hideFlags & HideFlags.DontUnloadUnusedAsset) != 0))
                {
                    dontDestroy = true;
                }

                if (!addDestroyOnLoad && !dontDestroy)
                {
                    return(false);
                }
                if (!addDontDestroyOnLoad && dontDestroy)
                {
                    return(false);
                }

                return(true);
            }
Exemple #5
0
        public static void NativeObjectIcon(Rect position, PackedNativeUnityEngineObject obj)
        {
            var warningMsg  = "";
            var showWarning = false;

            if (obj.isDontDestroyOnLoad || obj.isManager || ((obj.hideFlags & HideFlags.DontUnloadUnusedAsset) != 0))
            {
                warningMsg  = "\n\nThe object does not unload automatically during scene changes, because of 'isDontDestroyOnLoad' or 'isManager' or 'hideFlags'.";
                showWarning = true;
            }

            if (obj.isPersistent)
            {
                GUI.Box(position, new GUIContent(HeEditorStyles.assetImage, "Object is an asset." + warningMsg), HeEditorStyles.iconStyle);
            }
            else if (obj.instanceId < 0)
            {
                var c = GUI.color;
                GUI.color = new Color(1, 0.75f, 1, c.a);
                GUI.Box(position, new GUIContent(HeEditorStyles.instanceImage, "Object created at runtime." + warningMsg), HeEditorStyles.iconStyle);
                GUI.color = c;
            }
            else
            {
                GUI.Box(position, new GUIContent(HeEditorStyles.sceneImage, "Object is stored in scene." + warningMsg), HeEditorStyles.iconStyle);
            }

            if (showWarning)
            {
                var r = position;
                r.x += 5;
                r.y += 4;
                GUI.Box(r, new GUIContent(HeEditorStyles.warnImage), HeEditorStyles.iconStyle);
            }
        }
        public static void Read(System.IO.BinaryReader reader, out PackedNativeUnityEngineObject[] value, out string stateString)
        {
            value       = new PackedNativeUnityEngineObject[0];
            stateString = "";

            var version = reader.ReadInt32();

            if (version >= 1)
            {
                var length = reader.ReadInt32();
                stateString = string.Format("Loading {0} Native Objects", length);
                value       = new PackedNativeUnityEngineObject[length];

                for (int n = 0, nend = value.Length; n < nend; ++n)
                {
                    value[n].isPersistent        = reader.ReadBoolean();
                    value[n].isDontDestroyOnLoad = reader.ReadBoolean();
                    value[n].isManager           = reader.ReadBoolean();
                    value[n].name                  = reader.ReadString();
                    value[n].instanceId            = reader.ReadInt32();
                    value[n].size                  = reader.ReadInt32();
                    value[n].nativeTypesArrayIndex = reader.ReadInt32();
                    value[n].hideFlags             = (HideFlags)reader.ReadInt32();
                    value[n].nativeObjectAddress   = reader.ReadInt64();

                    value[n].nativeObjectsArrayIndex  = n;
                    value[n].managedObjectsArrayIndex = -1;
                }
            }
        }
Exemple #7
0
            public void Initialize(NativeObjectsControl owner, PackedNativeUnityEngineObject nativeObject)
            {
                m_Owner  = owner;
                m_Object = new RichNativeObject(owner.m_Snapshot, nativeObject.nativeObjectsArrayIndex);
#if HEAPEXPLORER_DISPLAY_REFS
                m_Object.GetConnectionsCount(out m_ReferencesCount, out m_ReferencedByCount);
#endif
            }
        public void GetConnections(PackedNativeUnityEngineObject nativeObj, List <PackedConnection> references, List <PackedConnection> referencedBy)
        {
            var index = nativeObj.nativeObjectsArrayIndex;

            if (index == -1)
            {
                return;
            }

            GetConnectionsInternal(PackedConnection.Kind.Native, index, references, referencedBy);
        }
        public static         PackedNativeUnityEngineObject[] FromMemoryProfiler(UnityEditor.Profiling.Memory.Experimental.PackedMemorySnapshot snapshot)
        {
            var source = snapshot.nativeObjects;
            var value  = new PackedNativeUnityEngineObject[source.GetNumEntries()];

            var sourceFlags = new ObjectFlags[source.flags.GetNumEntries()];

            source.flags.GetEntries(0, source.flags.GetNumEntries(), ref sourceFlags);

            var sourceObjectNames = new string[source.objectName.GetNumEntries()];

            source.objectName.GetEntries(0, source.objectName.GetNumEntries(), ref sourceObjectNames);

            var sourceInstanceIds = new int[source.instanceId.GetNumEntries()];

            source.instanceId.GetEntries(0, source.instanceId.GetNumEntries(), ref sourceInstanceIds);

            var sourceSizes = new ulong[source.size.GetNumEntries()];

            source.size.GetEntries(0, source.size.GetNumEntries(), ref sourceSizes);

            var sourceNativeTypeArrayIndex = new int[source.nativeTypeArrayIndex.GetNumEntries()];

            source.nativeTypeArrayIndex.GetEntries(0, source.nativeTypeArrayIndex.GetNumEntries(), ref sourceNativeTypeArrayIndex);

            var sourceHideFlags = new HideFlags[source.hideFlags.GetNumEntries()];

            source.hideFlags.GetEntries(0, source.hideFlags.GetNumEntries(), ref sourceHideFlags);

            var sourceNativeObjectAddress = new ulong[source.nativeObjectAddress.GetNumEntries()];

            source.nativeObjectAddress.GetEntries(0, source.nativeObjectAddress.GetNumEntries(), ref sourceNativeObjectAddress);

            for (int n = 0, nend = value.Length; n < nend; ++n)
            {
                value[n] = new PackedNativeUnityEngineObject
                {
                    isPersistent        = (sourceFlags[n] & ObjectFlags.IsPersistent) != 0,
                    isDontDestroyOnLoad = (sourceFlags[n] & ObjectFlags.IsDontDestroyOnLoad) != 0,
                    isManager           = (sourceFlags[n] & ObjectFlags.IsManager) != 0,
                    name                  = sourceObjectNames[n],
                    instanceId            = sourceInstanceIds[n],
                    size                  = (int)sourceSizes[n], // TODO: should be ulong
                    nativeTypesArrayIndex = sourceNativeTypeArrayIndex[n],
                    hideFlags             = sourceHideFlags[n],
                    nativeObjectAddress   = (long)sourceNativeObjectAddress[n], // TODO: should be ulong

                    nativeObjectsArrayIndex  = n,
                    managedObjectsArrayIndex = -1,
                };
            }

            return(value);
        }
Exemple #10
0
        void AddNativeUnityObject(TreeViewItem parent, PackedNativeUnityEngineObject nativeObject)
        {
            var item = new NativeObjectItem
            {
                id    = m_UniqueId++,
                depth = parent.depth + 1,
            };

            item.Initialize(this, m_Snapshot, nativeObject);
            parent.AddChild(item);
        }
Exemple #11
0
        public void Inspect(PackedNativeUnityEngineObject obj)
        {
            Clear();

            m_PreviewTime = Time.realtimeSinceStartup;
            m_Object      = new RichNativeObject(snapshot, obj.nativeObjectsArrayIndex);

            if (autoLoad && m_Object.isValid && m_Object.isPersistent)
            {
                LoadAssetPreviews();
            }
        }
Exemple #12
0
        /// <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);
        }
Exemple #13
0
 /// <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);
         }
     }
 }
Exemple #14
0
            public void Initialize(ConnectionsControl owner, PackedMemorySnapshot snapshot, PackedNativeUnityEngineObject nativeObject)
            {
                m_Owner        = owner;
                m_Snapshot     = snapshot;
                m_NativeObject = new RichNativeObject(snapshot, nativeObject.nativeObjectsArrayIndex);

                m_Value     = m_NativeObject.name;
                address     = m_NativeObject.address;
                displayName = m_NativeObject.type.name;

                // If it's a MonoBehaviour or ScriptableObject, use the C# typename instead
                // It makes it easier to understand what it is, otherwise everything displays 'MonoBehaviour' only.
                if (m_NativeObject.type.IsSubclassOf(m_Snapshot.coreTypes.nativeMonoBehaviour) || m_NativeObject.type.IsSubclassOf(m_Snapshot.coreTypes.nativeScriptableObject))
                {
                    string monoScriptName;
                    if (m_Snapshot.FindNativeMonoScriptType(m_NativeObject.packed.nativeObjectsArrayIndex, out monoScriptName) != -1)
                    {
                        if (!string.IsNullOrEmpty(monoScriptName))
                        {
                            displayName = monoScriptName;
                        }
                    }
                }
            }
Exemple #15
0
        public void Select(PackedNativeUnityEngineObject obj)
        {
            var item = FindItemByAddressRecursive(rootItem, (ulong)obj.nativeObjectAddress);

            SelectItem(item);
        }
Exemple #16
0
 public ObjectProxy(PackedMemorySnapshot snp, PackedNativeUnityEngineObject packed)
 {
     snapshot = snp;
     native   = new RichNativeObject(snp, packed.nativeObjectsArrayIndex);
 }
 public void Inspect(PackedNativeUnityEngineObject item)
 {
     ScheduleJob(new ObjectProxy(snapshot, item));
 }