Skip to content

Commit 7420bee

Browse files
committed
WIP
1 parent 2dd26a0 commit 7420bee

File tree

6 files changed

+86
-28
lines changed

6 files changed

+86
-28
lines changed

core/debugger/remote_debugger.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,17 @@ class RemoteDebugger::PerformanceProfiler : public EngineProfiler {
6262
last_perf_time = pt;
6363

6464
Array custom_monitor_names = performance->call("get_custom_monitor_names");
65+
Array custom_monitor_types = performance->call("get_custom_monitor_types");
66+
67+
Array custom_monitor_data;
68+
custom_monitor_data.clear();
69+
custom_monitor_data.append_array(custom_monitor_names);
70+
custom_monitor_data.append_array(custom_monitor_types);
6571

6672
uint64_t monitor_modification_time = performance->call("get_monitor_modification_time");
6773
if (monitor_modification_time > last_monitor_modification_time) {
6874
last_monitor_modification_time = monitor_modification_time;
69-
EngineDebugger::get_singleton()->send_message("performance:profile_names", custom_monitor_names);
75+
EngineDebugger::get_singleton()->send_message("performance:profile_names", custom_monitor_data);
7076
}
7177

7278
int max = performance->get("MONITOR_MAX");

editor/debugger/editor_performance_profiler.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "editor_performance_profiler.h"
3232

33+
#include "core/variant/variant.h"
3334
#include "editor/editor_string_names.h"
3435
#include "editor/inspector/editor_property_name_processor.h"
3536
#include "editor/settings/editor_settings.h"
@@ -88,6 +89,9 @@ String EditorPerformanceProfiler::_create_label(float p_value, Performance::Moni
8889
case Performance::MONITOR_TYPE_TIME: {
8990
return TS->format_number(rtos(p_value * 1000).pad_decimals(2)) + " " + TTR("ms");
9091
}
92+
case Performance::MONITOR_TYPE_PERCENTAGE: {
93+
return TS->format_number(rtos(CLAMP(p_value, 0.0, 100.0)).pad_decimals(2)) + "%";
94+
}
9195
default: {
9296
return TS->format_number(rtos(p_value));
9397
}
@@ -317,7 +321,7 @@ void EditorPerformanceProfiler::reset() {
317321
monitor_draw->queue_redraw();
318322
}
319323

320-
void EditorPerformanceProfiler::update_monitors(const Vector<StringName> &p_names) {
324+
void EditorPerformanceProfiler::update_monitors(const Vector<StringName> &p_names, const PackedInt32Array &p_types) {
321325
HashMap<StringName, int> names;
322326
for (int i = 0; i < p_names.size(); i++) {
323327
names.insert("custom:" + p_names[i], Performance::MONITOR_MAX + i);
@@ -340,14 +344,17 @@ void EditorPerformanceProfiler::update_monitors(const Vector<StringName> &p_name
340344
}
341345
}
342346

347+
int index = 0;
343348
for (const KeyValue<StringName, int> &E : names) {
344349
String name = String(E.key).replace_first("custom:", "");
345350
String base = "Custom";
346351
if (name.get_slice_count("/") == 2) {
347352
base = name.get_slicec('/', 0);
348353
name = name.get_slicec('/', 1);
349354
}
350-
monitors.insert(E.key, Monitor(name, base, E.value, Performance::MONITOR_TYPE_QUANTITY, nullptr));
355+
Performance::MonitorType type = Performance::MonitorType(p_types[index]);
356+
monitors.insert(E.key, Monitor(name, base, E.value, type, nullptr));
357+
index++;
351358
}
352359

353360
_build_monitor_tree();

editor/debugger/editor_performance_profiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class EditorPerformanceProfiler : public HSplitContainer {
8282

8383
public:
8484
void reset();
85-
void update_monitors(const Vector<StringName> &p_names);
85+
void update_monitors(const Vector<StringName> &p_names, const PackedInt32Array &p_types);
8686
void add_profile_frame(const Vector<float> &p_values);
8787
List<float> *get_monitor_data(const StringName &p_name);
8888
EditorPerformanceProfiler();

editor/debugger/script_editor_debugger.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "core/debugger/debugger_marshalls.h"
3434
#include "core/debugger/remote_debugger.h"
3535
#include "core/string/ustring.h"
36+
#include "core/variant/variant.h"
3637
#include "core/version.h"
3738
#include "editor/debugger/editor_debugger_plugin.h"
3839
#include "editor/debugger/editor_expression_evaluator.h"
@@ -904,13 +905,24 @@ void ScriptEditorDebugger::_msg_show_selection_limit_warning(uint64_t p_thread_i
904905
}
905906

906907
void ScriptEditorDebugger::_msg_performance_profile_names(uint64_t p_thread_id, const Array &p_data) {
908+
Array name_data = p_data.slice(0, p_data.size() / 2);
909+
Array type_data = p_data.slice(p_data.size() / 2);
910+
907911
Vector<StringName> monitors;
908-
monitors.resize(p_data.size());
909-
for (int i = 0; i < p_data.size(); i++) {
910-
ERR_FAIL_COND(p_data[i].get_type() != Variant::STRING_NAME);
911-
monitors.set(i, p_data[i]);
912+
monitors.resize(name_data.size());
913+
for (int i = 0; i < name_data.size(); i++) {
914+
ERR_FAIL_COND(name_data[i].get_type() != Variant::STRING_NAME);
915+
monitors.set(i, name_data[i]);
912916
}
913-
performance_profiler->update_monitors(monitors);
917+
918+
PackedInt32Array types;
919+
types.resize(type_data.size());
920+
for (int i = 0; i < type_data.size(); i++) {
921+
ERR_FAIL_COND(type_data[i].get_type() != Variant::INT);
922+
types.set(i, type_data[i]);
923+
}
924+
925+
performance_profiler->update_monitors(monitors, types);
914926
}
915927

916928
void ScriptEditorDebugger::_msg_filesystem_update_file(uint64_t p_thread_id, const Array &p_data) {

main/performance.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
#include "performance.h"
3232

3333
#include "core/os/os.h"
34+
#include "core/string/string_name.h"
3435
#include "core/variant/typed_array.h"
36+
#include "core/variant/variant.h"
3537
#include "scene/main/node.h"
3638
#include "scene/main/scene_tree.h"
3739
#include "servers/audio_server.h"
@@ -55,12 +57,13 @@ Performance *Performance::singleton = nullptr;
5557

5658
void Performance::_bind_methods() {
5759
ClassDB::bind_method(D_METHOD("get_monitor", "monitor"), &Performance::get_monitor);
58-
ClassDB::bind_method(D_METHOD("add_custom_monitor", "id", "callable", "arguments"), &Performance::add_custom_monitor, DEFVAL(Array()));
60+
ClassDB::bind_method(D_METHOD("add_custom_monitor", "id", "callable", "arguments", "type"), &Performance::add_custom_monitor, DEFVAL(Array()), DEFVAL(MONITOR_TYPE_QUANTITY));
5961
ClassDB::bind_method(D_METHOD("remove_custom_monitor", "id"), &Performance::remove_custom_monitor);
6062
ClassDB::bind_method(D_METHOD("has_custom_monitor", "id"), &Performance::has_custom_monitor);
6163
ClassDB::bind_method(D_METHOD("get_custom_monitor", "id"), &Performance::get_custom_monitor);
6264
ClassDB::bind_method(D_METHOD("get_monitor_modification_time"), &Performance::get_monitor_modification_time);
6365
ClassDB::bind_method(D_METHOD("get_custom_monitor_names"), &Performance::get_custom_monitor_names);
66+
ClassDB::bind_method(D_METHOD("get_custom_monitor_types"), &Performance::get_custom_monitor_types);
6467

6568
BIND_ENUM_CONSTANT(TIME_FPS);
6669
BIND_ENUM_CONSTANT(TIME_PROCESS);
@@ -130,6 +133,11 @@ void Performance::_bind_methods() {
130133
BIND_ENUM_CONSTANT(NAVIGATION_3D_OBSTACLE_COUNT);
131134
#endif // NAVIGATION_3D_DISABLED
132135
BIND_ENUM_CONSTANT(MONITOR_MAX);
136+
137+
BIND_ENUM_CONSTANT(MONITOR_TYPE_QUANTITY);
138+
BIND_ENUM_CONSTANT(MONITOR_TYPE_MEMORY);
139+
BIND_ENUM_CONSTANT(MONITOR_TYPE_TIME);
140+
BIND_ENUM_CONSTANT(MONITOR_TYPE_PERCENTAGE);
133141
}
134142

135143
int Performance::_get_node_count() const {
@@ -522,9 +530,9 @@ void Performance::set_navigation_process_time(double p_pt) {
522530
_navigation_process_time = p_pt;
523531
}
524532

525-
void Performance::add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args) {
533+
void Performance::add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args, MonitorType p_type = MONITOR_TYPE_QUANTITY) {
526534
ERR_FAIL_COND_MSG(has_custom_monitor(p_id), "Custom monitor with id '" + String(p_id) + "' already exists.");
527-
_monitor_map.insert(p_id, MonitorCall(p_callable, p_args));
535+
_monitor_map.insert(p_id, MonitorCall(p_type, p_callable, p_args));
528536
_monitor_modification_time = OS::get_singleton()->get_ticks_usec();
529537
}
530538

@@ -561,6 +569,20 @@ TypedArray<StringName> Performance::get_custom_monitor_names() {
561569
return return_array;
562570
}
563571

572+
PackedInt32Array Performance::get_custom_monitor_types() {
573+
if (!_monitor_map.size()) {
574+
return PackedInt32Array();
575+
}
576+
PackedInt32Array return_array;
577+
return_array.resize(_monitor_map.size());
578+
int index = 0;
579+
for (KeyValue<StringName, MonitorCall> i : _monitor_map) {
580+
return_array.set(index, (int)i.value.get_monitor_type());
581+
index++;
582+
}
583+
return return_array;
584+
}
585+
564586
uint64_t Performance::get_monitor_modification_time() {
565587
return _monitor_modification_time;
566588
}
@@ -573,7 +595,8 @@ Performance::Performance() {
573595
singleton = this;
574596
}
575597

576-
Performance::MonitorCall::MonitorCall(Callable p_callable, Vector<Variant> p_arguments) {
598+
Performance::MonitorCall::MonitorCall(Performance::MonitorType p_type, Callable p_callable, Vector<Variant> p_arguments) {
599+
_type = p_type;
577600
_callable = p_callable;
578601
_arguments = p_arguments;
579602
}
@@ -598,3 +621,7 @@ Variant Performance::MonitorCall::call(bool &r_error, String &r_error_message) {
598621
}
599622
return return_value;
600623
}
624+
625+
Performance::MonitorType Performance::MonitorCall::get_monitor_type() {
626+
return _type;
627+
}

main/performance.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,6 @@ class Performance : public Object {
5151
double _physics_process_time;
5252
double _navigation_process_time;
5353

54-
class MonitorCall {
55-
Callable _callable;
56-
Vector<Variant> _arguments;
57-
58-
public:
59-
MonitorCall(Callable p_callable, Vector<Variant> p_arguments);
60-
MonitorCall();
61-
Variant call(bool &r_error, String &r_error_message);
62-
};
63-
64-
HashMap<StringName, MonitorCall> _monitor_map;
65-
uint64_t _monitor_modification_time;
66-
6754
public:
6855
enum Monitor {
6956
TIME_FPS,
@@ -131,7 +118,8 @@ class Performance : public Object {
131118
enum MonitorType {
132119
MONITOR_TYPE_QUANTITY,
133120
MONITOR_TYPE_MEMORY,
134-
MONITOR_TYPE_TIME
121+
MONITOR_TYPE_TIME,
122+
MONITOR_TYPE_PERCENTAGE
135123
};
136124

137125
double get_monitor(Monitor p_monitor) const;
@@ -143,17 +131,35 @@ class Performance : public Object {
143131
void set_physics_process_time(double p_pt);
144132
void set_navigation_process_time(double p_pt);
145133

146-
void add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args);
134+
void add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args, MonitorType p_type);
147135
void remove_custom_monitor(const StringName &p_id);
148136
bool has_custom_monitor(const StringName &p_id);
149137
Variant get_custom_monitor(const StringName &p_id);
150138
TypedArray<StringName> get_custom_monitor_names();
139+
PackedInt32Array get_custom_monitor_types();
151140

152141
uint64_t get_monitor_modification_time();
153142

154143
static Performance *get_singleton() { return singleton; }
155144

156145
Performance();
146+
147+
private:
148+
class MonitorCall {
149+
MonitorType _type = MONITOR_TYPE_QUANTITY;
150+
Callable _callable;
151+
Vector<Variant> _arguments;
152+
153+
public:
154+
MonitorCall(MonitorType p_type, Callable p_callable, Vector<Variant> p_arguments);
155+
MonitorCall();
156+
Variant call(bool &r_error, String &r_error_message);
157+
MonitorType get_monitor_type();
158+
};
159+
160+
HashMap<StringName, MonitorCall> _monitor_map;
161+
uint64_t _monitor_modification_time;
157162
};
158163

159164
VARIANT_ENUM_CAST(Performance::Monitor);
165+
VARIANT_ENUM_CAST(Performance::MonitorType);

0 commit comments

Comments
 (0)