Files
ft/Client/Assets/Scripts/EventCubeMelt/Utils/ProfileScope.cs
2026-06-29 21:18:33 +08:00

40 lines
1.1 KiB
C#

using System.Collections.Generic;
using System.Diagnostics;
using EventCubeMelt;
using UnityEngine;
using Debug = UnityEngine.Debug;
namespace EventCubeMelt.Utils
{
public class ProfileScope
{
private Stopwatch sw;
private string scopeName;
private Dictionary<string,long> s_accum = new Dictionary<string,long>();
public void L_ProfileScope(string sectionName)
{
scopeName = sectionName;
sw = Stopwatch.StartNew();
}
public void L_ProfileScopeEnd()
{
sw.Stop();
long el = sw.ElapsedMilliseconds;
s_accum.TryGetValue(scopeName, out long old);
s_accum[scopeName] = old + el;
ELog($"{scopeName} 本次 {el} ms 累计 {s_accum[scopeName]} ms");
}
#region Log
private static void ELog(string message)
{
#if UNITY_EDITOR
if (!EventCubeMeltLogPolicy.EnableELog) return;
Debug.Log($"<color=orange>ProfileScope => {message} </color>");
#endif
}
#endregion
}
}