尝试同步
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TracyProfiler
|
||||
@@ -37,10 +38,11 @@ namespace TracyProfiler
|
||||
private static extern void TracySetThreadName(string name);
|
||||
|
||||
[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern void TracyZoneBegin(string name);
|
||||
private static extern void TracyZoneScopedBegin(string name, string function = "", string file = "",
|
||||
int line = 0);
|
||||
|
||||
[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern void TracyZoneEnd();
|
||||
private static extern void TracyZoneScopedEnd(string name);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -70,7 +72,7 @@ namespace TracyProfiler
|
||||
|
||||
try
|
||||
{
|
||||
#if TRACY_ENABLE || UNITY_EDITOR
|
||||
#if TRACY_ENABLE
|
||||
TracyInit();
|
||||
s_initialized = true;
|
||||
Debug.Log("[Tracy] 性能分析器已初始化");
|
||||
@@ -176,15 +178,14 @@ namespace TracyProfiler
|
||||
private bool isValid;
|
||||
private string zoneName;
|
||||
|
||||
public ZoneScope(string name)
|
||||
public ZoneScope(string name, string function = "", string file = "", int line = 0)
|
||||
{
|
||||
zoneName = name;
|
||||
isValid = s_initialized && s_enabled;
|
||||
|
||||
#if TRACY_ENABLE
|
||||
if (isValid)
|
||||
{
|
||||
TracyZoneBegin(name);
|
||||
TracyZoneScopedBegin(name, function, file, line);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -194,7 +195,7 @@ namespace TracyProfiler
|
||||
#if TRACY_ENABLE
|
||||
if (isValid && s_initialized && s_enabled)
|
||||
{
|
||||
TracyZoneEnd();
|
||||
TracyZoneScopedEnd(zoneName);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -210,31 +211,12 @@ namespace TracyProfiler
|
||||
/// // 要追踪的代码
|
||||
/// }
|
||||
/// </example>
|
||||
public static ZoneScope Zone(string name)
|
||||
public static ZoneScope Zone(string name,
|
||||
[CallerMemberName] string function = "",
|
||||
[CallerFilePath] string file = "",
|
||||
[CallerLineNumber] int line = 0)
|
||||
{
|
||||
return new ZoneScope(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始一个命名的 Zone
|
||||
/// 注意:必须手动调用 EndZone() 结束,推荐使用 Zone() 方法配合 using 语句
|
||||
/// </summary>
|
||||
[System.Diagnostics.Conditional("TRACY_ENABLE")]
|
||||
public static void BeginZone(string name)
|
||||
{
|
||||
if (!s_initialized || !s_enabled) return;
|
||||
TracyZoneBegin(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 结束当前 Zone
|
||||
/// 注意:必须与 BeginZone() 配对使用
|
||||
/// </summary>
|
||||
[System.Diagnostics.Conditional("TRACY_ENABLE")]
|
||||
public static void EndZone()
|
||||
{
|
||||
if (!s_initialized || !s_enabled) return;
|
||||
TracyZoneEnd();
|
||||
return new ZoneScope(name, function, file, line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user