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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user