1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Add an ObjectDB Profiling Tool

A new tab is added to the debugger that can help profile a game's memory usage.

Specifically, this lets you save a snapshot of all the objects in a running
game's ObjectDB to disk. It then lets you view the snapshot and diff two
snapshots against each other. This is meant to work similarly to Chrome's
heap snapshot tool or Unity's memory profiler.
This commit is contained in:
Aleksander Litynski
2025-05-06 10:30:52 +02:00
committed by Mikael Hermansson
parent 4d1f26e1fd
commit 78f1543e35
40 changed files with 4262 additions and 109 deletions

View File

@@ -2334,12 +2334,11 @@ void postinitialize_handler(Object *p_object) {
p_object->_postinitialize();
}
void ObjectDB::debug_objects(DebugFunc p_func) {
void ObjectDB::debug_objects(DebugFunc p_func, void *p_user_data) {
spin_lock.lock();
for (uint32_t i = 0, count = slot_count; i < slot_max && count != 0; i++) {
if (object_slots[i].validator) {
p_func(object_slots[i].object);
p_func(object_slots[i].object, p_user_data);
count--;
}
}
@@ -2507,6 +2506,9 @@ void ObjectDB::cleanup() {
if (obj->is_class("Resource")) {
extra_info = " - Resource path: " + String(resource_get_path->call(obj, nullptr, 0, call_error));
}
if (obj->is_class("RefCounted")) {
extra_info = " - RefCount: " + itos(((RefCounted *)obj)->get_reference_count());
}
uint64_t id = uint64_t(i) | (uint64_t(object_slots[i].validator) << OBJECTDB_SLOT_MAX_COUNT_BITS) | (object_slots[i].is_ref_counted ? OBJECTDB_REFERENCE_BIT : 0);
DEV_ASSERT(id == (uint64_t)obj->get_instance_id()); // We could just use the id from the object, but this check may help catching memory corruption catastrophes.