From 8db0bd44249e9cac56cf24c7c192bc782c118638 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: [PATCH] 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. (cherry picked from commit 8c3a6b10a9b9f0818d2953473e57e69f24104b6d) --- core/bind/core_bind.cpp | 38 +++++++++++++++++++++++++++++++++----- core/os/os.cpp | 2 +- core/resource.cpp | 2 ++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 0f36cdb61d5..ab17022bdbc 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -968,7 +968,7 @@ void _OS::print_all_textures_by_size() { ResourceCache::get_cached_resources(&rsrc); for (List>::Element *E = rsrc.front(); E; E = E->next()) { - if (!E->get()->is_class("ImageTexture")) { + if (!E->get()->is_class("Texture")) { continue; } @@ -988,14 +988,30 @@ void _OS::print_all_textures_by_size() { imgs.sort(); - for (List<_OSCoreBindImg>::Element *E = imgs.front(); E; E = E->next()) { - total -= E->get().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 (List<_OSCoreBindImg>::Element *E = imgs.front(); E; E = E->next()) { + print_line(vformat("%s - %s %s", + E->get().path, + String::humanize_size(E->get().vram), + E->get().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); @@ -1018,8 +1034,20 @@ 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 (List::Element *F = metas.front(); F; F = F->next()) { + print_line(vformat(" %s: %s", F->get(), r->get_meta(F->get()))); + } } -}; + + for (Map::Element *E = type_count.front(); E; E = E->next()) { + print_line(vformat("%s count: %d", E->key(), E->get())); + } +} bool _OS::has_virtual_keyboard() const { return OS::get_singleton()->has_virtual_keyboard(); diff --git a/core/os/os.cpp b/core/os/os.cpp index 8032b78edf3..ab2493041f2 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -199,7 +199,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 { diff --git a/core/resource.cpp b/core/resource.cpp index 668d2f5ebe9..05c4644b5ed 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -509,5 +509,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 }