private void QueueArrayElements(
            [NotNull] CrawlItem parent,
            [NotNull] Queue <CrawlItem> queue,
            [CanBeNull] object array,
            [NotNull] CrawlSettings crawlSettings)
        {
            if (array == null)
            {
                return;
            }

            if (!array.GetType().IsArray)
            {
                return;
            }

            var elementType = array.GetType().GetElementType();

            if (elementType == null)
            {
                return;
            }

            int index = 0;

            foreach (var arrayItem in (Array)array)
            {
                QueueValue(parent, queue, arrayItem, $"[{index}]", crawlSettings);
                index++;
            }
        }
        private void QueueHierarchy(
            [NotNull] CrawlItem parent,
            [NotNull] Queue <CrawlItem> queue,
            [CanBeNull] object v,
            [NotNull] CrawlSettings crawlSettings)
        {
            var go = v as GameObject;

            if (go == null)
            {
                return;
            }

            var components = go.GetComponents <Component>();

            foreach (var c in components)
            {
                if (ReferenceEquals(c, null))
                {
                    continue;
                }

                QueueValue(parent, queue, c, c.GetType().GetDisplayName(), crawlSettings);
            }

            var t = go.transform;

            for (int i = 0; i < t.childCount; ++i)
            {
                var childGo = t.GetChild(i).gameObject;
                QueueValue(parent, queue, childGo, childGo.name, crawlSettings);
            }
        }
        private void CrawlRoot([NotNull] CrawlItem root, [NotNull] CrawlSettings crawlSettings)
        {
            var queue = new Queue <CrawlItem>();

            queue.Enqueue(root);

            while (queue.Count > 0)
            {
                var next     = queue.Dequeue();
                var type     = next.Object.GetType();
                var typeData = TypeData.Get(type);

                if (type.IsArray)
                {
                    QueueArrayElements(next, queue, next.Object, crawlSettings);
                }
                if (type == typeof(GameObject))
                {
                    QueueHierarchy(next, queue, next.Object, crawlSettings);
                }
                if (typeData.DynamicSizedFields != null)
                {
                    foreach (var field in typeData.DynamicSizedFields)
                    {
                        var v = field.GetValue(next.Object);
                        QueueValue(next, queue, v, field.Name, crawlSettings);
                    }
                }
            }

            root.UpdateSize(SizeMode);
        }
        private void QueueHierarchy(
            [NotNull] CrawlItem parent,
            [NotNull] Queue <CrawlItem> queue,
            [CanBeNull] object v)
        {
            var go = v as GameObject;

            if (go == null)
            {
                return;
            }

            var components = go.GetComponents <Component>();

            foreach (var c in components)
            {
                QueueValue(parent, queue, c, "", true);
            }

            var t = go.transform;

            for (int i = 0; i < t.childCount; ++i)
            {
                var childGo = t.GetChild(i).gameObject;
                QueueValue(parent, queue, childGo, childGo.name, true);
            }
        }
        private void QueueArrayElements(
            [NotNull] CrawlItem parent,
            [NotNull] Queue <CrawlItem> queue,
            [CanBeNull] object array)
        {
            if (array == null)
            {
                return;
            }

            if (!array.GetType().IsArray)
            {
                return;
            }

            var elementType = array.GetType().GetElementType();

            if (elementType == null)
            {
                return;
            }

            foreach (var arrayItem in (Array)array)
            {
                QueueValue(parent, queue, arrayItem, "");
            }
        }
Exemplo n.º 6
0
        public static void RegisterItem([NotNull] CrawlItem item)
        {
            if (!SnapshotHistory.IsNew(item.Object))
            {
                return;
            }

            var stats = DemandTypeStats(item.Object.GetType());

            stats.Count++;
            stats.SelfSize  += item.SelfSize;
            stats.TotalSize += item.TotalSize;

            var unityObject = item.Object as UnityEngine.Object;

            if (unityObject != null)
            {
                stats.NativeSize += Profiler.GetRuntimeMemorySizeLong(unityObject);
            }

            if (stats.tracked)
            {
                stats.DemandInstanceStats(item.Object).Size = item.TotalSize;
            }
        }
Exemplo n.º 7
0
        public static void RegisterInstance([NotNull] CrawlItem parent, [NotNull] string name, [NotNull] object instance)
        {
            var stats = DemandTypeStats(instance.GetType());

            if (!stats.tracked)
            {
                return;
            }

            var instanceStats = stats.DemandInstanceStats(instance);
            var rootPath      = parent.GetRootPath() + "." + name;

            instanceStats.RootPaths.Add(rootPath);
        }
        private void QueueValue(
            [NotNull] CrawlItem parent,
            [NotNull] Queue <CrawlItem> queue,
            [CanBeNull] object v,
            [NotNull] string name,
            [NotNull] CrawlSettings crawlSettings)
        {
            if (v == null)
            {
                return;
            }

            if (IsForbidden(v))
            {
                return;
            }

            TypeStats.RegisterInstance(parent, name, v);
            if (visitedObjects.Contains(v))
            {
                return;
            }

            if (unityObjects.Contains(v) && !crawlSettings.IsUnityTypeAllowed(v.GetType()))
            {
                return;
            }

            if (IsRoot(v))
            {
                var rootName = parent.Object.GetType().GetDisplayName() + '.' + name;
                EnqueueRoot(v, rootName, true);
                return;
            }

            visitedObjects.Add(v);
            var item = new CrawlItem(parent, v, name);

            queue.Enqueue(item);
            parent.AddChild(item);
        }
        private void EnqueueRoot([NotNull] object root, [NotNull] string name, bool local)
        {
            if (IsForbidden(root))
            {
                return;
            }

            if (visitedObjects.Contains(root))
            {
                return;
            }

            visitedObjects.Add(root);
            var rootItem = new CrawlItem(null, root, name);

            if (local)
            {
                localRootsQueue.Enqueue(rootItem);
            }
            else
            {
                rootsQueue.Enqueue(rootItem);
            }
        }