alloc tracking

This commit is contained in:
2025-12-18 14:09:39 +02:00
parent 43e1acacce
commit e4cd76fdaf
3 changed files with 27 additions and 21 deletions

View File

@@ -13,8 +13,8 @@
#define NEW_VERSION 1
#if BUILD_DEBUG
#define LONGER 1
#define CHUNK_TIMES 10
#define LONGER 3
#define CHUNK_TIMES 100
#else
#define LONGER 10
#define CHUNK_TIMES 1000
@@ -246,9 +246,9 @@ void MyScript::OnStart()
if (scriptTwo == nullptr)
return;
bool otherTests = true;
bool arrayTests = true;
bool asRefTests = true;
bool otherTests = false;
bool arrayTests = false;
bool asRefTests = false;
Array<uint64> results(TIMES);
auto CyclesToSeconds = 1.0 / static_cast<double>(Platform::GetClockFrequency());
@@ -266,6 +266,11 @@ void MyScript::OnStart()
TestStruct testStruct; testStruct.Object = actor; testStruct.SceneRef = sceneRef;
Array<TestStruct> complexArray; for (int i=0; i<10; i++) complexArray.Add(testStruct);
#if NEW_VERSION
int64 allocationsBefore, deallocationsBefore;
scriptTwo->GetStats(allocationsBefore, deallocationsBefore);
#endif
if (otherTests)
{
BENCHMARK_CALL_ARGS0(TIMES2, SimpleCall);
@@ -449,7 +454,7 @@ void MyScript::OnStart()
}
if (arrayTests)
if (true || arrayTests)
{
BENCHMARK_CALL_ARGS1(TIMES4, SimpleArrayParam, simpleArray);
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES3, SimpleArrayParam);
@@ -534,6 +539,12 @@ void MyScript::OnStart()
#endif
BENCHMARK_THUNK_END();*/
}
#if NEW_VERSION
int64 allocationsAfter, deallocationsAfter;
scriptTwo->GetStats(allocationsAfter, deallocationsAfter);
LOG(Info, "Total ManagedHandle allocations: {}, deallocations: {}", allocationsAfter-allocationsBefore, deallocationsAfter-deallocationsBefore);
#endif
}
void MyScript::OnEnable()

View File

@@ -10,20 +10,6 @@
#include "Engine/Scripting/SoftTypeReference.h"
#include "Engine/Content/SceneReference.h"
API_ENUM() enum TestTypeEnum
{
None,
Value1,
Value22,
};
/*template<typename T>
API_STRUCT() struct GAME_API MyThinger
{
public:
T fieldo;
};*/
API_STRUCT(NoDefault) struct TestStruct : public ISerializable
{
API_AUTO_SERIALIZATION();
@@ -52,8 +38,10 @@ API_CLASS() class GAME_API MyScript2 : public Script
API_AUTO_SERIALIZATION();
DECLARE_SCRIPTING_TYPE(MyScript2);
API_FUNCTION() virtual void GetStats(API_PARAM(Ref) int64& allocations, API_PARAM(Ref) int64& deallocations) {};
API_FUNCTION() virtual void SimpleCall() {};
API_FUNCTION() virtual void SimpleParams(int a, float b, char c, double d, long e) {};
API_FUNCTION() virtual void SimpleParams(int32 a, float b, char c, double d, int64 e) {};
API_FUNCTION() virtual void StringParamAnsi(StringAnsi str) {};
API_FUNCTION() virtual void StringParam(String str) {};
API_FUNCTION() virtual void StringParamRef(String& str) {};

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using FlaxEngine;
using FlaxEngine.Interop;
namespace Game;
@@ -32,6 +33,12 @@ public class MyScriptTwo : MyScript2
{
}
public override void GetStats(ref long allocations, ref long deallocations)
{
allocations = ManagedHandle.Allocations;
deallocations = ManagedHandle.Deallocations;
}
public override void SimpleCall() {}
public override void SimpleParams(int a, float b, sbyte c, double d, long e) {}
public override void StringParamAnsi(string str) {}