diff --git a/Script/AtomicNET/AtomicNET/Core/Profiler.cs b/Script/AtomicNET/AtomicNET/Core/Profiler.cs index 2f7b149824..b6b5641c65 100644 --- a/Script/AtomicNET/AtomicNET/Core/Profiler.cs +++ b/Script/AtomicNET/AtomicNET/Core/Profiler.cs @@ -18,11 +18,32 @@ public static void Block(string name, Action block, uint color = 0xffffecb3, #endif block(); #if ATOMIC_PROFILING - profiler?.EndBlock(); + if (profiler != null) + csi_Atomic_Profiler_EndBlock(profiler); #endif } + public static void BeginBlock(string name, uint color = 0xffffecb3, + ProfilerBlockStatus status = ProfilerBlockStatus.ON, + [CallerFilePath] string file = "", + [CallerLineNumber] int line = 0) + { + var profiler = AtomicNET.Context.GetProfiler(); + if (profiler != null) + csi_Atomic_Profiler_BeginBlock(profiler, name, file, line, color, (byte)status); + } + + public static void EndBlock() + { + var profiler = AtomicNET.Context.GetProfiler(); + if (profiler != null) + csi_Atomic_Profiler_EndBlock(profiler); + } + [DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] private static extern void csi_Atomic_Profiler_BeginBlock(IntPtr self, string name, string file, int line, uint argb, byte status); + + [DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + private static extern void csi_Atomic_Profiler_EndBlock(IntPtr self); } } diff --git a/Script/Packages/Atomic/Core.json b/Script/Packages/Atomic/Core.json index 02a6b541fa..50f53099aa 100755 --- a/Script/Packages/Atomic/Core.json +++ b/Script/Packages/Atomic/Core.json @@ -28,6 +28,9 @@ "CSharp" : { "Object" : { "UnsubscribeFromAllEvents" : [] + }, + "Profiler": { + "EndBlock" : [] } } }, diff --git a/Source/AtomicNET/NETNative/NETCInterop.cpp b/Source/AtomicNET/NETNative/NETCInterop.cpp index d1fa277ce9..60de51c7ac 100644 --- a/Source/AtomicNET/NETNative/NETCInterop.cpp +++ b/Source/AtomicNET/NETNative/NETCInterop.cpp @@ -766,6 +766,16 @@ namespace Atomic warned = true; ATOMIC_LOGWARNING("Engine is built without profiler support."); } +#endif + } + + ATOMIC_EXPORT_API void csi_Atomic_Profiler_EndBlock(Profiler* profiler) + { +#if ATOMIC_PROFILING + if (!profiler) + return; + + profiler->EndBlock(); #endif } }