Add more profile events

This commit is contained in:
Wojtek Figat
2021-07-06 16:17:11 +02:00
parent bf67c62311
commit 9f9e5b49cc
8 changed files with 47 additions and 4 deletions

View File

@@ -588,6 +588,7 @@ void EngineImpl::InitMainWindow()
return; return;
} }
#endif #endif
PROFILE_CPU_NAMED("Engine::InitMainWindow");
// Create window // Create window
Engine::MainWindow = Application::CreateMainWindow(); Engine::MainWindow = Application::CreateMainWindow();

View File

@@ -328,6 +328,8 @@ FoliageType* Foliage::GetFoliageType(int32 index)
void Foliage::AddFoliageType(Model* model) void Foliage::AddFoliageType(Model* model)
{ {
PROFILE_CPU();
// Ensure to have unique model // Ensure to have unique model
CHECK(model); CHECK(model);
for (int32 i = 0; i < FoliageTypes.Count(); i++) for (int32 i = 0; i < FoliageTypes.Count(); i++)
@@ -352,6 +354,8 @@ void Foliage::AddFoliageType(Model* model)
void Foliage::RemoveFoliageType(int32 index) void Foliage::RemoveFoliageType(int32 index)
{ {
PROFILE_CPU();
// Remove instances using this foliage type // Remove instances using this foliage type
if (FoliageTypes.Count() != 1) if (FoliageTypes.Count() != 1)
{ {

View File

@@ -4,6 +4,7 @@
#include "ScriptingObject.h" #include "ScriptingObject.h"
#include "Engine/Core/Log.h" #include "Engine/Core/Log.h"
#include "Engine/Threading/Threading.h" #include "Engine/Threading/Threading.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "ManagedCLR/MAssembly.h" #include "ManagedCLR/MAssembly.h"
#include "ManagedCLR/MClass.h" #include "ManagedCLR/MClass.h"
#include "ManagedCLR/MType.h" #include "ManagedCLR/MType.h"
@@ -589,6 +590,7 @@ MMethod* ManagedBinaryModule::FindMethod(MClass* mclass, const ScriptingTypeMeth
void ManagedBinaryModule::OnLoading(MAssembly* assembly) void ManagedBinaryModule::OnLoading(MAssembly* assembly)
{ {
PROFILE_CPU();
for (ScriptingType& type : Types) for (ScriptingType& type : Types)
{ {
type.InitRuntime(); type.InitRuntime();
@@ -597,6 +599,7 @@ void ManagedBinaryModule::OnLoading(MAssembly* assembly)
void ManagedBinaryModule::OnLoaded(MAssembly* assembly) void ManagedBinaryModule::OnLoaded(MAssembly* assembly)
{ {
PROFILE_CPU();
ASSERT(ClassToTypeIndex.IsEmpty()); ASSERT(ClassToTypeIndex.IsEmpty());
const auto& classes = assembly->GetClasses(); const auto& classes = assembly->GetClasses();
@@ -750,6 +753,8 @@ void ManagedBinaryModule::OnLoaded(MAssembly* assembly)
void ManagedBinaryModule::OnUnloading(MAssembly* assembly) void ManagedBinaryModule::OnUnloading(MAssembly* assembly)
{ {
PROFILE_CPU();
// Clear managed-only types // Clear managed-only types
for (int32 i = _firstManagedTypeIndex; i < Types.Count(); i++) for (int32 i = _firstManagedTypeIndex; i < Types.Count(); i++)
{ {

View File

@@ -17,6 +17,7 @@
#include "Engine/Scripting/Scripting.h" #include "Engine/Scripting/Scripting.h"
#include "Engine/Platform/StringUtils.h" #include "Engine/Platform/StringUtils.h"
#include "Engine/Platform/File.h" #include "Engine/Platform/File.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Threading/Threading.h" #include "Engine/Threading/Threading.h"
#include <ThirdParty/mono-2.0/mono/metadata/mono-debug.h> #include <ThirdParty/mono-2.0/mono/metadata/mono-debug.h>
#include <ThirdParty/mono-2.0/mono/metadata/assembly.h> #include <ThirdParty/mono-2.0/mono/metadata/assembly.h>
@@ -49,9 +50,10 @@ String MAssembly::ToString() const
bool MAssembly::Load(const String& assemblyPath) bool MAssembly::Load(const String& assemblyPath)
{ {
// Skip if already loaded
if (IsLoaded()) if (IsLoaded())
return false; return false;
PROFILE_CPU();
ZoneText(*assemblyPath, assemblyPath.Length());
// Check file path // Check file path
if (!FileSystem::FileExists(assemblyPath)) if (!FileSystem::FileExists(assemblyPath))
@@ -83,9 +85,13 @@ bool MAssembly::Load(const String& assemblyPath)
bool MAssembly::Load(MonoImage* monoImage) bool MAssembly::Load(MonoImage* monoImage)
{ {
// Skip if already loaded
if (IsLoaded()) if (IsLoaded())
return false; return false;
PROFILE_CPU();
#if TRACY_ENABLE
const StringAnsiView monoImageName(mono_image_get_name(monoImage));
ZoneText(*monoImageName, monoImageName.Length());
#endif
// Ensure to be unloaded // Ensure to be unloaded
Unload(); Unload();
@@ -114,6 +120,7 @@ void MAssembly::Unload(bool isReloading)
{ {
if (!IsLoaded()) if (!IsLoaded())
return; return;
PROFILE_CPU();
Unloading(this); Unloading(this);
@@ -223,6 +230,11 @@ const MAssembly::ClassesDictionary& MAssembly::GetClasses() const
{ {
if (_hasCachedClasses || !IsLoaded()) if (_hasCachedClasses || !IsLoaded())
return _classes; return _classes;
PROFILE_CPU();
#if TRACY_ENABLE
const StringAnsiView monoImageName(mono_image_get_name(_monoImage));
ZoneText(*monoImageName, monoImageName.Length());
#endif
ScopeLock lock(_locker); ScopeLock lock(_locker);
if (_hasCachedClasses) if (_hasCachedClasses)
return _classes; return _classes;

View File

@@ -342,6 +342,7 @@ static void* OnMonoLinuxDlSym(void* handle, const char* name, char** err, void*
bool MCore::LoadEngine() bool MCore::LoadEngine()
{ {
PROFILE_CPU();
ASSERT(Globals::MonoPath.IsANSI()); ASSERT(Globals::MonoPath.IsANSI());
#if 0 #if 0
@@ -609,16 +610,19 @@ void MCore::ExitThread()
void MCore::GC::Collect() void MCore::GC::Collect()
{ {
PROFILE_CPU();
mono_gc_collect(mono_gc_max_generation()); mono_gc_collect(mono_gc_max_generation());
} }
void MCore::GC::Collect(int32 generation) void MCore::GC::Collect(int32 generation)
{ {
PROFILE_CPU();
mono_gc_collect(generation); mono_gc_collect(generation);
} }
void MCore::GC::WaitForPendingFinalizers() void MCore::GC::WaitForPendingFinalizers()
{ {
PROFILE_CPU();
if (mono_gc_pending_finalizers()) if (mono_gc_pending_finalizers())
{ {
mono_gc_finalize_notify(); mono_gc_finalize_notify();

View File

@@ -409,6 +409,7 @@ bool Scripting::LoadBinaryModules(const String& path, const String& projectFolde
bool Scripting::Load() bool Scripting::Load()
{ {
PROFILE_CPU();
// Note: this action can be called from main thread (due to Mono problems with assemblies actions from other threads) // Note: this action can be called from main thread (due to Mono problems with assemblies actions from other threads)
ASSERT(IsInMainThread()); ASSERT(IsInMainThread());
@@ -472,6 +473,7 @@ bool Scripting::Load()
void Scripting::Release() void Scripting::Release()
{ {
PROFILE_CPU();
// Note: this action can be called from main thread (due to Mono problems with assemblies actions from other threads) // Note: this action can be called from main thread (due to Mono problems with assemblies actions from other threads)
ASSERT(IsInMainThread()); ASSERT(IsInMainThread());
@@ -718,7 +720,6 @@ ScriptingObject* Scripting::FindObject(Guid id, MClass* type)
{ {
if (!id.IsValid()) if (!id.IsValid())
return nullptr; return nullptr;
PROFILE_CPU(); PROFILE_CPU();
// Try to map object id // Try to map object id
@@ -798,7 +799,6 @@ ScriptingObject* Scripting::FindObject(const MonoObject* managedInstance)
{ {
if (managedInstance == nullptr) if (managedInstance == nullptr)
return nullptr; return nullptr;
PROFILE_CPU(); PROFILE_CPU();
// TODO: optimize it by reading the unmanagedPtr or _internalId from managed Object property // TODO: optimize it by reading the unmanagedPtr or _internalId from managed Object property

View File

@@ -112,6 +112,22 @@ inline void ScopedZone::Text( const char* txt, size_t size )
TracyLfqCommit; TracyLfqCommit;
} }
inline void ScopedZone::Text(const Char* txt, size_t size)
{
assert( size < std::numeric_limits<uint16_t>::max() );
if( !m_active ) return;
#ifdef TRACY_ON_DEMAND
if( GetProfiler().ConnectionId() != m_connectionId ) return;
#endif
auto ptr = (char*)tracy_malloc( size );
for( int i = 0; i < size; i++)
ptr[i] = (char)txt[i];
TracyLfqPrepare( QueueType::ZoneText );
MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
MemWrite( &item->zoneTextFat.size, (uint16_t)size );
TracyLfqCommit;
}
inline void ScopedZone::Name( const char* txt, size_t size ) inline void ScopedZone::Name( const char* txt, size_t size )
{ {
assert( size < std::numeric_limits<uint16_t>::max() ); assert( size < std::numeric_limits<uint16_t>::max() );

View File

@@ -59,6 +59,7 @@ public:
~ScopedZone(); ~ScopedZone();
void Text( const char* txt, size_t size ); void Text( const char* txt, size_t size );
void Text( const Char* txt, size_t size );
void Name( const char* txt, size_t size ); void Name( const char* txt, size_t size );
void Name( const Char* txt, size_t size ); void Name( const Char* txt, size_t size );
void Color( uint32_t color ); void Color( uint32_t color );