Esempio n. 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);
        }
Esempio n. 2
0
        public void Select(PackedGCHandle obj)
        {
            var item = FindItemByAddressRecursive(rootItem, (ulong)(obj.target));

            if (item != null)
            {
                SetSelection(new[] { item.id }, TreeViewSelectionOptions.RevealAndFrame | TreeViewSelectionOptions.FireSelectionChanged);
            }
        }
Esempio n. 3
0
        void AddGCHandle(TreeViewItem parent, PackedGCHandle gcHandle)
        {
            var item = new GCHandleItem
            {
                id    = m_UniqueId++,
                depth = parent.depth + 1
            };

            item.Initialize(this, m_Snapshot, gcHandle.gcHandlesArrayIndex);
            parent.AddChild(item);
        }
        public void GetConnections(PackedGCHandle gcHandle, List <PackedConnection> references, List <PackedConnection> referencedBy)
        {
            var index = gcHandle.gcHandlesArrayIndex;

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

            GetConnectionsInternal(PackedConnection.Kind.GCHandle, index, references, referencedBy);
        }
Esempio n. 5
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);
        }
        public static                       PackedGCHandle[] FromMemoryProfiler(UnityEditor.MemoryProfiler.PackedGCHandle[] source)
        {
            var value = new PackedGCHandle[source.Length];

            for (int n = 0, nend = source.Length; n < nend; ++n)
            {
                value[n] = new PackedGCHandle
                {
                    target = source[n].target,
                    gcHandlesArrayIndex      = n,
                    managedObjectsArrayIndex = -1,
                };
            }
            return(value);
        }
Esempio n. 7
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);
         }
     }
 }
        public static                       PackedGCHandle[] FromMemoryProfiler(UnityEditor.Profiling.Memory.Experimental.PackedMemorySnapshot snapshot)
        {
            var source = snapshot.gcHandles;
            var value  = new PackedGCHandle[source.GetNumEntries()];

            var sourceTargets = new ulong[source.target.GetNumEntries()];

            source.target.GetEntries(0, source.target.GetNumEntries(), ref sourceTargets);

            for (int n = 0, nend = value.Length; n < nend; ++n)
            {
                value[n] = new PackedGCHandle
                {
                    target = sourceTargets[n],
                    gcHandlesArrayIndex      = n,
                    managedObjectsArrayIndex = -1,
                };
            }
            return(value);
        }
        public static void Read(System.IO.BinaryReader reader, out PackedGCHandle[] value, out string stateString)
        {
            value       = new PackedGCHandle[0];
            stateString = "";

            var version = reader.ReadInt32();

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

                for (int n = 0, nend = value.Length; n < nend; ++n)
                {
                    value[n].target = reader.ReadUInt64();
                    value[n].gcHandlesArrayIndex      = n;
                    value[n].managedObjectsArrayIndex = -1;
                }
            }
        }
Esempio n. 10
0
 public ObjectProxy(PackedMemorySnapshot snp, PackedGCHandle packed)
 {
     snapshot = snp;
     gcHandle = new RichGCHandle(snp, packed.gcHandlesArrayIndex);
 }
 public void Inspect(PackedGCHandle item)
 {
     ScheduleJob(new ObjectProxy(snapshot, item));
 }
Esempio n. 12
0
 public void Inspect(PackedGCHandle item)
 {
     m_Selected = null;
     ScheduleJob(new ObjectProxy(snapshot, item));
 }