Browse Source

Static profiler BeginBlock and EndBlock methods for c#

Rokas Kupstys 8 years ago
parent
commit
bedf501ac2

+ 22 - 1
Script/AtomicNET/AtomicNET/Core/Profiler.cs

@@ -18,11 +18,32 @@ namespace AtomicEngine
 #endif
 #endif
             block();
             block();
 #if ATOMIC_PROFILING
 #if ATOMIC_PROFILING
-            profiler?.EndBlock();
+            if (profiler != null)
+                csi_Atomic_Profiler_EndBlock(profiler);
 #endif
 #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)]
         [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);
         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);
     }
     }
 }
 }

+ 3 - 0
Script/Packages/Atomic/Core.json

@@ -28,6 +28,9 @@
 		"CSharp" : {
 		"CSharp" : {
 			"Object" : {
 			"Object" : {
 				"UnsubscribeFromAllEvents" : []
 				"UnsubscribeFromAllEvents" : []
+			},
+			"Profiler": {
+				"EndBlock" : []
 			}
 			}
 		}
 		}
 	},
 	},

+ 10 - 0
Source/AtomicNET/NETNative/NETCInterop.cpp

@@ -766,6 +766,16 @@ namespace Atomic
                 warned = true;
                 warned = true;
                 ATOMIC_LOGWARNING("Engine is built without profiler support.");
                 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
 #endif
         }
         }
     }
     }