using System.Collections.Generic;
using System;
public static class PerformanceProfiler
{
private struct PerformancePoint
{
public PerformancePoint(string msg)
{
this.msg = msg;
this.time = DateTime.Now;
}
private string msg;
private DateTime time;
public override string ToString()
{
return string.Format("PerformanceProfiler ****** {0} => {1} ms", string.IsNullOrEmpty(this.msg) ? "Time" : msg, (DateTime.Now - this.time).Ticks/10000.0f);
}
}
private static LinkedList<PerformancePoint> PerformancePoints = new LinkedList<PerformancePoint>();
public static void SetPoint(string msg = null)
{
PerformancePoints.AddLast(new PerformancePoint(msg));
}
public static void GetPoint()
{
if (PerformancePoints.Count > 0)
{
PerformancePoint point = PerformancePoints.Last.Value;
PerformancePoints.RemoveLast();
UnityEngine.Debug.LogWarning(point.ToString());
}
else
{
UnityEngine.Debug.LogWarning("PerformancePoints Empty!!!");
}
}
}
UNITY 用于打点统计的小工具
最新推荐文章于 2023-03-08 10:21:12 发布
这是一个简单的Unity性能监控工具,通过`PerformanceProfiler`类实现打点统计。工具使用LinkedList存储性能点,记录每个点的时间戳,并提供方法设置和获取性能点,以便于分析代码执行时间。当调用`GetPoint`时,会弹出警告窗口显示从上一打点到当前的时间差。
摘要由CSDN通过智能技术生成