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).
This commit is contained in:
parent
583c0c4897
commit
eb56d1d1eb
7 changed files with 0 additions and 243 deletions
|
@ -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<OSCoreBindImg> imgs;
|
||||
uint64_t total = 0;
|
||||
{
|
||||
List<Ref<Resource>> rsrc;
|
||||
ResourceCache::get_cached_resources(&rsrc);
|
||||
|
||||
for (Ref<Resource> &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<String> &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<String, int> type_count;
|
||||
List<Ref<Resource>> resources;
|
||||
ResourceCache::get_cached_resources(&resources);
|
||||
|
||||
for (const Ref<Resource> &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<StringName> metas;
|
||||
r->get_meta_list(&metas);
|
||||
for (const StringName &meta : metas) {
|
||||
print_line(vformat(" %s: %s", meta, r->get_meta(meta)));
|
||||
}
|
||||
}
|
||||
|
||||
for (const KeyValue<String, int> &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);
|
||||
|
|
|
@ -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<String> &p_types);
|
||||
|
||||
bool is_debug_build() const;
|
||||
|
||||
String get_unique_id() const;
|
||||
|
|
|
@ -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<String, int> type_count;
|
||||
|
||||
Ref<FileAccess> 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<String, Resource *> &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<String, int> &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
|
||||
}
|
||||
|
|
|
@ -167,7 +167,6 @@ public:
|
|||
static void reload_externals();
|
||||
static bool has(const String &p_path);
|
||||
static Ref<Resource> get_ref(const String &p_path);
|
||||
static void dump(const char *p_file = nullptr, bool p_short = false);
|
||||
static void get_cached_resources(List<Ref<Resource>> *p_resources);
|
||||
static int get_cached_resource_count();
|
||||
};
|
||||
|
|
|
@ -186,46 +186,6 @@ void OS::set_stderr_enabled(bool p_enabled) {
|
|||
_stderr_enabled = p_enabled;
|
||||
}
|
||||
|
||||
static Ref<FileAccess> _OSPRF;
|
||||
|
||||
static void _OS_printres(Object *p_obj) {
|
||||
Resource *res = Object::cast_to<Resource>(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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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).
|
||||
</description>
|
||||
</method>
|
||||
<method name="dump_resources_to_file">
|
||||
<return type="void" />
|
||||
<param index="0" name="file" type="String" />
|
||||
<description>
|
||||
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.
|
||||
</description>
|
||||
</method>
|
||||
<method name="execute">
|
||||
<return type="int" />
|
||||
<param index="0" name="path" type="String" />
|
||||
|
@ -526,33 +517,6 @@
|
|||
[b]Note:[/b] This method is implemented on Linux, macOS and Windows.
|
||||
</description>
|
||||
</method>
|
||||
<method name="print_all_resources">
|
||||
<return type="void" />
|
||||
<param index="0" name="tofile" type="String" default="""" />
|
||||
<description>
|
||||
Shows all resources in the game. Optionally, the list can be written to a file by specifying a file path in [param tofile].
|
||||
</description>
|
||||
</method>
|
||||
<method name="print_all_textures_by_size">
|
||||
<return type="void" />
|
||||
<description>
|
||||
Shows the list of loaded textures sorted by size in memory.
|
||||
</description>
|
||||
</method>
|
||||
<method name="print_resources_by_type">
|
||||
<return type="void" />
|
||||
<param index="0" name="types" type="PackedStringArray" />
|
||||
<description>
|
||||
Shows the number of resources loaded by the game of the given types.
|
||||
</description>
|
||||
</method>
|
||||
<method name="print_resources_in_use">
|
||||
<return type="void" />
|
||||
<param index="0" name="short" type="bool" default="false" />
|
||||
<description>
|
||||
Shows all resources currently used by the game.
|
||||
</description>
|
||||
</method>
|
||||
<method name="request_permission">
|
||||
<return type="bool" />
|
||||
<param index="0" name="name" type="String" />
|
||||
|
|
Loading…
Reference in a new issue