mirror of
https://github.com/godotengine/godot-benchmarks.git
synced 2026-01-05 10:10:08 +03:00
Merge pull request #16 from Calinou/add-save-json-to-file
This commit is contained in:
@@ -25,6 +25,8 @@ you can run benchmarks from an editor or export template binary. The project wil
|
||||
automatically quit after running benchmarks.
|
||||
|
||||
The results JSON is printed to standard output once all benchmarks are run.
|
||||
You can save the results JSON to a file using `--save-json="path/to/file.json"`
|
||||
(the target folder **must** exist).
|
||||
|
||||
> **Note**
|
||||
>
|
||||
|
||||
17
main.gd
17
main.gd
@@ -10,7 +10,7 @@ var exclude_benchmarks_glob := ""
|
||||
func _ready() -> void:
|
||||
# Use a fixed random seed to improve reproducibility of results.
|
||||
seed(0x60d07)
|
||||
|
||||
|
||||
# No point in copying JSON without any results yet.
|
||||
$CopyJSON.visible = false
|
||||
|
||||
@@ -69,18 +69,25 @@ func _ready() -> void:
|
||||
for argument in OS.get_cmdline_user_args():
|
||||
if argument.begins_with("--include-benchmarks="):
|
||||
var key_value := argument.split("=")
|
||||
# Remove quotes around the argument's value, so that "`rendering/culling/*`"
|
||||
# Remove quotes around the argument's value, so that `"rendering/culling/*"`
|
||||
# becomes `rendering/culling/*` for globbing.
|
||||
include_benchmarks_glob = key_value[1].trim_prefix('"').trim_suffix('"').trim_prefix("'").trim_suffix("'")
|
||||
print("Using benchmark include glob specified on command line: %s" % include_benchmarks_glob)
|
||||
|
||||
if argument.begins_with("--exclude-benchmarks="):
|
||||
var key_value := argument.split("=")
|
||||
# Remove quotes around the argument's value, so that "`rendering/culling/*`"
|
||||
# Remove quotes around the argument's value, so that `"rendering/culling/*"`
|
||||
# becomes `rendering/culling/*` for globbing.
|
||||
exclude_benchmarks_glob = key_value[1].trim_prefix('"').trim_suffix('"').trim_prefix("'").trim_suffix("'")
|
||||
print("Using benchmark exclude glob specified on command line: %s" % exclude_benchmarks_glob)
|
||||
|
||||
if argument.begins_with("--save-json="):
|
||||
var key_value := argument.split("=")
|
||||
# Remove quotes around the argument's value, so that `"example.json"`
|
||||
# becomes `example.json`.
|
||||
Manager.save_json_to_path = key_value[1].trim_prefix('"').trim_suffix('"').trim_prefix("'").trim_suffix("'")
|
||||
print("Will save results JSON to: %s" % Manager.save_json_to_path)
|
||||
|
||||
if "--run-benchmarks" in OS.get_cmdline_user_args():
|
||||
Manager.run_from_cli = true
|
||||
print("Running benchmarks as specified on command line.\n")
|
||||
@@ -110,11 +117,11 @@ func _on_Run_pressed() -> void:
|
||||
var paths := []
|
||||
for item in items:
|
||||
var path: String = item.get_meta("path").trim_prefix("res://benchmarks/").trim_suffix(".tscn")
|
||||
|
||||
|
||||
if not include_benchmarks_glob.is_empty():
|
||||
if not path.match(include_benchmarks_glob):
|
||||
item.set_checked(0, false)
|
||||
|
||||
|
||||
if not exclude_benchmarks_glob.is_empty():
|
||||
if path.match(exclude_benchmarks_glob):
|
||||
item.set_checked(0, false)
|
||||
|
||||
14
main.tscn
14
main.tscn
@@ -3,11 +3,15 @@
|
||||
[ext_resource type="Script" path="res://main.gd" id="1"]
|
||||
|
||||
[node name="Main" type="Panel"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 20.0
|
||||
offset_top = 10.0
|
||||
offset_right = 285.0
|
||||
@@ -16,6 +20,8 @@ text = "Available Benchmarks:"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="Tree" type="Tree" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 10.0
|
||||
@@ -28,6 +34,8 @@ hide_root = true
|
||||
metadata/_edit_layout_mode = 1
|
||||
|
||||
[node name="SelectAll" type="Button" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 10.0
|
||||
@@ -39,6 +47,8 @@ text = "Select All"
|
||||
metadata/_edit_layout_mode = 1
|
||||
|
||||
[node name="SelectNone" type="Button" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 184.0
|
||||
@@ -50,6 +60,8 @@ text = "Select None"
|
||||
metadata/_edit_layout_mode = 1
|
||||
|
||||
[node name="CopyJSON" type="Button" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
@@ -64,6 +76,8 @@ text = "Copy JSON to Clipboard"
|
||||
metadata/_edit_layout_mode = 1
|
||||
|
||||
[node name="Run" type="Button" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
|
||||
27
manager.gd
27
manager.gd
@@ -32,6 +32,7 @@ var test_time := 5.0
|
||||
var return_to_scene : = ""
|
||||
var skip_first := false
|
||||
var run_from_cli := false
|
||||
var save_json_to_path := ""
|
||||
|
||||
var record_render_gpu := false
|
||||
var record_render_cpu := false
|
||||
@@ -49,9 +50,9 @@ func dir_contents(path: String, contents: PackedStringArray = PackedStringArray(
|
||||
var file_name = dir.get_next()
|
||||
while file_name != "":
|
||||
if dir.current_is_dir():
|
||||
dir_contents(path.plus_file(file_name), contents)
|
||||
dir_contents(path.path_join(file_name), contents)
|
||||
elif file_name.ends_with(".tscn"):
|
||||
contents.push_back(path.plus_file(file_name))
|
||||
contents.push_back(path.path_join(file_name))
|
||||
file_name = dir.get_next()
|
||||
else:
|
||||
print("An error occurred when trying to access the path: %s" % path)
|
||||
@@ -148,7 +149,7 @@ func begin_test() -> void:
|
||||
|
||||
results = Results.new()
|
||||
set_process(true)
|
||||
get_tree().change_scene(tests[tests_queue[0]].path)
|
||||
get_tree().change_scene_to_file(tests[tests_queue[0]].path)
|
||||
|
||||
recording = true
|
||||
begin_time = Time.get_ticks_usec() * 0.001
|
||||
@@ -194,11 +195,23 @@ func end_test() -> void:
|
||||
if tests_queue.size() > 0:
|
||||
begin_test()
|
||||
else:
|
||||
get_tree().change_scene(return_to_scene)
|
||||
get_tree().change_scene_to_file(return_to_scene)
|
||||
return_to_scene = ""
|
||||
DisplayServer.window_set_title("[DONE] %d benchmarks - Godot Benchmarks" % tests_queue_initial_size)
|
||||
print_rich("[color=green][b]Done running %d benchmarks.[/b] Results JSON:[/color]\n" % tests_queue_initial_size)
|
||||
print(get_results_dict())
|
||||
|
||||
print("Results JSON:")
|
||||
print("----------------")
|
||||
print(JSON.stringify(get_results_dict()))
|
||||
print("----------------")
|
||||
|
||||
if not save_json_to_path.is_empty():
|
||||
print("Saving JSON output to: %s" % save_json_to_path)
|
||||
var file := File.new()
|
||||
file.open(save_json_to_path, File.WRITE)
|
||||
file.store_string(JSON.stringify(get_results_dict()))
|
||||
file.close()
|
||||
|
||||
if run_from_cli:
|
||||
# Automatically exit after running benchmarks for automation purposes.
|
||||
get_tree().quit()
|
||||
@@ -219,6 +232,8 @@ func get_results_dict() -> Dictionary:
|
||||
build_type = "debug" if OS.is_debug_build() else "release",
|
||||
},
|
||||
system = {
|
||||
os = OS.get_name(),
|
||||
cpu_name = OS.get_processor_name(),
|
||||
cpu_architecture = (
|
||||
"x86_64" if OS.has_feature("x86_64")
|
||||
else "arm64" if OS.has_feature("arm64")
|
||||
@@ -239,7 +254,7 @@ func get_results_dict() -> Dictionary:
|
||||
name = Manager.get_test_name(i),
|
||||
}
|
||||
|
||||
var result: Manager.Results = Manager.get_test_result(i)
|
||||
var result: Results = Manager.get_test_result(i)
|
||||
if result:
|
||||
test.results = {
|
||||
render_cpu = snapped(result.render_cpu, 0.01),
|
||||
|
||||
Reference in New Issue
Block a user