You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +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:
committed by
Mikael Hermansson
parent
4d1f26e1fd
commit
78f1543e35
@@ -697,18 +697,20 @@ void SceneDebugger::reload_cached_files(const PackedStringArray &p_files) {
|
||||
}
|
||||
}
|
||||
|
||||
SceneDebuggerObject::SceneDebuggerObject(ObjectID p_id) :
|
||||
SceneDebuggerObject(ObjectDB::get_instance(p_id)) {
|
||||
}
|
||||
|
||||
/// SceneDebuggerObject
|
||||
SceneDebuggerObject::SceneDebuggerObject(ObjectID p_id) {
|
||||
id = ObjectID();
|
||||
Object *obj = ObjectDB::get_instance(p_id);
|
||||
if (!obj) {
|
||||
SceneDebuggerObject::SceneDebuggerObject(Object *p_obj) {
|
||||
if (!p_obj) {
|
||||
return;
|
||||
}
|
||||
|
||||
id = p_id;
|
||||
class_name = obj->get_class();
|
||||
id = p_obj->get_instance_id();
|
||||
class_name = p_obj->get_class();
|
||||
|
||||
if (ScriptInstance *si = obj->get_script_instance()) {
|
||||
if (ScriptInstance *si = p_obj->get_script_instance()) {
|
||||
// Read script instance constants and variables
|
||||
if (!si->get_script().is_null()) {
|
||||
Script *s = si->get_script().ptr();
|
||||
@@ -716,7 +718,7 @@ SceneDebuggerObject::SceneDebuggerObject(ObjectID p_id) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Node *node = Object::cast_to<Node>(obj)) {
|
||||
if (Node *node = Object::cast_to<Node>(p_obj)) {
|
||||
// For debugging multiplayer.
|
||||
{
|
||||
PropertyInfo pi(Variant::INT, String("Node/multiplayer_authority"), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_READ_ONLY);
|
||||
@@ -731,17 +733,17 @@ SceneDebuggerObject::SceneDebuggerObject(ObjectID p_id) {
|
||||
PropertyInfo pi(Variant::STRING, String("Node/path"));
|
||||
properties.push_back(SceneDebuggerProperty(pi, "[Orphan]"));
|
||||
}
|
||||
} else if (Script *s = Object::cast_to<Script>(obj)) {
|
||||
} else if (Script *s = Object::cast_to<Script>(p_obj)) {
|
||||
// Add script constants (no instance).
|
||||
_parse_script_properties(s, nullptr);
|
||||
}
|
||||
|
||||
// Add base object properties.
|
||||
List<PropertyInfo> pinfo;
|
||||
obj->get_property_list(&pinfo, true);
|
||||
p_obj->get_property_list(&pinfo, true);
|
||||
for (const PropertyInfo &E : pinfo) {
|
||||
if (E.usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) {
|
||||
properties.push_back(SceneDebuggerProperty(E, obj->get(E.name)));
|
||||
properties.push_back(SceneDebuggerProperty(E, p_obj->get(E.name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -840,13 +842,16 @@ void SceneDebuggerObject::deserialize(const Array &p_arr) {
|
||||
CHECK_TYPE(p_arr[1], STRING);
|
||||
CHECK_TYPE(p_arr[2], ARRAY);
|
||||
|
||||
id = uint64_t(p_arr[0]);
|
||||
class_name = p_arr[1];
|
||||
Array props = p_arr[2];
|
||||
deserialize(uint64_t(p_arr[0]), p_arr[1], p_arr[2]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < props.size(); i++) {
|
||||
CHECK_TYPE(props[i], ARRAY);
|
||||
Array prop = props[i];
|
||||
void SceneDebuggerObject::deserialize(uint64_t p_id, const String &p_class_name, const Array &p_props) {
|
||||
id = p_id;
|
||||
class_name = p_class_name;
|
||||
|
||||
for (int i = 0; i < p_props.size(); i++) {
|
||||
CHECK_TYPE(p_props[i], ARRAY);
|
||||
Array prop = p_props[i];
|
||||
|
||||
ERR_FAIL_COND(prop.size() != 6);
|
||||
CHECK_TYPE(prop[0], STRING);
|
||||
|
||||
Reference in New Issue
Block a user