diff options
Diffstat (limited to 'core/os/os.cpp')
-rw-r--r-- | core/os/os.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/core/os/os.cpp b/core/os/os.cpp index 4123a1d602..5704ef7a40 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -34,6 +34,7 @@ #include "core/input/input.h" #include "core/io/dir_access.h" #include "core/io/file_access.h" +#include "core/io/json.h" #include "core/os/midi_driver.h" #include "core/version_generated.gen.h" @@ -151,6 +152,14 @@ int OS::get_low_processor_usage_mode_sleep_usec() const { return low_processor_usage_mode_sleep_usec; } +void OS::set_delta_smoothing(bool p_enabled) { + _delta_smoothing_enabled = p_enabled; +} + +bool OS::is_delta_smoothing_enabled() const { + return _delta_smoothing_enabled; +} + String OS::get_executable_path() const { return _execpath; } @@ -581,6 +590,59 @@ OS::PreferredTextureFormat OS::get_preferred_texture_format() const { #endif } +void OS::set_use_benchmark(bool p_use_benchmark) { + use_benchmark = p_use_benchmark; +} + +bool OS::is_use_benchmark_set() { + return use_benchmark; +} + +void OS::set_benchmark_file(const String &p_benchmark_file) { + benchmark_file = p_benchmark_file; +} + +String OS::get_benchmark_file() { + return benchmark_file; +} + +void OS::benchmark_begin_measure(const String &p_what) { +#ifdef TOOLS_ENABLED + start_benchmark_from[p_what] = OS::get_singleton()->get_ticks_usec(); +#endif +} +void OS::benchmark_end_measure(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); + + startup_benchmark_json[p_what] = total_f; +#endif +} + +void OS::benchmark_dump() { +#ifdef TOOLS_ENABLED + if (!use_benchmark) { + return; + } + if (!benchmark_file.is_empty()) { + Ref<FileAccess> f = FileAccess::open(benchmark_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("BENCHMARK:"); + for (const Variant &K : keys) { + print_line("\t-", K, ": ", startup_benchmark_json[K], +" sec."); + } + } +#endif +} + OS::OS() { singleton = this; |