diff options
Diffstat (limited to 'core/config')
-rw-r--r-- | core/config/engine.cpp | 39 | ||||
-rw-r--r-- | core/config/engine.h | 10 |
2 files changed, 49 insertions, 0 deletions
diff --git a/core/config/engine.cpp b/core/config/engine.cpp index e1da9eb44e..6606557fce 100644 --- a/core/config/engine.cpp +++ b/core/config/engine.cpp @@ -33,7 +33,9 @@ #include "core/authors.gen.h" #include "core/config/project_settings.h" #include "core/donors.gen.h" +#include "core/io/json.h" #include "core/license.gen.h" +#include "core/os/os.h" #include "core/version.h" void Engine::set_physics_ticks_per_second(int p_ips) { @@ -307,6 +309,43 @@ Engine::Engine() { singleton = this; } +void Engine::startup_begin() { + startup_benchmark_total_from = OS::get_singleton()->get_ticks_usec(); +} + +void Engine::startup_benchmark_begin_measure(const String &p_what) { + startup_benchmark_section = p_what; + startup_benchmark_from = OS::get_singleton()->get_ticks_usec(); +} +void Engine::startup_benchmark_end_measure() { + uint64_t total = OS::get_singleton()->get_ticks_usec() - startup_benchmark_from; + double total_f = double(total) / double(1000000); + + startup_benchmark_json[startup_benchmark_section] = total_f; +} + +void Engine::startup_dump(const String &p_to_file) { + uint64_t total = OS::get_singleton()->get_ticks_usec() - startup_benchmark_total_from; + double total_f = double(total) / double(1000000); + startup_benchmark_json["total_time"] = total_f; + + if (!p_to_file.is_empty()) { + Ref<FileAccess> f = FileAccess::open(p_to_file, FileAccess::WRITE); + if (f.is_valid()) { + Ref<JSON> json; + json.instantiate(); + f->store_string(json->stringify(startup_benchmark_json, "\t", false, true)); + } + } else { + List<Variant> keys; + startup_benchmark_json.get_key_list(&keys); + print_line("STARTUP BENCHMARK:"); + for (const Variant &K : keys) { + print_line("\t-", K, ": ", startup_benchmark_json[K], +" sec."); + } + } +} + Engine::Singleton::Singleton(const StringName &p_name, Object *p_ptr, const StringName &p_class_name) : name(p_name), ptr(p_ptr), diff --git a/core/config/engine.h b/core/config/engine.h index 649be23717..b4364dbda4 100644 --- a/core/config/engine.h +++ b/core/config/engine.h @@ -79,6 +79,11 @@ private: String write_movie_path; String shader_cache_path; + Dictionary startup_benchmark_json; + String startup_benchmark_section; + uint64_t startup_benchmark_from = 0; + uint64_t startup_benchmark_total_from = 0; + public: static Engine *get_singleton(); @@ -151,6 +156,11 @@ public: bool is_validation_layers_enabled() const; int32_t get_gpu_index() const; + void startup_begin(); + void startup_benchmark_begin_measure(const String &p_what); + void startup_benchmark_end_measure(); + void startup_dump(const String &p_to_file); + Engine(); virtual ~Engine() {} }; |