mirror of
https://github.com/godotengine/godot
synced 2024-09-04 21:18:26 +00:00
Improve engine startup/shutdown benchmarks
- Add contexts to give a better sense of benchmarked areas. - Add missing benchmarks and adjust some begin/end points. - Clean up names. - Improve Android's internal benchmarks in a similar manner. Co-authored-by: Fredia Huya-Kouadio <fhuya@meta.com>
This commit is contained in:
parent
d5ad37afcd
commit
fc3f40f37d
|
@ -626,17 +626,22 @@ String OS::get_benchmark_file() {
|
|||
return benchmark_file;
|
||||
}
|
||||
|
||||
void OS::benchmark_begin_measure(const String &p_what) {
|
||||
void OS::benchmark_begin_measure(const String &p_context, const String &p_what) {
|
||||
#ifdef TOOLS_ENABLED
|
||||
start_benchmark_from[p_what] = OS::get_singleton()->get_ticks_usec();
|
||||
Pair<String, String> mark_key(p_context, p_what);
|
||||
ERR_FAIL_COND_MSG(benchmark_marks_from.has(mark_key), vformat("Benchmark key '%s:%s' already exists.", p_context, p_what));
|
||||
|
||||
benchmark_marks_from[mark_key] = OS::get_singleton()->get_ticks_usec();
|
||||
#endif
|
||||
}
|
||||
void OS::benchmark_end_measure(const String &p_what) {
|
||||
void OS::benchmark_end_measure(const String &p_context, const String &p_what) {
|
||||
#ifdef TOOLS_ENABLED
|
||||
uint64_t total = OS::get_singleton()->get_ticks_usec() - start_benchmark_from[p_what];
|
||||
double total_f = double(total) / double(1000000);
|
||||
Pair<String, String> mark_key(p_context, p_what);
|
||||
ERR_FAIL_COND_MSG(!benchmark_marks_from.has(mark_key), vformat("Benchmark key '%s:%s' doesn't exist.", p_context, p_what));
|
||||
|
||||
startup_benchmark_json[p_what] = total_f;
|
||||
uint64_t total = OS::get_singleton()->get_ticks_usec() - benchmark_marks_from[mark_key];
|
||||
double total_f = double(total) / double(1000000);
|
||||
benchmark_marks_final[mark_key] = total_f;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -645,19 +650,33 @@ void OS::benchmark_dump() {
|
|||
if (!use_benchmark) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!benchmark_file.is_empty()) {
|
||||
Ref<FileAccess> f = FileAccess::open(benchmark_file, FileAccess::WRITE);
|
||||
if (f.is_valid()) {
|
||||
Dictionary benchmark_marks;
|
||||
for (const KeyValue<Pair<String, String>, double> &E : benchmark_marks_final) {
|
||||
const String mark_key = vformat("[%s] %s", E.key.first, E.key.second);
|
||||
benchmark_marks[mark_key] = E.value;
|
||||
}
|
||||
|
||||
Ref<JSON> json;
|
||||
json.instantiate();
|
||||
f->store_string(json->stringify(startup_benchmark_json, "\t", false, true));
|
||||
f->store_string(json->stringify(benchmark_marks, "\t", false, true));
|
||||
}
|
||||
} else {
|
||||
List<Variant> keys;
|
||||
startup_benchmark_json.get_key_list(&keys);
|
||||
HashMap<String, String> results;
|
||||
for (const KeyValue<Pair<String, String>, double> &E : benchmark_marks_final) {
|
||||
if (E.key.first == "Startup" && !results.has(E.key.first)) {
|
||||
results.insert(E.key.first, "", true); // Hack to make sure "Startup" always comes first.
|
||||
}
|
||||
|
||||
results[E.key.first] += vformat("\t\t- %s: %.3f msec.\n", E.key.second, (E.value * 1000));
|
||||
}
|
||||
|
||||
print_line("BENCHMARK:");
|
||||
for (const Variant &K : keys) {
|
||||
print_line("\t-", K, ": ", startup_benchmark_json[K], +" sec.");
|
||||
for (const KeyValue<String, String> &E : results) {
|
||||
print_line(vformat("\t[%s]\n%s", E.key, E.value));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -79,8 +79,8 @@ class OS {
|
|||
// For tracking benchmark data
|
||||
bool use_benchmark = false;
|
||||
String benchmark_file;
|
||||
HashMap<String, uint64_t> start_benchmark_from;
|
||||
Dictionary startup_benchmark_json;
|
||||
HashMap<Pair<String, String>, uint64_t, PairHash<String, String>> benchmark_marks_from;
|
||||
HashMap<Pair<String, String>, double, PairHash<String, String>> benchmark_marks_final;
|
||||
|
||||
protected:
|
||||
void _set_logger(CompositeLogger *p_logger);
|
||||
|
@ -313,8 +313,8 @@ public:
|
|||
bool is_use_benchmark_set();
|
||||
void set_benchmark_file(const String &p_benchmark_file);
|
||||
String get_benchmark_file();
|
||||
virtual void benchmark_begin_measure(const String &p_what);
|
||||
virtual void benchmark_end_measure(const String &p_what);
|
||||
virtual void benchmark_begin_measure(const String &p_context, const String &p_what);
|
||||
virtual void benchmark_end_measure(const String &p_context, const String &p_what);
|
||||
virtual void benchmark_dump();
|
||||
|
||||
virtual void process_and_drop_events() {}
|
||||
|
|
|
@ -120,7 +120,8 @@ static ResourceUID *resource_uid = nullptr;
|
|||
static bool _is_core_extensions_registered = false;
|
||||
|
||||
void register_core_types() {
|
||||
OS::get_singleton()->benchmark_begin_measure("register_core_types");
|
||||
OS::get_singleton()->benchmark_begin_measure("Core", "Register Types");
|
||||
|
||||
//consistency check
|
||||
static_assert(sizeof(Callable) <= 16);
|
||||
|
||||
|
@ -296,7 +297,7 @@ void register_core_types() {
|
|||
|
||||
worker_thread_pool = memnew(WorkerThreadPool);
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("register_core_types");
|
||||
OS::get_singleton()->benchmark_end_measure("Core", "Register Types");
|
||||
}
|
||||
|
||||
void register_core_settings() {
|
||||
|
@ -311,6 +312,8 @@ void register_core_settings() {
|
|||
}
|
||||
|
||||
void register_core_singletons() {
|
||||
OS::get_singleton()->benchmark_begin_measure("Core", "Register Singletons");
|
||||
|
||||
GDREGISTER_CLASS(ProjectSettings);
|
||||
GDREGISTER_ABSTRACT_CLASS(IP);
|
||||
GDREGISTER_CLASS(core_bind::Geometry2D);
|
||||
|
@ -346,25 +349,35 @@ void register_core_singletons() {
|
|||
Engine::get_singleton()->add_singleton(Engine::Singleton("GDExtensionManager", GDExtensionManager::get_singleton()));
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton("ResourceUID", ResourceUID::get_singleton()));
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton("WorkerThreadPool", worker_thread_pool));
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Core", "Register Singletons");
|
||||
}
|
||||
|
||||
void register_core_extensions() {
|
||||
OS::get_singleton()->benchmark_begin_measure("Core", "Register Extensions");
|
||||
|
||||
// Hardcoded for now.
|
||||
GDExtension::initialize_gdextensions();
|
||||
gdextension_manager->load_extensions();
|
||||
gdextension_manager->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_CORE);
|
||||
_is_core_extensions_registered = true;
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Core", "Register Extensions");
|
||||
}
|
||||
|
||||
void unregister_core_extensions() {
|
||||
OS::get_singleton()->benchmark_begin_measure("Core", "Unregister Extensions");
|
||||
|
||||
if (_is_core_extensions_registered) {
|
||||
gdextension_manager->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_CORE);
|
||||
}
|
||||
GDExtension::finalize_gdextensions();
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Core", "Unregister Extensions");
|
||||
}
|
||||
|
||||
void unregister_core_types() {
|
||||
OS::get_singleton()->benchmark_begin_measure("unregister_core_types");
|
||||
OS::get_singleton()->benchmark_begin_measure("Core", "Unregister Types");
|
||||
|
||||
// Destroy singletons in reverse order to ensure dependencies are not broken.
|
||||
|
||||
|
@ -435,5 +448,5 @@ void unregister_core_types() {
|
|||
CoreStringNames::free();
|
||||
StringName::cleanup();
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("unregister_core_types");
|
||||
OS::get_singleton()->benchmark_end_measure("Core", "Unregister Types");
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ Ref<FontVariation> make_bold_font(const Ref<Font> &p_font, double p_embolden, Ty
|
|||
}
|
||||
|
||||
void editor_register_fonts(Ref<Theme> p_theme) {
|
||||
OS::get_singleton()->benchmark_begin_measure("editor_register_fonts");
|
||||
OS::get_singleton()->benchmark_begin_measure("EditorTheme", "Register Fonts");
|
||||
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
|
||||
TextServer::FontAntialiasing font_antialiasing = (TextServer::FontAntialiasing)(int)EDITOR_GET("interface/editor/font_antialiasing");
|
||||
|
@ -445,5 +445,5 @@ void editor_register_fonts(Ref<Theme> p_theme) {
|
|||
p_theme->set_font_size("status_source_size", EditorStringName(EditorFonts), default_font_size);
|
||||
p_theme->set_font("status_source", EditorStringName(EditorFonts), mono_other_fc);
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("editor_register_fonts");
|
||||
OS::get_singleton()->benchmark_end_measure("EditorTheme", "Register Fonts");
|
||||
}
|
||||
|
|
|
@ -2360,6 +2360,7 @@ void EditorHelp::_add_text(const String &p_bbcode) {
|
|||
_add_text_to_rt(p_bbcode, class_desc, this, edited_class);
|
||||
}
|
||||
|
||||
int EditorHelp::doc_generation_count = 0;
|
||||
String EditorHelp::doc_version_hash;
|
||||
Thread EditorHelp::worker_thread;
|
||||
|
||||
|
@ -2392,6 +2393,8 @@ void EditorHelp::_load_doc_thread(void *p_udata) {
|
|||
// We have to go back to the main thread to start from scratch, bypassing any possibly existing cache.
|
||||
callable_mp_static(&EditorHelp::generate_doc).bind(false).call_deferred();
|
||||
}
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("EditorHelp", vformat("Generate Documentation (Run %d)", doc_generation_count));
|
||||
}
|
||||
|
||||
void EditorHelp::_gen_doc_thread(void *p_udata) {
|
||||
|
@ -2417,6 +2420,8 @@ void EditorHelp::_gen_doc_thread(void *p_udata) {
|
|||
if (err) {
|
||||
ERR_PRINT("Cannot save editor help cache (" + get_cache_full_path() + ").");
|
||||
}
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("EditorHelp", vformat("Generate Documentation (Run %d)", doc_generation_count));
|
||||
}
|
||||
|
||||
void EditorHelp::_gen_extensions_docs() {
|
||||
|
@ -2424,7 +2429,8 @@ void EditorHelp::_gen_extensions_docs() {
|
|||
}
|
||||
|
||||
void EditorHelp::generate_doc(bool p_use_cache) {
|
||||
OS::get_singleton()->benchmark_begin_measure("EditorHelp::generate_doc");
|
||||
doc_generation_count++;
|
||||
OS::get_singleton()->benchmark_begin_measure("EditorHelp", vformat("Generate Documentation (Run %d)", doc_generation_count));
|
||||
|
||||
// In case not the first attempt.
|
||||
_wait_for_thread();
|
||||
|
@ -2444,8 +2450,6 @@ void EditorHelp::generate_doc(bool p_use_cache) {
|
|||
doc->generate();
|
||||
worker_thread.start(_gen_doc_thread, nullptr);
|
||||
}
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("EditorHelp::generate_doc");
|
||||
}
|
||||
|
||||
void EditorHelp::_toggle_scripts_pressed() {
|
||||
|
|
|
@ -187,6 +187,7 @@ class EditorHelp : public VBoxContainer {
|
|||
String _fix_constant(const String &p_constant) const;
|
||||
void _toggle_scripts_pressed();
|
||||
|
||||
static int doc_generation_count;
|
||||
static String doc_version_hash;
|
||||
static Thread worker_thread;
|
||||
|
||||
|
|
|
@ -627,7 +627,7 @@ void EditorNode::_notification(int p_what) {
|
|||
if (requested_first_scan) {
|
||||
requested_first_scan = false;
|
||||
|
||||
OS::get_singleton()->benchmark_begin_measure("editor_scan_and_import");
|
||||
OS::get_singleton()->benchmark_begin_measure("Editor", "First Scan");
|
||||
|
||||
if (run_surface_upgrade_tool) {
|
||||
run_surface_upgrade_tool = false;
|
||||
|
@ -1041,7 +1041,7 @@ void EditorNode::_sources_changed(bool p_exist) {
|
|||
if (waiting_for_first_scan) {
|
||||
waiting_for_first_scan = false;
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("editor_scan_and_import");
|
||||
OS::get_singleton()->benchmark_end_measure("Editor", "First Scan");
|
||||
|
||||
// Reload the global shader variables, but this time
|
||||
// loading textures, as they are now properly imported.
|
||||
|
@ -1050,11 +1050,12 @@ void EditorNode::_sources_changed(bool p_exist) {
|
|||
_load_editor_layout();
|
||||
|
||||
if (!defer_load_scene.is_empty()) {
|
||||
OS::get_singleton()->benchmark_begin_measure("editor_load_scene");
|
||||
OS::get_singleton()->benchmark_begin_measure("Editor", "Load Scene");
|
||||
|
||||
load_scene(defer_load_scene);
|
||||
defer_load_scene = "";
|
||||
OS::get_singleton()->benchmark_end_measure("editor_load_scene");
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Editor", "Load Scene");
|
||||
OS::get_singleton()->benchmark_dump();
|
||||
}
|
||||
|
||||
|
@ -4665,7 +4666,7 @@ void EditorNode::_begin_first_scan() {
|
|||
// In headless mode, scan right away.
|
||||
// This allows users to continue using `godot --headless --editor --quit` to prepare a project.
|
||||
if (!DisplayServer::get_singleton()->window_can_draw()) {
|
||||
OS::get_singleton()->benchmark_begin_measure("editor_scan_and_import");
|
||||
OS::get_singleton()->benchmark_begin_measure("Editor", "First Scan");
|
||||
EditorFileSystem::get_singleton()->scan();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -403,7 +403,9 @@ float get_gizmo_handle_scale(const String &gizmo_handle_name = "") {
|
|||
}
|
||||
|
||||
void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme, float p_icon_saturation, int p_thumb_size, bool p_only_thumbs = false) {
|
||||
OS::get_singleton()->benchmark_begin_measure("editor_register_and_generate_icons_" + String((p_only_thumbs ? "with_only_thumbs" : "all")));
|
||||
const String benchmark_key = vformat("Generate Icons (%s)", (p_only_thumbs ? "Only Thumbs" : "All"));
|
||||
OS::get_singleton()->benchmark_begin_measure("EditorTheme", benchmark_key);
|
||||
|
||||
// Before we register the icons, we adjust their colors and saturation.
|
||||
// Most icons follow the standard rules for color conversion to follow the editor
|
||||
// theme's polarity (dark/light). We also adjust the saturation for most icons,
|
||||
|
@ -531,11 +533,11 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme, f
|
|||
p_theme->set_icon(editor_icons_names[index], EditorStringName(EditorIcons), icon);
|
||||
}
|
||||
}
|
||||
OS::get_singleton()->benchmark_end_measure("editor_register_and_generate_icons_" + String((p_only_thumbs ? "with_only_thumbs" : "all")));
|
||||
OS::get_singleton()->benchmark_end_measure("EditorTheme", benchmark_key);
|
||||
}
|
||||
|
||||
Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
|
||||
OS::get_singleton()->benchmark_begin_measure("create_editor_theme");
|
||||
OS::get_singleton()->benchmark_begin_measure("EditorTheme", "Create Editor Theme");
|
||||
Ref<EditorTheme> theme = memnew(EditorTheme);
|
||||
|
||||
// Controls may rely on the scale for their internal drawing logic.
|
||||
|
@ -2360,15 +2362,16 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
|
|||
theme->set_color("search_result_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_color"));
|
||||
theme->set_color("search_result_border_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_border_color"));
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("create_editor_theme");
|
||||
OS::get_singleton()->benchmark_end_measure("EditorTheme", "Create Editor Theme");
|
||||
|
||||
return theme;
|
||||
}
|
||||
|
||||
Ref<Theme> create_custom_theme(const Ref<Theme> p_theme) {
|
||||
OS::get_singleton()->benchmark_begin_measure("create_custom_theme");
|
||||
Ref<Theme> theme = create_editor_theme(p_theme);
|
||||
|
||||
OS::get_singleton()->benchmark_begin_measure("EditorTheme", "Create Custom Theme");
|
||||
|
||||
const String custom_theme_path = EDITOR_GET("interface/theme/custom_theme");
|
||||
if (!custom_theme_path.is_empty()) {
|
||||
Ref<Theme> custom_theme = ResourceLoader::load(custom_theme_path);
|
||||
|
@ -2377,7 +2380,7 @@ Ref<Theme> create_custom_theme(const Ref<Theme> p_theme) {
|
|||
}
|
||||
}
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("create_custom_theme");
|
||||
OS::get_singleton()->benchmark_end_measure("EditorTheme", "Create Custom Theme");
|
||||
return theme;
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@
|
|||
#include "editor/register_exporters.h"
|
||||
|
||||
void register_editor_types() {
|
||||
OS::get_singleton()->benchmark_begin_measure("register_editor_types");
|
||||
OS::get_singleton()->benchmark_begin_measure("Editor", "Register Types");
|
||||
|
||||
ResourceLoader::set_timestamp_on_load(true);
|
||||
ResourceSaver::set_timestamp_on_save(true);
|
||||
|
@ -282,11 +282,11 @@ void register_editor_types() {
|
|||
ei_singleton.editor_only = true;
|
||||
Engine::get_singleton()->add_singleton(ei_singleton);
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("register_editor_types");
|
||||
OS::get_singleton()->benchmark_end_measure("Editor", "Register Types");
|
||||
}
|
||||
|
||||
void unregister_editor_types() {
|
||||
OS::get_singleton()->benchmark_begin_measure("unregister_editor_types");
|
||||
OS::get_singleton()->benchmark_begin_measure("Editor", "Unregister Types");
|
||||
|
||||
EditorNode::cleanup();
|
||||
EditorInterface::free();
|
||||
|
@ -296,5 +296,5 @@ void unregister_editor_types() {
|
|||
}
|
||||
EditorStringNames::free();
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("unregister_editor_types");
|
||||
OS::get_singleton()->benchmark_end_measure("Editor", "Unregister Types");
|
||||
}
|
||||
|
|
|
@ -765,12 +765,12 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
|
|||
|
||||
// Benchmark tracking must be done after `OS::get_singleton()->initialize()` as on some
|
||||
// platforms, it's used to set up the time utilities.
|
||||
OS::get_singleton()->benchmark_begin_measure("startup_begin");
|
||||
OS::get_singleton()->benchmark_begin_measure("Startup", "Total");
|
||||
|
||||
engine = memnew(Engine);
|
||||
|
||||
MAIN_PRINT("Main: Initialize CORE");
|
||||
OS::get_singleton()->benchmark_begin_measure("core");
|
||||
OS::get_singleton()->benchmark_begin_measure("Startup", "Core");
|
||||
|
||||
register_core_types();
|
||||
register_core_driver_types();
|
||||
|
@ -2179,11 +2179,12 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
|
|||
Thread::release_main_thread(); // If setup2() is called from another thread, that one will become main thread, so preventively release this one.
|
||||
set_current_thread_safe_for_nodes(false);
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Startup", "Core");
|
||||
|
||||
if (p_second_phase) {
|
||||
return setup2();
|
||||
}
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("core");
|
||||
return OK;
|
||||
|
||||
error:
|
||||
|
@ -2237,7 +2238,7 @@ error:
|
|||
memdelete(message_queue);
|
||||
}
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("core");
|
||||
OS::get_singleton()->benchmark_end_measure("Startup", "Core");
|
||||
|
||||
OS::get_singleton()->finalize_core();
|
||||
locale = String();
|
||||
|
@ -2271,7 +2272,7 @@ Error Main::setup2() {
|
|||
// Print engine name and version
|
||||
print_line(String(VERSION_NAME) + " v" + get_full_version_string() + " - " + String(VERSION_WEBSITE));
|
||||
|
||||
OS::get_singleton()->benchmark_begin_measure("servers");
|
||||
OS::get_singleton()->benchmark_begin_measure("Startup", "Servers");
|
||||
|
||||
tsman = memnew(TextServerManager);
|
||||
|
||||
|
@ -2675,11 +2676,11 @@ Error Main::setup2() {
|
|||
ERR_FAIL_V_MSG(ERR_CANT_CREATE, "TextServer: Unable to create TextServer interface.");
|
||||
}
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("servers");
|
||||
OS::get_singleton()->benchmark_end_measure("Startup", "Servers");
|
||||
|
||||
MAIN_PRINT("Main: Load Scene Types");
|
||||
|
||||
OS::get_singleton()->benchmark_begin_measure("scene");
|
||||
OS::get_singleton()->benchmark_begin_measure("Startup", "Scene");
|
||||
|
||||
// Initialize ThemeDB early so that scene types can register their theme items.
|
||||
// Default theme will be initialized later, after modules and ScriptServer are ready.
|
||||
|
@ -2765,7 +2766,7 @@ Error Main::setup2() {
|
|||
print_verbose("EDITOR API HASH: " + uitos(ClassDB::get_api_hash(ClassDB::API_EDITOR)));
|
||||
MAIN_PRINT("Main: Done");
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("scene");
|
||||
OS::get_singleton()->benchmark_end_measure("Startup", "Scene");
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
@ -3169,7 +3170,7 @@ bool Main::start() {
|
|||
if (!project_manager && !editor) { // game
|
||||
if (!game_path.is_empty() || !script.is_empty()) {
|
||||
//autoload
|
||||
OS::get_singleton()->benchmark_begin_measure("load_autoloads");
|
||||
OS::get_singleton()->benchmark_begin_measure("Startup", "Load Autoloads");
|
||||
HashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
||||
|
||||
//first pass, add the constants so they exist before any script is loaded
|
||||
|
@ -3234,7 +3235,7 @@ bool Main::start() {
|
|||
for (Node *E : to_add) {
|
||||
sml->get_root()->add_child(E);
|
||||
}
|
||||
OS::get_singleton()->benchmark_end_measure("load_autoloads");
|
||||
OS::get_singleton()->benchmark_end_measure("Startup", "Load Autoloads");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3273,7 +3274,7 @@ bool Main::start() {
|
|||
|
||||
EditorNode *editor_node = nullptr;
|
||||
if (editor) {
|
||||
OS::get_singleton()->benchmark_begin_measure("editor");
|
||||
OS::get_singleton()->benchmark_begin_measure("Startup", "Editor");
|
||||
editor_node = memnew(EditorNode);
|
||||
sml->get_root()->add_child(editor_node);
|
||||
|
||||
|
@ -3282,7 +3283,7 @@ bool Main::start() {
|
|||
game_path = ""; // Do not load anything.
|
||||
}
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("editor");
|
||||
OS::get_singleton()->benchmark_end_measure("Startup", "Editor");
|
||||
}
|
||||
#endif
|
||||
sml->set_auto_accept_quit(GLOBAL_GET("application/config/auto_accept_quit"));
|
||||
|
@ -3420,7 +3421,7 @@ bool Main::start() {
|
|||
|
||||
if (!project_manager && !editor) { // game
|
||||
|
||||
OS::get_singleton()->benchmark_begin_measure("game_load");
|
||||
OS::get_singleton()->benchmark_begin_measure("Startup", "Load Game");
|
||||
|
||||
// Load SSL Certificates from Project Settings (or builtin).
|
||||
Crypto::load_default_certificates(GLOBAL_GET("network/tls/certificate_bundle_override"));
|
||||
|
@ -3462,19 +3463,19 @@ bool Main::start() {
|
|||
}
|
||||
}
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("game_load");
|
||||
OS::get_singleton()->benchmark_end_measure("Startup", "Load Game");
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (project_manager) {
|
||||
OS::get_singleton()->benchmark_begin_measure("project_manager");
|
||||
OS::get_singleton()->benchmark_begin_measure("Startup", "Project Manager");
|
||||
Engine::get_singleton()->set_editor_hint(true);
|
||||
ProjectManager *pmanager = memnew(ProjectManager);
|
||||
ProgressDialog *progress_dialog = memnew(ProgressDialog);
|
||||
pmanager->add_child(progress_dialog);
|
||||
sml->get_root()->add_child(pmanager);
|
||||
DisplayServer::get_singleton()->set_context(DisplayServer::CONTEXT_PROJECTMAN);
|
||||
OS::get_singleton()->benchmark_end_measure("project_manager");
|
||||
OS::get_singleton()->benchmark_end_measure("Startup", "Project Manager");
|
||||
}
|
||||
|
||||
if (project_manager || editor) {
|
||||
|
@ -3502,7 +3503,7 @@ bool Main::start() {
|
|||
}
|
||||
}
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("startup_begin");
|
||||
OS::get_singleton()->benchmark_end_measure("Startup", "Total");
|
||||
OS::get_singleton()->benchmark_dump();
|
||||
|
||||
return true;
|
||||
|
@ -3751,7 +3752,7 @@ void Main::force_redraw() {
|
|||
* The order matters as some of those steps are linked with each other.
|
||||
*/
|
||||
void Main::cleanup(bool p_force) {
|
||||
OS::get_singleton()->benchmark_begin_measure("Main::cleanup");
|
||||
OS::get_singleton()->benchmark_begin_measure("Shutdown", "Total");
|
||||
if (!p_force) {
|
||||
ERR_FAIL_COND(!_start_success);
|
||||
}
|
||||
|
@ -3892,7 +3893,7 @@ void Main::cleanup(bool p_force) {
|
|||
uninitialize_modules(MODULE_INITIALIZATION_LEVEL_CORE);
|
||||
unregister_core_types();
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Main::cleanup");
|
||||
OS::get_singleton()->benchmark_end_measure("Shutdown", "Total");
|
||||
OS::get_singleton()->benchmark_dump();
|
||||
|
||||
OS::get_singleton()->finalize_core();
|
||||
|
|
|
@ -184,7 +184,7 @@ class Godot(private val context: Context) : SensorEventListener {
|
|||
return
|
||||
}
|
||||
|
||||
beginBenchmarkMeasure("Godot::onCreate")
|
||||
beginBenchmarkMeasure("Startup", "Godot::onCreate")
|
||||
try {
|
||||
this.primaryHost = primaryHost
|
||||
val activity = requireActivity()
|
||||
|
@ -286,7 +286,7 @@ class Godot(private val context: Context) : SensorEventListener {
|
|||
initializationStarted = false
|
||||
throw e
|
||||
} finally {
|
||||
endBenchmarkMeasure("Godot::onCreate");
|
||||
endBenchmarkMeasure("Startup", "Godot::onCreate");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1016,13 +1016,13 @@ class Godot(private val context: Context) : SensorEventListener {
|
|||
}
|
||||
|
||||
@Keep
|
||||
private fun nativeBeginBenchmarkMeasure(label: String) {
|
||||
beginBenchmarkMeasure(label)
|
||||
private fun nativeBeginBenchmarkMeasure(scope: String, label: String) {
|
||||
beginBenchmarkMeasure(scope, label)
|
||||
}
|
||||
|
||||
@Keep
|
||||
private fun nativeEndBenchmarkMeasure(label: String) {
|
||||
endBenchmarkMeasure(label)
|
||||
private fun nativeEndBenchmarkMeasure(scope: String, label: String) {
|
||||
endBenchmarkMeasure(scope, label)
|
||||
}
|
||||
|
||||
@Keep
|
||||
|
|
|
@ -172,7 +172,7 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH
|
|||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
BenchmarkUtils.beginBenchmarkMeasure("GodotFragment::onCreate");
|
||||
BenchmarkUtils.beginBenchmarkMeasure("Startup", "GodotFragment::onCreate");
|
||||
super.onCreate(icicle);
|
||||
|
||||
final Activity activity = getActivity();
|
||||
|
@ -180,7 +180,7 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH
|
|||
|
||||
godot = new Godot(requireContext());
|
||||
performEngineInitialization();
|
||||
BenchmarkUtils.endBenchmarkMeasure("GodotFragment::onCreate");
|
||||
BenchmarkUtils.endBenchmarkMeasure("Startup", "GodotFragment::onCreate");
|
||||
}
|
||||
|
||||
private void performEngineInitialization() {
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.godotengine.godot.io.file.FileAccessFlags
|
|||
import org.godotengine.godot.io.file.FileAccessHandler
|
||||
import org.json.JSONObject
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.concurrent.ConcurrentSkipListMap
|
||||
import java.util.Collections
|
||||
|
||||
/**
|
||||
* Contains benchmark related utilities methods
|
||||
|
@ -51,44 +51,47 @@ private const val TAG = "GodotBenchmark"
|
|||
var useBenchmark = false
|
||||
var benchmarkFile = ""
|
||||
|
||||
private val startBenchmarkFrom = ConcurrentSkipListMap<String, Long>()
|
||||
private val benchmarkTracker = ConcurrentSkipListMap<String, Double>()
|
||||
private val startBenchmarkFrom = Collections.synchronizedMap(LinkedHashMap<Pair<String, String>, Long>())
|
||||
private val benchmarkTracker = Collections.synchronizedMap(LinkedHashMap<Pair<String, String>, Double>())
|
||||
|
||||
/**
|
||||
* Start measuring and tracing the execution of a given section of code using the given label.
|
||||
* Start measuring and tracing the execution of a given section of code using the given label
|
||||
* within the given scope.
|
||||
*
|
||||
* Must be followed by a call to [endBenchmarkMeasure].
|
||||
*
|
||||
* Note: Only enabled on 'editorDev' build variant.
|
||||
*/
|
||||
fun beginBenchmarkMeasure(label: String) {
|
||||
fun beginBenchmarkMeasure(scope: String, label: String) {
|
||||
if (BuildConfig.FLAVOR != "editor" || BuildConfig.BUILD_TYPE != "dev") {
|
||||
return
|
||||
}
|
||||
startBenchmarkFrom[label] = SystemClock.elapsedRealtime()
|
||||
val key = Pair(scope, label)
|
||||
startBenchmarkFrom[key] = SystemClock.elapsedRealtime()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
Trace.beginAsyncSection(label, 0)
|
||||
Trace.beginAsyncSection("[$scope] $label", 0)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* End measuring and tracing of the section of code with the given label.
|
||||
* End measuring and tracing of the section of code with the given label within the given scope.
|
||||
*
|
||||
* Must be preceded by a call [beginBenchmarkMeasure]
|
||||
*
|
||||
* * Note: Only enabled on 'editorDev' build variant.
|
||||
*/
|
||||
fun endBenchmarkMeasure(label: String) {
|
||||
fun endBenchmarkMeasure(scope: String, label: String) {
|
||||
if (BuildConfig.FLAVOR != "editor" || BuildConfig.BUILD_TYPE != "dev") {
|
||||
return
|
||||
}
|
||||
val startTime = startBenchmarkFrom[label] ?: return
|
||||
val key = Pair(scope, label)
|
||||
val startTime = startBenchmarkFrom[key] ?: return
|
||||
val total = SystemClock.elapsedRealtime() - startTime
|
||||
benchmarkTracker[label] = total / 1000.0
|
||||
benchmarkTracker[key] = total / 1_000.0
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
Trace.endAsyncSection(label, 0)
|
||||
Trace.endAsyncSection("[$scope] $label", 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,8 +110,16 @@ fun dumpBenchmark(fileAccessHandler: FileAccessHandler?, filepath: String? = ben
|
|||
return
|
||||
}
|
||||
|
||||
val results = LinkedHashMap<String, String>()
|
||||
for (entry in benchmarkTracker) {
|
||||
if (!results.containsKey(entry.key.first)) {
|
||||
results[entry.key.first] = ""
|
||||
}
|
||||
results[entry.key.first] += "\t\t- ${entry.key.second}: ${entry.value * 1_000.0} msec.\n"
|
||||
}
|
||||
|
||||
val printOut =
|
||||
benchmarkTracker.map { "\t- ${it.key} : ${it.value} sec." }.joinToString("\n")
|
||||
results.map { "\t- [${it.key}]\n ${it.value}" }.joinToString("\n")
|
||||
Log.i(TAG, "BENCHMARK:\n$printOut")
|
||||
|
||||
if (fileAccessHandler != null && !filepath.isNullOrBlank()) {
|
||||
|
|
|
@ -78,8 +78,8 @@ GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_
|
|||
_on_godot_main_loop_started = p_env->GetMethodID(godot_class, "onGodotMainLoopStarted", "()V");
|
||||
_create_new_godot_instance = p_env->GetMethodID(godot_class, "createNewGodotInstance", "([Ljava/lang/String;)I");
|
||||
_get_render_view = p_env->GetMethodID(godot_class, "getRenderView", "()Lorg/godotengine/godot/GodotRenderView;");
|
||||
_begin_benchmark_measure = p_env->GetMethodID(godot_class, "nativeBeginBenchmarkMeasure", "(Ljava/lang/String;)V");
|
||||
_end_benchmark_measure = p_env->GetMethodID(godot_class, "nativeEndBenchmarkMeasure", "(Ljava/lang/String;)V");
|
||||
_begin_benchmark_measure = p_env->GetMethodID(godot_class, "nativeBeginBenchmarkMeasure", "(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
_end_benchmark_measure = p_env->GetMethodID(godot_class, "nativeEndBenchmarkMeasure", "(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
_dump_benchmark = p_env->GetMethodID(godot_class, "nativeDumpBenchmark", "(Ljava/lang/String;)V");
|
||||
_get_gdextension_list_config_file = p_env->GetMethodID(godot_class, "getGDExtensionConfigFiles", "()[Ljava/lang/String;");
|
||||
_has_feature = p_env->GetMethodID(godot_class, "hasFeature", "(Ljava/lang/String;)Z");
|
||||
|
@ -348,21 +348,23 @@ int GodotJavaWrapper::create_new_godot_instance(List<String> args) {
|
|||
}
|
||||
}
|
||||
|
||||
void GodotJavaWrapper::begin_benchmark_measure(const String &p_label) {
|
||||
void GodotJavaWrapper::begin_benchmark_measure(const String &p_context, const String &p_label) {
|
||||
if (_begin_benchmark_measure) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_NULL(env);
|
||||
jstring j_context = env->NewStringUTF(p_context.utf8().get_data());
|
||||
jstring j_label = env->NewStringUTF(p_label.utf8().get_data());
|
||||
env->CallVoidMethod(godot_instance, _begin_benchmark_measure, j_label);
|
||||
env->CallVoidMethod(godot_instance, _begin_benchmark_measure, j_context, j_label);
|
||||
}
|
||||
}
|
||||
|
||||
void GodotJavaWrapper::end_benchmark_measure(const String &p_label) {
|
||||
void GodotJavaWrapper::end_benchmark_measure(const String &p_context, const String &p_label) {
|
||||
if (_end_benchmark_measure) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_NULL(env);
|
||||
jstring j_context = env->NewStringUTF(p_context.utf8().get_data());
|
||||
jstring j_label = env->NewStringUTF(p_label.utf8().get_data());
|
||||
env->CallVoidMethod(godot_instance, _end_benchmark_measure, j_label);
|
||||
env->CallVoidMethod(godot_instance, _end_benchmark_measure, j_context, j_label);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -105,8 +105,8 @@ public:
|
|||
void vibrate(int p_duration_ms);
|
||||
String get_input_fallback_mapping();
|
||||
int create_new_godot_instance(List<String> args);
|
||||
void begin_benchmark_measure(const String &p_label);
|
||||
void end_benchmark_measure(const String &p_label);
|
||||
void begin_benchmark_measure(const String &p_context, const String &p_label);
|
||||
void end_benchmark_measure(const String &p_context, const String &p_label);
|
||||
void dump_benchmark(const String &benchmark_file);
|
||||
|
||||
// Return the list of gdextensions config file.
|
||||
|
|
|
@ -708,15 +708,15 @@ String OS_Android::get_config_path() const {
|
|||
return get_user_data_dir().path_join("config");
|
||||
}
|
||||
|
||||
void OS_Android::benchmark_begin_measure(const String &p_what) {
|
||||
void OS_Android::benchmark_begin_measure(const String &p_context, const String &p_what) {
|
||||
#ifdef TOOLS_ENABLED
|
||||
godot_java->begin_benchmark_measure(p_what);
|
||||
godot_java->begin_benchmark_measure(p_context, p_what);
|
||||
#endif
|
||||
}
|
||||
|
||||
void OS_Android::benchmark_end_measure(const String &p_what) {
|
||||
void OS_Android::benchmark_end_measure(const String &p_context, const String &p_what) {
|
||||
#ifdef TOOLS_ENABLED
|
||||
godot_java->end_benchmark_measure(p_what);
|
||||
godot_java->end_benchmark_measure(p_context, p_what);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -165,8 +165,8 @@ public:
|
|||
|
||||
virtual Error setup_remote_filesystem(const String &p_server_host, int p_port, const String &p_password, String &r_project_path) override;
|
||||
|
||||
virtual void benchmark_begin_measure(const String &p_what) override;
|
||||
virtual void benchmark_end_measure(const String &p_what) override;
|
||||
virtual void benchmark_begin_measure(const String &p_context, const String &p_what) override;
|
||||
virtual void benchmark_end_measure(const String &p_context, const String &p_what) override;
|
||||
virtual void benchmark_dump() override;
|
||||
|
||||
virtual void load_platform_gdextensions() const override;
|
||||
|
|
|
@ -293,6 +293,8 @@ static Ref<ResourceFormatSaverShaderInclude> resource_saver_shader_include;
|
|||
static Ref<ResourceFormatLoaderShaderInclude> resource_loader_shader_include;
|
||||
|
||||
void register_scene_types() {
|
||||
OS::get_singleton()->benchmark_begin_measure("Scene", "Register Types");
|
||||
|
||||
SceneStringNames::create();
|
||||
|
||||
OS::get_singleton()->yield(); // may take time to init
|
||||
|
@ -1182,9 +1184,13 @@ void register_scene_types() {
|
|||
}
|
||||
|
||||
SceneDebugger::initialize();
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Scene", "Register Types");
|
||||
}
|
||||
|
||||
void unregister_scene_types() {
|
||||
OS::get_singleton()->benchmark_begin_measure("Scene", "Unregister Types");
|
||||
|
||||
SceneDebugger::deinitialize();
|
||||
|
||||
ResourceLoader::remove_resource_format_loader(resource_loader_texture_layered);
|
||||
|
@ -1227,10 +1233,16 @@ void unregister_scene_types() {
|
|||
CanvasItemMaterial::finish_shaders();
|
||||
ColorPicker::finish_shaders();
|
||||
SceneStringNames::free();
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Scene", "Unregister Types");
|
||||
}
|
||||
|
||||
void register_scene_singletons() {
|
||||
OS::get_singleton()->benchmark_begin_measure("Scene", "Register Singletons");
|
||||
|
||||
GDREGISTER_CLASS(ThemeDB);
|
||||
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton("ThemeDB", ThemeDB::get_singleton()));
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Scene", "Register Singletons");
|
||||
}
|
||||
|
|
|
@ -117,6 +117,8 @@ static MovieWriterMJPEG *writer_mjpeg = nullptr;
|
|||
static MovieWriterPNGWAV *writer_pngwav = nullptr;
|
||||
|
||||
void register_server_types() {
|
||||
OS::get_singleton()->benchmark_begin_measure("Servers", "Register Extensions");
|
||||
|
||||
shader_types = memnew(ShaderTypes);
|
||||
|
||||
GDREGISTER_CLASS(TextServerManager);
|
||||
|
@ -293,16 +295,24 @@ void register_server_types() {
|
|||
|
||||
writer_pngwav = memnew(MovieWriterPNGWAV);
|
||||
MovieWriter::add_writer(writer_pngwav);
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Servers", "Register Extensions");
|
||||
}
|
||||
|
||||
void unregister_server_types() {
|
||||
OS::get_singleton()->benchmark_begin_measure("Servers", "Unregister Extensions");
|
||||
|
||||
ServersDebugger::deinitialize();
|
||||
memdelete(shader_types);
|
||||
memdelete(writer_mjpeg);
|
||||
memdelete(writer_pngwav);
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Servers", "Unregister Extensions");
|
||||
}
|
||||
|
||||
void register_server_singletons() {
|
||||
OS::get_singleton()->benchmark_begin_measure("Servers", "Register Singletons");
|
||||
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton("DisplayServer", DisplayServer::get_singleton(), "DisplayServer"));
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton("RenderingServer", RenderingServer::get_singleton(), "RenderingServer"));
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton(), "AudioServer"));
|
||||
|
@ -312,4 +322,6 @@ void register_server_singletons() {
|
|||
Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton(), "NavigationServer3D"));
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton("XRServer", XRServer::get_singleton(), "XRServer"));
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton(), "CameraServer"));
|
||||
|
||||
OS::get_singleton()->benchmark_end_measure("Servers", "Register Singletons");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue