Refactor Tracy source locations to be static

#597
This commit is contained in:
Wojtek Figat
2021-08-13 13:44:29 +02:00
parent 0bbb72e24d
commit 9deb021a5e
10 changed files with 115 additions and 20 deletions

View File

@@ -60,18 +60,23 @@ MMethod::MMethod(MonoMethod* monoMethod, const char* name, MClass* parentClass)
ProfilerName.Get()[className.Length()] = ':';
ProfilerName.Get()[className.Length() + 1] = ':';
Platform::MemoryCopy(ProfilerName.Get() + className.Length() + 2, _name.Get(), _name.Length());
ProfilerData.name = ProfilerName.Get();
ProfilerData.function = _name.Get();
ProfilerData.file = nullptr;
ProfilerData.line = 0;
ProfilerData.color = 0;
#endif
}
MonoObject* MMethod::Invoke(void* instance, void** params, MonoObject** exception) const
{
PROFILE_CPU_NAMED(*ProfilerName);
PROFILE_CPU_SRC_LOC(ProfilerData);
return mono_runtime_invoke(_monoMethod, instance, params, exception);
}
MonoObject* MMethod::InvokeVirtual(MonoObject* instance, void** params, MonoObject** exception) const
{
PROFILE_CPU_NAMED(*ProfilerName);
PROFILE_CPU_SRC_LOC(ProfilerData);
MonoMethod* virtualMethod = mono_object_get_virtual_method(instance, _monoMethod);
return mono_runtime_invoke(virtualMethod, instance, params, exception);
}

View File

@@ -3,6 +3,9 @@
#pragma once
#include "Engine/Core/Collections/Array.h"
#if COMPILE_WITH_PROFILER
#include "Engine/Profiler/ProfilerSrcLoc.h"
#endif
#include "MTypes.h"
/// <summary>
@@ -42,6 +45,7 @@ public:
#if COMPILE_WITH_PROFILER
MString ProfilerName;
SourceLocationData ProfilerData;
#endif
#if USE_MONO

View File

@@ -9,13 +9,29 @@
#include "Engine/Scripting/ManagedCLR/MUtils.h"
#include "Engine/Core/ObjectsRemovalService.h"
#include "Engine/Profiler/Profiler.h"
#if TRACY_ENABLE && !PROFILE_CPU_USE_TRANSIENT_DATA
#include "Engine/Core/Collections/ChunkedArray.h"
#endif
#include "Engine/Core/Types/Pair.h"
#include "Engine/Threading/Threading.h"
#include <ThirdParty/mono-2.0/mono/metadata/mono-gc.h>
namespace ProfilerInternal
{
#if COMPILE_WITH_PROFILER
Array<int32> ManagedEventsGPU;
Array<int32, InlinedAllocation<32>> ManagedEventsGPU;
#if TRACY_ENABLE && !PROFILE_CPU_USE_TRANSIENT_DATA
CriticalSection ManagedSourceLocationsLocker;
struct Location
{
String Name;
StringAnsi NameAnsi;
tracy::SourceLocationData SrcLocation;
};
ChunkedArray<Location, 256> ManagedSourceLocations;
#endif
#endif
void BeginEvent(MonoString* nameObj)
@@ -24,7 +40,34 @@ namespace ProfilerInternal
const StringView name((const Char*)mono_string_chars(nameObj), mono_string_length(nameObj));
ProfilerCPU::BeginEvent(*name);
#if TRACY_ENABLE
#if PROFILE_CPU_USE_TRANSIENT_DATA
tracy::ScopedZone::Begin(__LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), name.Get(), name.Length() );
#else
ScopeLock lock(ManagedSourceLocationsLocker);
tracy::SourceLocationData* srcLoc = nullptr;
for (auto& e = ManagedSourceLocations.Begin(); e.IsNotEnd(); ++e)
{
if (name == e->Name)
{
srcLoc = &e->SrcLocation;
break;
}
}
if (!srcLoc)
{
auto& e = ManagedSourceLocations.AddOne();
e.Name = name;
e.NameAnsi = name.Get();
srcLoc = &e.SrcLocation;
srcLoc->name = e.NameAnsi.Get();
srcLoc->function = nullptr;
srcLoc->file = nullptr;
srcLoc->line = 0;
srcLoc->color = 0;
}
//static constexpr tracy::SourceLocationData tracySrcLoc{ nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 };
tracy::ScopedZone::Begin(srcLoc);
#endif
#endif
#endif
}