From 8c3a6b10a9b9f0818d2953473e57e69f24104b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 28 Feb 2021 12:10:47 +0100 Subject: OS: Fix used resource debug prints These methods were broken by 22419082d9bedbc9dc060ea5784bb0871f8710a3 5 years ago and nobody complained, so maybe they're not so useful... But at least this should restore them to a working state. --- core/core_bind.cpp | 36 ++++++++++++++++++++++++++++++++---- core/io/resource.cpp | 2 ++ core/os/os.cpp | 2 +- 3 files changed, 35 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/core_bind.cpp b/core/core_bind.cpp index d34ed29691..6f6c4056a9 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -356,7 +356,7 @@ void _OS::print_all_textures_by_size() { ResourceCache::get_cached_resources(&rsrc); for (Ref &res : rsrc) { - if (!res->is_class("ImageTexture")) { + if (!res->is_class("Texture")) { continue; } @@ -376,14 +376,30 @@ void _OS::print_all_textures_by_size() { imgs.sort(); - for (_OSCoreBindImg &E : imgs) { - total -= E.vram; + if (imgs.size() == 0) { + print_line("No textures seem used in this project."); + } else { + print_line("Textures currently in use, sorted by VRAM usage:\n" + "Path - VRAM usage (Dimensions)"); + } + + for (const _OSCoreBindImg &img : imgs) { + print_line(vformat("%s - %s %s", + img.path, + String::humanize_size(img.vram), + img.size)); } + + print_line(vformat("Total VRAM usage: %s.", String::humanize_size(total))); } void _OS::print_resources_by_type(const Vector &p_types) { - Map type_count; + ERR_FAIL_COND_MSG(p_types.size() == 0, + "At least one type should be provided to print resources by type."); + + print_line(vformat("Resources currently in use for the following types: %s", p_types)); + Map type_count; List> resources; ResourceCache::get_cached_resources(&resources); @@ -404,6 +420,18 @@ void _OS::print_resources_by_type(const Vector &p_types) { } type_count[r->get_class()]++; + + print_line(vformat("%s: %s", r->get_class(), r->get_path())); + + List metas; + r->get_meta_list(&metas); + for (const StringName &meta : metas) { + print_line(vformat(" %s: %s", meta, r->get_meta(meta))); + } + } + + for (const KeyValue &E : type_count) { + print_line(vformat("%s count: %d", E.key, E.value)); } } diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 727611a573..0262655927 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -552,5 +552,7 @@ void ResourceCache::dump(const char *p_file, bool p_short) { } lock.read_unlock(); +#else + WARN_PRINT("ResourceCache::dump only with in debug builds."); #endif } diff --git a/core/os/os.cpp b/core/os/os.cpp index cdb570bb73..76a6da51e1 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -178,7 +178,7 @@ static void _OS_printres(Object *p_obj) { return; } - String str = itos(res->get_instance_id()) + String(res->get_class()) + ":" + String(res->get_name()) + " - " + res->get_path(); + String str = vformat("%s - %s - %s", res->to_string(), res->get_name(), res->get_path()); if (_OSPRF) { _OSPRF->store_line(str); } else { -- cgit v1.2.3