99 lines
2.8 KiB
C#
99 lines
2.8 KiB
C#
using TMPro;
|
||
using UnityEngine;
|
||
using VMdemo.Simulation;
|
||
|
||
namespace VMdemo.UI
|
||
{
|
||
public class SimulationTraceView : MonoBehaviour
|
||
{
|
||
[SerializeField] private TMP_Text splitTraceText;
|
||
[SerializeField] private TMP_Text pageTableTraceText;
|
||
[SerializeField] private TMP_Text decisionReasonText;
|
||
[SerializeField] private TMP_Text pathSummaryText;
|
||
|
||
private void Awake()
|
||
{
|
||
EnsureRichTextEnabled(splitTraceText);
|
||
}
|
||
|
||
public void ShowNotInitialized()
|
||
{
|
||
SetText(splitTraceText, "地址拆分可视化:N/A");
|
||
SetText(pageTableTraceText, "多级页表查询可视化:N/A");
|
||
SetText(decisionReasonText, "分支原因:N/A");
|
||
SetText(pathSummaryText, "路径摘要:N/A");
|
||
}
|
||
|
||
public void Render(TranslatorEngine engine)
|
||
{
|
||
if (engine == null)
|
||
{
|
||
ShowNotInitialized();
|
||
return;
|
||
}
|
||
|
||
SetText(
|
||
splitTraceText,
|
||
SimulationUIFormatter.FormatAddressSplitTrace(
|
||
engine.State,
|
||
engine.VaBits,
|
||
engine.OffsetBits,
|
||
engine.L1Bits,
|
||
engine.L2Bits));
|
||
|
||
SetText(
|
||
pageTableTraceText,
|
||
SimulationUIFormatter.FormatPageTableWalkTrace(engine.State, engine.PageTable));
|
||
|
||
SetText(
|
||
decisionReasonText,
|
||
string.IsNullOrEmpty(engine.State.LastDecisionReason)
|
||
? "分支原因:暂无"
|
||
: $"分支原因:{engine.State.LastDecisionReason}");
|
||
|
||
SetText(pathSummaryText, BuildPathSummary(engine.State));
|
||
}
|
||
|
||
private static string BuildPathSummary(SimulationState state)
|
||
{
|
||
if (state == null)
|
||
{
|
||
return "路径摘要:N/A";
|
||
}
|
||
|
||
if (state.IsTlbHit)
|
||
{
|
||
return "路径摘要:TLB命中 -> 直接合成PA";
|
||
}
|
||
|
||
if (state.IsPageTableHit)
|
||
{
|
||
return "路径摘要:TLB未命中 -> 页表命中 -> 合成PA";
|
||
}
|
||
|
||
if (state.IsPageFault)
|
||
{
|
||
return "路径摘要:TLB未命中 -> 页表未命中 -> 缺页处理 -> 合成PA";
|
||
}
|
||
|
||
return "路径摘要:进行中";
|
||
}
|
||
|
||
private static void SetText(TMP_Text target, string value)
|
||
{
|
||
if (target != null)
|
||
{
|
||
target.text = value;
|
||
}
|
||
}
|
||
|
||
private static void EnsureRichTextEnabled(TMP_Text target)
|
||
{
|
||
if (target != null)
|
||
{
|
||
target.richText = true;
|
||
}
|
||
}
|
||
}
|
||
}
|