From eb56d1d1eb6ba3fbf3cc45f603d893d8963d74f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Mon, 29 Aug 2022 12:56:53 +0200 Subject: Drop obsolete resource usage debug methods from OS class These methods exist since the dawn of (open source) Godot and have hardly been updated over time, so they barely work and I'm fairly sure nobody is using them. (See #46505 for details.) While some of the functionality they aimed to provide might be useful for optimization work and introspection, this should likely be redesigned from scratch with a cleaner and more modern interface (e.g. exposed via the Performance singleton, or ResourceLoader, and a better API overall). --- core/core_bind.cpp | 115 --------------------------------------------------- core/core_bind.h | 7 ---- core/io/resource.cpp | 40 ------------------ core/io/resource.h | 1 - core/os/os.cpp | 40 ------------------ core/os/os.h | 4 -- doc/classes/OS.xml | 36 ---------------- 7 files changed, 243 deletions(-) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index bcc87d78c4..9daf58cb71 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -437,114 +437,6 @@ bool OS::is_stdout_verbose() const { return ::OS::get_singleton()->is_stdout_verbose(); } -struct OSCoreBindImg { - String path; - Size2 size; - int fmt = 0; - ObjectID id; - int vram = 0; - bool operator<(const OSCoreBindImg &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; } -}; - -void OS::print_all_textures_by_size() { - List imgs; - uint64_t total = 0; - { - List> rsrc; - ResourceCache::get_cached_resources(&rsrc); - - for (Ref &res : rsrc) { - if (!res->is_class("Texture")) { - continue; - } - - Size2 size = res->call("get_size"); - int fmt = res->call("get_format"); - - OSCoreBindImg img; - img.size = size; - img.fmt = fmt; - img.path = res->get_path(); - img.vram = Image::get_image_data_size(img.size.width, img.size.height, Image::Format(img.fmt)); - img.id = res->get_instance_id(); - total += img.vram; - imgs.push_back(img); - } - } - - imgs.sort(); - - 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) { - 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)); - - RBMap type_count; - List> resources; - ResourceCache::get_cached_resources(&resources); - - for (const Ref &r : resources) { - bool found = false; - - for (int i = 0; i < p_types.size(); i++) { - if (r->is_class(p_types[i])) { - found = true; - } - } - if (!found) { - continue; - } - - if (!type_count.has(r->get_class())) { - type_count[r->get_class()] = 0; - } - - 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)); - } -} - -void OS::print_all_resources(const String &p_to_file) { - ::OS::get_singleton()->print_all_resources(p_to_file); -} - -void OS::print_resources_in_use(bool p_short) { - ::OS::get_singleton()->print_resources_in_use(p_short); -} - -void OS::dump_resources_to_file(const String &p_file) { - ::OS::get_singleton()->dump_resources_to_file(p_file.utf8().get_data()); -} - Error OS::move_to_trash(const String &p_path) const { return ::OS::get_singleton()->move_to_trash(p_path); } @@ -663,10 +555,6 @@ void OS::_bind_methods() { ClassDB::bind_method(D_METHOD("is_debug_build"), &OS::is_debug_build); - ClassDB::bind_method(D_METHOD("dump_resources_to_file", "file"), &OS::dump_resources_to_file); - ClassDB::bind_method(D_METHOD("print_resources_in_use", "short"), &OS::print_resources_in_use, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("print_all_resources", "tofile"), &OS::print_all_resources, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_static_memory_usage"), &OS::get_static_memory_usage); ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"), &OS::get_static_memory_peak_usage); @@ -678,9 +566,6 @@ void OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_cache_dir"), &OS::get_cache_dir); ClassDB::bind_method(D_METHOD("get_unique_id"), &OS::get_unique_id); - ClassDB::bind_method(D_METHOD("print_all_textures_by_size"), &OS::print_all_textures_by_size); - ClassDB::bind_method(D_METHOD("print_resources_by_type", "types"), &OS::print_resources_by_type); - ClassDB::bind_method(D_METHOD("get_keycode_string", "code"), &OS::get_keycode_string); ClassDB::bind_method(D_METHOD("is_keycode_unicode", "code"), &OS::is_keycode_unicode); ClassDB::bind_method(D_METHOD("find_keycode_from_string", "string"), &OS::find_keycode_from_string); diff --git a/core/core_bind.h b/core/core_bind.h index 642a0c00c7..cd382d2915 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -201,13 +201,6 @@ public: String get_model_name() const; - void dump_resources_to_file(const String &p_file); - - void print_resources_in_use(bool p_short = false); - void print_all_resources(const String &p_to_file); - void print_all_textures_by_size(); - void print_resources_by_type(const Vector &p_types); - bool is_debug_build() const; String get_unique_id() const; diff --git a/core/io/resource.cpp b/core/io/resource.cpp index fec5ca5c7b..d117f86f39 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -543,43 +543,3 @@ int ResourceCache::get_cached_resource_count() { return rc; } - -void ResourceCache::dump(const char *p_file, bool p_short) { -#ifdef DEBUG_ENABLED - lock.lock(); - - HashMap type_count; - - Ref f; - if (p_file) { - f = FileAccess::open(String::utf8(p_file), FileAccess::WRITE); - ERR_FAIL_COND_MSG(f.is_null(), "Cannot create file at path '" + String::utf8(p_file) + "'."); - } - - for (KeyValue &E : resources) { - Resource *r = E.value; - - if (!type_count.has(r->get_class())) { - type_count[r->get_class()] = 0; - } - - type_count[r->get_class()]++; - - if (!p_short) { - if (f.is_valid()) { - f->store_line(r->get_class() + ": " + r->get_path()); - } - } - } - - for (const KeyValue &E : type_count) { - if (f.is_valid()) { - f->store_line(E.key + " count: " + itos(E.value)); - } - } - - lock.unlock(); -#else - WARN_PRINT("ResourceCache::dump only with in debug builds."); -#endif -} diff --git a/core/io/resource.h b/core/io/resource.h index a2cde87990..a76a3920be 100644 --- a/core/io/resource.h +++ b/core/io/resource.h @@ -167,7 +167,6 @@ public: static void reload_externals(); static bool has(const String &p_path); static Ref get_ref(const String &p_path); - static void dump(const char *p_file = nullptr, bool p_short = false); static void get_cached_resources(List> *p_resources); static int get_cached_resource_count(); }; diff --git a/core/os/os.cpp b/core/os/os.cpp index 45cd7109e2..5536155d05 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -186,46 +186,6 @@ void OS::set_stderr_enabled(bool p_enabled) { _stderr_enabled = p_enabled; } -static Ref _OSPRF; - -static void _OS_printres(Object *p_obj) { - Resource *res = Object::cast_to(p_obj); - if (!res) { - return; - } - - String str = vformat("%s - %s - %s", res->to_string(), res->get_name(), res->get_path()); - if (_OSPRF.is_valid()) { - _OSPRF->store_line(str); - } else { - print_line(str); - } -} - -void OS::print_all_resources(String p_to_file) { - ERR_FAIL_COND(!p_to_file.is_empty() && _OSPRF.is_valid()); - if (!p_to_file.is_empty()) { - Error err; - _OSPRF = FileAccess::open(p_to_file, FileAccess::WRITE, &err); - if (err != OK) { - _OSPRF.unref(); - ERR_FAIL_MSG("Can't print all resources to file: " + String(p_to_file) + "."); - } - } - - ObjectDB::debug_objects(_OS_printres); - - _OSPRF.unref(); -} - -void OS::print_resources_in_use(bool p_short) { - ResourceCache::dump(nullptr, p_short); -} - -void OS::dump_resources_to_file(const char *p_file) { - ResourceCache::dump(p_file); -} - int OS::get_exit_code() const { return _exit_code; } diff --git a/core/os/os.h b/core/os/os.h index ff769cc4f1..0e8a2d0398 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -246,10 +246,6 @@ public: virtual bool is_disable_crash_handler() const { return false; } virtual void initialize_debugging() {} - virtual void dump_resources_to_file(const char *p_file); - virtual void print_resources_in_use(bool p_short = false); - virtual void print_all_resources(String p_to_file = ""); - virtual uint64_t get_static_memory_usage() const; virtual uint64_t get_static_memory_peak_usage() const; virtual uint64_t get_free_static_memory() const; diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index e180c73733..30a52210bb 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -88,15 +88,6 @@ [b]Note:[/b] When [method delay_usec] is called on the main thread, it will freeze the project and will prevent it from redrawing and registering input until the delay has passed. When using [method delay_usec] as part of an [EditorPlugin] or [EditorScript], it will freeze the editor but won't freeze the project if it is currently running (since the project is an independent child process). - - - - - Dumps all used resources to file (only works in debug). - Entry format per line: "Resource Type : Resource Location". - At the end of the file is a statistic of all used Resource Types. - - @@ -526,33 +517,6 @@ [b]Note:[/b] This method is implemented on Linux, macOS and Windows. - - - - - Shows all resources in the game. Optionally, the list can be written to a file by specifying a file path in [param tofile]. - - - - - - Shows the list of loaded textures sorted by size in memory. - - - - - - - Shows the number of resources loaded by the game of the given types. - - - - - - - Shows all resources currently used by the game. - - -- cgit v1.2.3