添加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
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using Cinemachine;
|
||||
using Convention;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Cinemachine;
|
||||
using Convention;
|
||||
using Unity.Profiling;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -296,11 +295,6 @@ namespace Demo.Game
|
||||
|
||||
private bool IsScrollTimeline = false;
|
||||
|
||||
#if UNITY_EDITOR||Using_ProfilerMarker
|
||||
public ProfilerMarker s_PreparePerfMarkerForSetSongCurrentTime = new(nameof(GameController) + "RuntimeForSetSongCurrentTime");
|
||||
public ProfilerMarker s_PreparePerfMarker = new(nameof(GameController) + "Runtime");
|
||||
#endif
|
||||
|
||||
private void Update()
|
||||
{
|
||||
CurrentTime = MainAudio.CurrentTime + SongOffset;
|
||||
@@ -313,23 +307,23 @@ namespace Demo.Game
|
||||
// TODO : 修正这个逻辑,这个逻辑是反常的
|
||||
if (MainAudio.IsPlaying())
|
||||
{
|
||||
#if UNITY_EDITOR||Using_ProfilerMarker
|
||||
s_PreparePerfMarkerForSetSongCurrentTime.Begin();
|
||||
#endif
|
||||
SetSongCurrentTime(CurrentTime);
|
||||
#if UNITY_EDITOR||Using_ProfilerMarker
|
||||
s_PreparePerfMarkerForSetSongCurrentTime.End();
|
||||
#endif
|
||||
MainObject.ScriptUpdate(CurrentTime, deltaTime, ScriptableObject.TickType.Update);
|
||||
using (Profiler.BeginZone("GameController.SetSongCurrentTime"))
|
||||
{
|
||||
SetSongCurrentTime(CurrentTime);
|
||||
}
|
||||
|
||||
using (Profiler.BeginZone("GameController.ScriptUpdate"))
|
||||
{
|
||||
MainObject.ScriptUpdate(CurrentTime, deltaTime, ScriptableObject.TickType.Update);
|
||||
}
|
||||
}
|
||||
if (IsMain == false)
|
||||
return;
|
||||
|
||||
#if UNITY_EDITOR || Using_ProfilerMarker
|
||||
s_PreparePerfMarker.Begin(this);
|
||||
#endif
|
||||
using (Profiler.BeginZone("GameController.InputHandling"))
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (Keyboard.current[Key.LeftShift].isPressed)
|
||||
if (Keyboard.current[Key.LeftShift].isPressed)
|
||||
#else
|
||||
if (Keyboard.current[Key.LeftCtrl].isPressed)
|
||||
#endif
|
||||
@@ -374,9 +368,7 @@ namespace Demo.Game
|
||||
}
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR||Using_ProfilerMarker
|
||||
s_PreparePerfMarker.End();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator GameExit()
|
||||
|
||||
@@ -8,7 +8,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Unity.Profiling;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Demo
|
||||
@@ -276,9 +275,6 @@ namespace Demo
|
||||
|
||||
public void EnableScript(ScriptableObject parent)
|
||||
{
|
||||
#if UNITY_EDITOR||Using_ProfilerMarker
|
||||
s_PreparePerfMarker = new(ScriptName);
|
||||
#endif
|
||||
if (isEnableScript)
|
||||
{
|
||||
Debug.LogError($"ScriptableObject is currently enableScript, start coroutine {nameof(UnloadScript)} to disable", this);
|
||||
@@ -328,11 +324,6 @@ namespace Demo
|
||||
public static Dictionary<string, Type> FastScriptableObjectTypen = new();
|
||||
public static int AllScriptableObjectCounter = 0;
|
||||
|
||||
|
||||
#if UNITY_EDITOR||Using_ProfilerMarker
|
||||
public ProfilerMarker s_PreparePerfMarker;
|
||||
#endif
|
||||
|
||||
#region LoadSubScript
|
||||
|
||||
/// <summary>
|
||||
@@ -471,28 +462,26 @@ namespace Demo
|
||||
return;
|
||||
if (gameObject.activeInHierarchy == false)
|
||||
return;
|
||||
#if UNITY_EDITOR||Using_ProfilerMarker
|
||||
s_PreparePerfMarker.Begin(this);
|
||||
#endif
|
||||
if (tickType == TickType.Reset)
|
||||
|
||||
using (Profiler.BeginZone($"{GetType().Name}.Update"))
|
||||
{
|
||||
ResetEnterGameStatus();
|
||||
if (tickType == TickType.Reset)
|
||||
{
|
||||
ResetEnterGameStatus();
|
||||
}
|
||||
// UpdateTicks
|
||||
if (UpdatePerFrame > 0)
|
||||
{
|
||||
if (ScriptUpdateCounter % UpdatePerFrame == 0)
|
||||
UpdateTicks(currentTime, deltaTime, tickType);
|
||||
ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0;
|
||||
}
|
||||
// Childs UpdateTicks
|
||||
foreach (var child in Childs)
|
||||
{
|
||||
child.ScriptUpdate(currentTime, deltaTime, tickType);
|
||||
}
|
||||
}
|
||||
// UpdateTicks
|
||||
if (UpdatePerFrame > 0)
|
||||
{
|
||||
if (ScriptUpdateCounter % UpdatePerFrame == 0)
|
||||
UpdateTicks(currentTime, deltaTime, tickType);
|
||||
ScriptUpdateCounter += tickType == TickType.Update ? 1 : 0;
|
||||
}
|
||||
// Childs UpdateTicks
|
||||
foreach (var child in Childs)
|
||||
{
|
||||
child.ScriptUpdate(currentTime, deltaTime, tickType);
|
||||
}
|
||||
#if UNITY_EDITOR||Using_ProfilerMarker
|
||||
s_PreparePerfMarker.End();
|
||||
#endif
|
||||
}
|
||||
|
||||
protected virtual void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using Convention;
|
||||
using Demo.Editor.UI;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Convention;
|
||||
using Demo.Editor.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Demo.Game
|
||||
@@ -71,38 +69,41 @@ namespace Demo.Game
|
||||
|
||||
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
|
||||
{
|
||||
base.UpdateTicks(currentTime, deltaTime, tickType);
|
||||
|
||||
float GetPercentValue()
|
||||
using (Profiler.BeginZone($"Updatement<{typeof(DataType).Name}>.UpdateTicks"))
|
||||
{
|
||||
return (currentTime - Entries[Content].TimePoint) / (Entries[Content + 1].TimePoint - Entries[Content].TimePoint);
|
||||
}
|
||||
base.UpdateTicks(currentTime, deltaTime, tickType);
|
||||
|
||||
if (Entries.Count <= 1)
|
||||
return;
|
||||
switch (tickType)
|
||||
{
|
||||
case TickType.Reset:
|
||||
case TickType.Start:
|
||||
{
|
||||
Content = 0;
|
||||
while (Content + 1 < Entries.Count && Entries[Content + 1].TimePoint < currentTime)
|
||||
float GetPercentValue()
|
||||
{
|
||||
return (currentTime - Entries[Content].TimePoint) / (Entries[Content + 1].TimePoint - Entries[Content].TimePoint);
|
||||
}
|
||||
|
||||
if (Entries.Count <= 1)
|
||||
return;
|
||||
switch (tickType)
|
||||
{
|
||||
case TickType.Reset:
|
||||
case TickType.Start:
|
||||
{
|
||||
Content = 0;
|
||||
while (Content + 1 < Entries.Count && Entries[Content + 1].TimePoint < currentTime)
|
||||
Content++;
|
||||
UpdateEntry(Content, GetPercentValue());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (Entries[0].TimePoint > currentTime)
|
||||
return;
|
||||
if (Content + 1 >= Entries.Count)
|
||||
return;
|
||||
if (Entries[Content + 1].TimePoint < currentTime)
|
||||
Content++;
|
||||
UpdateEntry(Content, GetPercentValue());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (Entries[0].TimePoint > currentTime)
|
||||
return;
|
||||
if (Content + 1 >= Entries.Count)
|
||||
return;
|
||||
if (Entries[Content + 1].TimePoint < currentTime)
|
||||
Content++;
|
||||
if (Content + 1 >= Entries.Count)
|
||||
UpdateEntry(Content, 1);
|
||||
else
|
||||
UpdateEntry(Content, GetPercentValue());
|
||||
break;
|
||||
if (Content + 1 >= Entries.Count)
|
||||
UpdateEntry(Content, 1);
|
||||
else
|
||||
UpdateEntry(Content, GetPercentValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user