添加Tracy0.11的性能分析支持
This commit is contained in:
@@ -1,25 +1,19 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Convention;
|
||||
using Convention.WindowsUI;
|
||||
using Convention.WindowsUI.Variant;
|
||||
using Demo.Game;
|
||||
using Unity.Profiling;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Demo.Editor
|
||||
{
|
||||
public class EditorController : MonoSingleton<EditorController>
|
||||
{
|
||||
#if UNITY_EDITOR||Using_ProfilerMarker
|
||||
public ProfilerMarker s_PreparePerfMarker = new(nameof(EditorController) + "Runtime");
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// 必须是-1至0
|
||||
/// </summary>
|
||||
@@ -376,6 +370,8 @@ namespace Demo.Editor
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Profiler.AppInfo(Application.productName);
|
||||
|
||||
GlobalConfig.ConstConfigFile = "config.easysave";
|
||||
// Generate Framework
|
||||
{
|
||||
@@ -490,15 +486,47 @@ namespace Demo.Editor
|
||||
StartCoroutine(Foo());
|
||||
}
|
||||
|
||||
#region Performance Monitoring
|
||||
|
||||
private void MonitorFrameRate()
|
||||
{
|
||||
float fps = 1.0f / Time.unscaledDeltaTime;
|
||||
float frameTime = Time.unscaledDeltaTime * 1000.0f;
|
||||
|
||||
Profiler.Plot("FPS", fps);
|
||||
Profiler.Plot("Frame Time (ms)", frameTime);
|
||||
Profiler.Plot("Time Scale", Time.timeScale);
|
||||
}
|
||||
private void MonitorMemory()
|
||||
{
|
||||
// GC 内存
|
||||
long totalMemory = System.GC.GetTotalMemory(false);
|
||||
Profiler.Plot("GC Memory (MB)", totalMemory / (1024.0 * 1024.0));
|
||||
|
||||
// Unity Profiler 内存统计
|
||||
long usedHeap = UnityEngine.Profiling.Profiler.usedHeapSizeLong;
|
||||
long totalAllocated = UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong();
|
||||
long totalReserved = UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong();
|
||||
|
||||
Profiler.Plot("Used Heap (MB)", usedHeap / (1024.0 * 1024.0));
|
||||
Profiler.Plot("Total Allocated (MB)", totalAllocated / (1024.0 * 1024.0));
|
||||
Profiler.Plot("Total Reserved (MB)", totalReserved / (1024.0 * 1024.0));
|
||||
|
||||
// 纹理内存
|
||||
Profiler.Plot("Texture Memory (MB)", UnityEngine.Profiling.Profiler.GetAllocatedMemoryForGraphicsDriver() / (1024.0 * 1024.0));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Update()
|
||||
{
|
||||
CurrentFPS.text = $"{1 / Time.smoothDeltaTime}";
|
||||
MonitorMemory();
|
||||
MonitorFrameRate();
|
||||
|
||||
#if UNITY_EDITOR||Using_ProfilerMarker
|
||||
s_PreparePerfMarker.Begin(this);
|
||||
try
|
||||
using (Profiler.BeginZone("EditorController.Update"))
|
||||
{
|
||||
#endif
|
||||
CurrentFPS.text = $"{1 / Time.smoothDeltaTime}";
|
||||
|
||||
if (string.IsNullOrEmpty(LastLoadProjectName))
|
||||
return;
|
||||
|
||||
@@ -557,13 +585,12 @@ namespace Demo.Editor
|
||||
CloseCurrentProject();
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR||Using_ProfilerMarker
|
||||
}
|
||||
finally
|
||||
{
|
||||
s_PreparePerfMarker.End();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
Profiler.EmitFrameMark();
|
||||
}
|
||||
|
||||
// ToolTable
|
||||
|
||||
Reference in New Issue
Block a user