UNITY 用于打点统计的小工具

这是一个简单的Unity性能监控工具,通过`PerformanceProfiler`类实现打点统计。工具使用LinkedList存储性能点,记录每个点的时间戳,并提供方法设置和获取性能点,以便于分析代码执行时间。当调用`GetPoint`时,会弹出警告窗口显示从上一打点到当前的时间差。
摘要由CSDN通过智能技术生成
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!!!");
        }
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值