diff --git a/Source/Engine/Scripting/ManagedCLR/MMethod.Mono.cpp b/Source/Engine/Scripting/ManagedCLR/MMethod.Mono.cpp index d1e8a6cef..3fb8a16a4 100644 --- a/Source/Engine/Scripting/ManagedCLR/MMethod.Mono.cpp +++ b/Source/Engine/Scripting/ManagedCLR/MMethod.Mono.cpp @@ -6,6 +6,7 @@ #include "MType.h" #include "MClass.h" +#include "Engine/Profiler/ProfilerCPU.h" #include #include @@ -51,15 +52,26 @@ MMethod::MMethod(MonoMethod* monoMethod, const char* name, MClass* parentClass) default: CRASH; } + +#if COMPILE_WITH_PROFILER + const MString& className = parentClass->GetFullName(); + ProfilerName.Resize(className.Length() + 2 + _name.Length()); + Platform::MemoryCopy(ProfilerName.Get(), className.Get(), className.Length()); + ProfilerName.Get()[className.Length()] = ':'; + ProfilerName.Get()[className.Length() + 1] = ':'; + Platform::MemoryCopy(ProfilerName.Get() + className.Length() + 2, _name.Get(), _name.Length()); +#endif } MonoObject* MMethod::Invoke(void* instance, void** params, MonoObject** exception) const { + PROFILE_CPU_NAMED(*ProfilerName); return mono_runtime_invoke(_monoMethod, instance, params, exception); } MonoObject* MMethod::InvokeVirtual(MonoObject* instance, void** params, MonoObject** exception) const { + PROFILE_CPU_NAMED(*ProfilerName); MonoMethod* virtualMethod = mono_object_get_virtual_method(instance, _monoMethod); return mono_runtime_invoke(virtualMethod, instance, params, exception); } @@ -90,7 +102,7 @@ int32 MMethod::GetParametersCount() const return mono_signature_get_param_count(sig); } -MType MMethod::GetParameterType(int32 paramIdx) +MType MMethod::GetParameterType(int32 paramIdx) const { MonoMethodSignature* sig = mono_method_signature(_monoMethod); ASSERT_LOW_LAYER(paramIdx >= 0 && paramIdx < (int32)mono_signature_get_param_count(sig)); @@ -99,7 +111,7 @@ MType MMethod::GetParameterType(int32 paramIdx) return MType(((MonoType**)it)[paramIdx]); } -bool MMethod::GetParameterIsOut(int32 paramIdx) +bool MMethod::GetParameterIsOut(int32 paramIdx) const { MonoMethodSignature* sig = mono_method_signature(_monoMethod); ASSERT_LOW_LAYER(paramIdx >= 0 && paramIdx < (int32)mono_signature_get_param_count(sig)); diff --git a/Source/Engine/Scripting/ManagedCLR/MMethod.h b/Source/Engine/Scripting/ManagedCLR/MMethod.h index 695ac2de0..60701a9b3 100644 --- a/Source/Engine/Scripting/ManagedCLR/MMethod.h +++ b/Source/Engine/Scripting/ManagedCLR/MMethod.h @@ -40,6 +40,10 @@ public: public: +#if COMPILE_WITH_PROFILER + MString ProfilerName; +#endif + #if USE_MONO /// @@ -91,7 +95,6 @@ public: /// /// Gets the method name. /// - /// The name. FORCE_INLINE const MString& GetName() const { return _name; @@ -100,7 +103,6 @@ public: /// /// Returns the parent class that this method is contained with. /// - /// The parent class. FORCE_INLINE MClass* GetParentClass() const { return _parentClass; @@ -109,13 +111,11 @@ public: /// /// Returns the type of the return value. Returns null if method has no return value. /// - /// Returns method return type MType GetReturnType() const; /// /// Returns the number of parameters the method expects. /// - /// The amount of the method parameters. int32 GetParametersCount() const; /// @@ -123,19 +123,18 @@ public: /// /// The parameter type. /// The parameter type. - MType GetParameterType(int32 paramIdx); + MType GetParameterType(int32 paramIdx) const; /// /// Returns the value indicating whenever the method parameter at the specified index is marked as output parameter. /// /// The parameter type. /// True if parameter is marked as output, otherwise false. - bool GetParameterIsOut(int32 paramIdx); + bool GetParameterIsOut(int32 paramIdx) const; /// /// Gets method visibility in the class. /// - /// The method visibility. FORCE_INLINE MVisibility GetVisibility() const { return _visibility; @@ -144,7 +143,6 @@ public: /// /// Returns true if the method doesn't require a class instance. /// - /// True if the method is static, otherwise false. FORCE_INLINE bool IsStatic() const { return _isStatic != 0; @@ -155,7 +153,6 @@ public: /// /// Gets the Mono method handle. /// - /// The native Mono method handle. FORCE_INLINE MonoMethod* GetNative() const { return _monoMethod; diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs index 1bde2a5c5..b01054d77 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs @@ -952,6 +952,8 @@ namespace Flax.Build.Bindings contents.Append(parameterInfo.Name); } + CppIncludeFiles.Add("Engine/Profiler/ProfilerCPU.h"); + contents.Append(')'); contents.AppendLine(); contents.AppendLine(" {"); @@ -985,6 +987,7 @@ namespace Flax.Build.Bindings contents.AppendLine(" auto scriptVTable = (MMethod**)managedTypePtr->Script.ScriptVTable;"); contents.AppendLine($" ASSERT(scriptVTable && scriptVTable[{scriptVTableIndex}]);"); contents.AppendLine($" auto method = scriptVTable[{scriptVTableIndex}];"); + contents.AppendLine(" PROFILE_CPU_NAMED(*method->ProfilerName);"); contents.AppendLine(" MonoObject* exception = nullptr;"); contents.AppendLine(" IsDuringWrapperCall = true;"); @@ -1228,6 +1231,7 @@ namespace Flax.Build.Bindings CppIncludeFiles.Add("Engine/Scripting/ManagedCLR/MClass.h"); CppIncludeFiles.Add("Engine/Scripting/ManagedCLR/MEvent.h"); CppIncludeFiles.Add("Engine/Scripting/ManagedCLR/MClass.h"); + CppIncludeFiles.Add("Engine/Profiler/ProfilerCPU.h"); contents.Append(" "); if (eventInfo.IsStatic) contents.Append("static "); @@ -1244,6 +1248,7 @@ namespace Flax.Build.Bindings contents.Append(" if (!mmethod)").AppendLine(); contents.AppendFormat(" mmethod = {1}::TypeInitializer.GetType().ManagedClass->GetMethod(\"Internal_{0}_Invoke\", {2});", eventInfo.Name, classTypeNameNative, paramsCount).AppendLine(); contents.Append(" CHECK(mmethod);").AppendLine(); + contents.Append(" PROFILE_CPU_NAMED(*mmethod->ProfilerName);").AppendLine(); contents.Append(" MonoObject* exception = nullptr;").AppendLine(); if (paramsCount == 0) contents.AppendLine(" void** params = nullptr;");