107 lines
5.3 KiB
C#
107 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace AlicizaX.Debugger.Runtime
|
|
{
|
|
public sealed partial class DebuggerComponent
|
|
{
|
|
private sealed class ReferencePoolInformationWindow : PollingDebuggerWindowBase
|
|
{
|
|
private readonly Dictionary<string, List<MemoryPoolInfo>> m_ReferencePoolInfos = new Dictionary<string, List<MemoryPoolInfo>>(StringComparer.Ordinal);
|
|
private readonly Comparison<MemoryPoolInfo> m_NormalClassNameComparer = NormalClassNameComparer;
|
|
private readonly Comparison<MemoryPoolInfo> m_FullClassNameComparer = FullClassNameComparer;
|
|
private bool m_ShowFullClassName;
|
|
private Toggle showFullClassNameToggle;
|
|
|
|
protected override void BuildWindow(VisualElement root)
|
|
{
|
|
VisualElement overview = CreateSection("Reference Pool Overview", out VisualElement overviewCard);
|
|
overviewCard.Add(CreateRow("Enable Strict Check", MemoryPool.EnableStrictCheck.ToString()));
|
|
overviewCard.Add(CreateRow("Reference Pool Count", MemoryPool.Count.ToString()));
|
|
showFullClassNameToggle = ScrollableDebuggerWindowBase.CreateConsoleFilterToggle("Show Full ClassName", m_ShowFullClassName, DebuggerTheme.PrimaryText, value => m_ShowFullClassName = value);
|
|
overviewCard.Add(showFullClassNameToggle);
|
|
root.Add(overview);
|
|
|
|
m_ReferencePoolInfos.Clear();
|
|
MemoryPoolInfo[] referencePoolInfos = MemoryPool.GetAllMemoryPoolInfos();
|
|
foreach (MemoryPoolInfo referencePoolInfo in referencePoolInfos)
|
|
{
|
|
string assemblyName = referencePoolInfo.Type.Assembly.GetName().Name;
|
|
if (!m_ReferencePoolInfos.TryGetValue(assemblyName, out List<MemoryPoolInfo> results))
|
|
{
|
|
results = new List<MemoryPoolInfo>();
|
|
m_ReferencePoolInfos.Add(assemblyName, results);
|
|
}
|
|
|
|
results.Add(referencePoolInfo);
|
|
}
|
|
|
|
foreach (KeyValuePair<string, List<MemoryPoolInfo>> assemblyReferencePoolInfo in m_ReferencePoolInfos)
|
|
{
|
|
assemblyReferencePoolInfo.Value.Sort(m_ShowFullClassName ? m_FullClassNameComparer : m_NormalClassNameComparer);
|
|
VisualElement section = CreateSection(Utility.Text.Format("Assembly: {0}", assemblyReferencePoolInfo.Key), out VisualElement card);
|
|
if (assemblyReferencePoolInfo.Value.Count <= 0)
|
|
{
|
|
card.Add(CreateRow("State", "Reference Pool is Empty ..."));
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < assemblyReferencePoolInfo.Value.Count; i++)
|
|
{
|
|
MemoryPoolInfo info = assemblyReferencePoolInfo.Value[i];
|
|
string title = m_ShowFullClassName ? info.Type.FullName : info.Type.Name;
|
|
string content = Utility.Text.Format(
|
|
"Unused {0} | Using {1} | Acquire {2} | Release {3} | Add {4} | Remove {5}",
|
|
info.UnusedMemoryCount,
|
|
info.UsingMemoryCount,
|
|
info.AcquireMemoryCount,
|
|
info.ReleaseMemoryCount,
|
|
info.AddMemoryCount,
|
|
info.RemoveMemoryCount);
|
|
card.Add(CreatePoolInfoItem(title, content));
|
|
}
|
|
}
|
|
|
|
root.Add(section);
|
|
}
|
|
}
|
|
|
|
private static int NormalClassNameComparer(MemoryPoolInfo a, MemoryPoolInfo b)
|
|
{
|
|
return a.Type.Name.CompareTo(b.Type.Name);
|
|
}
|
|
|
|
private static int FullClassNameComparer(MemoryPoolInfo a, MemoryPoolInfo b)
|
|
{
|
|
return a.Type.FullName.CompareTo(b.Type.FullName);
|
|
}
|
|
|
|
private static VisualElement CreatePoolInfoItem(string title, string content)
|
|
{
|
|
float scale = DebuggerComponent.Instance != null ? DebuggerComponent.Instance.GetUiScale() : 1f;
|
|
VisualElement item = CreateCard();
|
|
item.style.marginBottom = 8f * scale;
|
|
item.style.backgroundColor = DebuggerTheme.PanelSurfaceAlt;
|
|
|
|
Label titleLabel = new Label(title ?? string.Empty);
|
|
titleLabel.style.color = DebuggerTheme.PrimaryText;
|
|
titleLabel.style.fontSize = 16f * scale;
|
|
titleLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
|
|
titleLabel.style.whiteSpace = WhiteSpace.Normal;
|
|
titleLabel.style.marginBottom = 6f * scale;
|
|
|
|
Label contentLabel = new Label(content ?? string.Empty);
|
|
contentLabel.style.color = DebuggerTheme.SecondaryText;
|
|
contentLabel.style.fontSize = 14f * scale;
|
|
contentLabel.style.whiteSpace = WhiteSpace.Normal;
|
|
|
|
item.Add(titleLabel);
|
|
item.Add(contentLabel);
|
|
return item;
|
|
}
|
|
}
|
|
}
|
|
}
|