forked from godotengine/godot-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.gd
147 lines (117 loc) · 4.63 KB
/
main.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
extends Panel
var items := []
# Prefix variables with `arg_` to have them automatically be parsed from command line arguments
var arg_include_benchmarks := ""
var arg_exclude_benchmarks := ""
var arg_save_json := ""
var arg_json_results_prefix := ""
var arg_run_benchmarks := false
var arg_visualize := false
@onready var tree := $Tree as Tree
var categories := {}
func _ready() -> void:
# Parse valid command-line arguments of the form `--key=value` into member variables.
for argument in OS.get_cmdline_user_args():
if not argument.begins_with("--"):
print("Invalid argument: %s" % argument)
continue
var key_value := argument.substr(2).split("=", true, 1)
var var_name := "arg_" + key_value[0].replace("-", "_")
if var_name not in self:
print("Invalid argument: %s" % argument)
continue
if key_value.size() == 1:
self.set(var_name, true)
else:
# Remove quotes around the argument's value, so that `"example.json"` becomes `example.json`.
self.set(var_name, key_value[1].trim_prefix('"').trim_suffix('"').trim_prefix("'").trim_suffix("'"))
print("Variable %s set by command line to %s" % [var_name, self.get(var_name)])
Manager.visualize = arg_visualize
# No point in copying JSON without any results yet.
$CopyJSON.visible = false
tree.columns = 6
tree.set_column_titles_visible(true)
tree.set_column_title(0, "Test Name")
tree.set_column_title(1, "Render CPU")
tree.set_column_title(2, "Render GPU")
tree.set_column_title(3, "Idle")
tree.set_column_title(4, "Physics")
tree.set_column_title(5, "Main Thread Time")
var root := tree.create_item()
for test_id in Manager.get_test_ids():
var test_name := test_id.pretty_name()
var category := test_id.pretty_category()
var path := test_id.to_string()
if category not in categories:
var c := tree.create_item(root)
c.set_text(0, category)
categories[category] = c
var item := tree.create_item(categories[category])
item.set_cell_mode(0, TreeItem.CELL_MODE_CHECK)
item.set_text(0, test_name)
item.set_editable(0, true)
# Store the full scene path each TreeItem points towards (for include/exclude glob checking).
item.set_meta("test_id", test_id)
# Default to selecting the benchmarks specified by command line arguments,
# or all of them if none were given. If `--run-benchmarks` was not passed,
# then the user gets the opportunity to override command line arguments
# from the interface after the fact.
item.set_checked(0, true)
if arg_include_benchmarks:
if not path.matchn(arg_include_benchmarks):
item.set_checked(0, false)
if arg_exclude_benchmarks:
if path.matchn(arg_exclude_benchmarks):
item.set_checked(0, false)
var results := Manager.get_test_result_as_dict(test_id)
var metric_names := ["render_cpu", "render_gpu", "idle", "physics", "time"]
for i in metric_names.size():
var metric = results.get(metric_names[i])
if metric:
item.set_text(i+1, "%s ms" % str(metric))
$CopyJSON.visible = true
items.append(item)
_on_Tree_item_edited()
if arg_save_json:
Manager.save_json_to_path = arg_save_json
Manager.json_results_prefix = arg_json_results_prefix
if arg_run_benchmarks:
_on_Run_pressed()
func _on_SelectAll_pressed() -> void:
for category in categories.values():
category.collapsed = false
for item in items:
item.set_checked(0, true)
_on_Tree_item_edited()
func _on_SelectNone_pressed() -> void:
for category in categories.values():
category.collapsed = true
for item in items:
item.set_checked(0, false)
_on_Tree_item_edited()
func _on_CopyJSON_pressed() -> void:
DisplayServer.clipboard_set(JSON.stringify(Manager.get_results_dict(), "\t"))
func _on_Run_pressed() -> void:
var test_ids : Array[Manager.TestID] = []
for item in items:
if item.is_checked(0):
test_ids.push_back(item.get_meta("test_id"))
if test_ids:
print_rich("[b]Running %d benchmarks:[/b]\n\t%s\n" % [test_ids.size(), "\n\t".join(test_ids)])
var return_path := ""
# Automatically exit after running benchmarks for automation purposes.
if not arg_run_benchmarks:
return_path = get_tree().current_scene.scene_file_path
Manager.benchmark(test_ids, return_path)
else:
print_rich("[color=red][b]ERROR:[/b] No benchmarks to run.[/color]")
if arg_run_benchmarks:
print(" Double-check the syntax of the benchmarks include/exclude glob (quotes are required).")
print_rich(' Example usage: [code]godot -- --run-benchmarks --include-benchmarks="rendering/culling/*" --exclude-benchmarks="rendering/culling/basic_cull"[/code]')
get_tree().quit(1)
func _on_Tree_item_edited() -> void:
$Run.disabled = true
for item in items:
if item.is_checked(0):
$Run.disabled = false
break