< Summary

Class:GDX.Developer.Reports.Resource.Objects.ObjectInfo
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Developer/Reports/Resource/Objects/ObjectInfo.cs
Covered lines:42
Uncovered lines:8
Coverable lines:50
Total lines:169
Line coverage:84% (42 of 50)
Covered branches:0
Total branches:0
Covered methods:4
Total methods:5
Method coverage:80% (4 of 5)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Clone()0%2100%
GetDetailedInformation(...)0%110100%
Populate(...)0%220100%
CompareTo(...)0%3.13077.78%
Output(...)0%7.077088.89%

File(s)

D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Developer/Reports/Resource/Objects/ObjectInfo.cs

#LineLine coverage
 1// Copyright (c) 2020-2022 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5#if !UNITY_DOTSRUNTIME
 6
 7using System;
 8using System.Text;
 9using UnityEngine.Profiling;
 10using Object = UnityEngine.Object;
 11
 12namespace GDX.Developer.Reports.Resource.Objects
 13{
 14    /// <summary>
 15    ///     An information storage object for a target <see cref="object" />.
 16    /// </summary>
 17    /// <exception cref="UnsupportedRuntimeException">Not supported on DOTS Runtime.</exception>
 18    public class ObjectInfo : IComparable
 19    {
 20        /// <summary>
 21        ///     The fully qualified reflection definition of the <see cref="ObjectInfo" />.
 22        /// </summary>
 23        public const string TypeDefinition = "GDX.Developer.Reports.Resource.Objects.ObjectInfo,GDX";
 24
 25        /// <summary>
 26        ///     The number of copies of the <see cref="Reference" /> object known by Unity.
 27        /// </summary>
 28        public uint CopyCount;
 29
 30        /// <summary>
 31        ///     The memory usage of the actual <see cref="Reference" /> object (in bytes).
 32        /// </summary>
 33        public long MemoryUsage;
 34
 35        /// <summary>
 36        ///     The name of the <see cref="Reference" /> object.
 37        /// </summary>
 38        public string Name;
 39
 40        /// <summary>
 41        ///     A <see cref="TransientReference" /> to the target object.
 42        /// </summary>
 43        public TransientReference Reference;
 44
 45        /// <summary>
 46        ///     The total memory usage of the <see cref="Reference" /> object (in bytes).
 47        /// </summary>
 48        public long TotalMemoryUsage;
 49
 50        /// <summary>
 51        ///     The cached <see cref="Type" /> of the <see cref="Reference" /> object.
 52        /// </summary>
 53        public Type Type;
 54
 55        /// <summary>
 56        /// Create a clone of this object.
 57        /// </summary>
 58        /// <returns></returns>
 59        public virtual ObjectInfo Clone()
 060        {
 061            return new ObjectInfo()
 62            {
 63                CopyCount = CopyCount,
 64                MemoryUsage = MemoryUsage,
 65                Name = Name,
 66                Reference = Reference,
 67                TotalMemoryUsage = TotalMemoryUsage,
 68                Type = Type
 69            };
 070        }
 71
 72        /// <summary>
 73        ///     Get additional information about the specific <see cref="Reference" />.
 74        /// </summary>
 75        /// <returns>A <see cref="string" /> of additional information.</returns>
 76        public virtual string GetDetailedInformation(int maximumWidth)
 1493477        {
 1493478            return null;
 1493479        }
 80
 81        /// <summary>
 82        ///     Populate an <see cref="ObjectInfo" /> from the <paramref name="targetObject" />. Optionally providing an
 83        ///     <paramref name="reference" /> created prior.
 84        /// </summary>
 85        /// <param name="targetObject">The <see cref="object" /> which to cache information about.</param>
 86        /// <param name="reference">An existing <see cref="TransientReference" /> targeting the <paramref name="targetOb
 87        public virtual void Populate(Object targetObject, TransientReference reference = null)
 1817388        {
 89            // Basic info
 1817390            Name = targetObject.name;
 1817391            Type = targetObject.GetType();
 92
 93            // Assign initial memory usage stats
 1817394            MemoryUsage = Profiler.GetRuntimeMemorySizeLong(targetObject);
 1817395            TotalMemoryUsage = MemoryUsage;
 96
 97            // Assign or create the transient reference to the target object
 1817398            Reference = reference != null ? reference : new TransientReference(targetObject);
 99
 100            // It's new, so there's only one.
 18173101            CopyCount = 1;
 18173102        }
 103
 104        /// <summary>
 105        /// Evaluate if the compared <see cref="ObjectInfo"/> utilizes more memory then this one.
 106        /// </summary>
 107        /// <param name="obj">The <see cref="ObjectInfo"/> to compare against.</param>
 108        /// <returns>1 if larger, otherwise 0.</returns>
 109        public int CompareTo(object obj)
 227266110        {
 227266111            if (!(obj is ObjectInfo info))
 0112            {
 0113                return 0;
 114            }
 115
 227266116            if (TotalMemoryUsage > info.TotalMemoryUsage)
 128662117            {
 128662118                return -1;
 119            }
 98604120            return 1;
 227266121        }
 122
 123
 124        public void Output(ResourceReportContext context, StringBuilder builder, bool stripUnicode = true)
 18298125        {
 18298126            string typeName = Type.Name.PadRight(context.ObjectTypeWidth);
 18298127            if (typeName.Length > context.ObjectTypeWidth)
 1580128            {
 1580129                typeName = typeName.Substring(0, context.ObjectTypeWidth);
 1580130            }
 18298131            if (stripUnicode)
 18298132            {
 18298133                typeName = typeName.StripNonAscii();
 18298134            }
 135
 18298136            string objectName = Name.PadRight(context.ObjectNameWidth);
 18298137            if (objectName.Length > context.ObjectNameWidth)
 952138            {
 952139                objectName = objectName.Substring(0, context.ObjectNameWidth);
 952140            }
 18298141            if (stripUnicode)
 18298142            {
 18298143                objectName = objectName.StripNonAscii();
 18298144            }
 145
 18298146            string sizeInfo =
 147                $"{Localization.GetHumanReadableFileSize(MemoryUsage)} x {CopyCount.ToString()}".PadRight(
 148                    context.ObjectSizeWidth);
 18298149            if (sizeInfo.Length > context.ObjectSizeWidth)
 0150            {
 0151                sizeInfo = sizeInfo.Substring(0, context.ObjectSizeWidth);
 0152            }
 153
 154
 155            // Additional information
 18298156            string additionalInfo = GetDetailedInformation(context.ObjectInfoWidth);
 157
 158            // Add to builder
 18298159            builder.AppendLine(additionalInfo != null
 160                ? $"{typeName} {objectName} {sizeInfo} {additionalInfo}"
 161                : $"{typeName} {objectName} {sizeInfo}");
 18298162        }
 163
 164
 165
 166
 167    }
 168}
 169#endif