2024-08-17 14:27:18 +08:00
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2024-10-17 01:59:25 +08:00
|
|
|
namespace JNGame.Runtime.Util
|
2024-08-17 14:27:18 +08:00
|
|
|
{
|
|
|
|
public class Profiler
|
|
|
|
{
|
2024-10-17 01:59:25 +08:00
|
|
|
|
|
|
|
// [System.Diagnostics.Conditional("ENABLE_TEST_SROPTIONS")]
|
2024-08-17 14:27:18 +08:00
|
|
|
public static void BeginSample(string tag)
|
|
|
|
{
|
|
|
|
#if UNITY_5_3_OR_NEWER
|
|
|
|
UnityEngine.Profiling.Profiler.BeginSample(tag);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2024-10-17 01:59:25 +08:00
|
|
|
// [System.Diagnostics.Conditional("ENABLE_TEST_SROPTIONS")]
|
2024-08-17 14:27:18 +08:00
|
|
|
public static void EndSample()
|
|
|
|
{
|
|
|
|
#if UNITY_5_3_OR_NEWER
|
|
|
|
UnityEngine.Profiling.Profiler.EndSample();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 统计标记时间
|
|
|
|
/// </summary>
|
|
|
|
private static DateTime s_MarkStart;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 重置当前时间
|
|
|
|
/// </summary>
|
|
|
|
public static void ResetElapseTime()
|
|
|
|
{
|
|
|
|
s_MarkStart = DateTime.Now;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 统计时间间隔,单位:毫秒
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="tag"></param>
|
|
|
|
public static void LogElapseTime(string tag = "")
|
|
|
|
{
|
|
|
|
var ms = (DateTime.Now - s_MarkStart).TotalMilliseconds;
|
|
|
|
Debug.LogWarning($"{tag} use time:{ms} ms");
|
|
|
|
s_MarkStart = DateTime.Now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|