31
31
#include " performance.h"
32
32
33
33
#include " core/os/os.h"
34
+ #include " core/string/string_name.h"
34
35
#include " core/variant/typed_array.h"
36
+ #include " core/variant/variant.h"
35
37
#include " scene/main/node.h"
36
38
#include " scene/main/scene_tree.h"
37
39
#include " servers/audio_server.h"
@@ -55,12 +57,13 @@ Performance *Performance::singleton = nullptr;
55
57
56
58
void Performance::_bind_methods () {
57
59
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 ));
59
61
ClassDB::bind_method (D_METHOD (" remove_custom_monitor" , " id" ), &Performance::remove_custom_monitor);
60
62
ClassDB::bind_method (D_METHOD (" has_custom_monitor" , " id" ), &Performance::has_custom_monitor);
61
63
ClassDB::bind_method (D_METHOD (" get_custom_monitor" , " id" ), &Performance::get_custom_monitor);
62
64
ClassDB::bind_method (D_METHOD (" get_monitor_modification_time" ), &Performance::get_monitor_modification_time);
63
65
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);
64
67
65
68
BIND_ENUM_CONSTANT (TIME_FPS);
66
69
BIND_ENUM_CONSTANT (TIME_PROCESS);
@@ -130,6 +133,11 @@ void Performance::_bind_methods() {
130
133
BIND_ENUM_CONSTANT (NAVIGATION_3D_OBSTACLE_COUNT);
131
134
#endif // NAVIGATION_3D_DISABLED
132
135
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);
133
141
}
134
142
135
143
int Performance::_get_node_count () const {
@@ -522,9 +530,9 @@ void Performance::set_navigation_process_time(double p_pt) {
522
530
_navigation_process_time = p_pt;
523
531
}
524
532
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 ) {
526
534
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));
528
536
_monitor_modification_time = OS::get_singleton ()->get_ticks_usec ();
529
537
}
530
538
@@ -561,6 +569,20 @@ TypedArray<StringName> Performance::get_custom_monitor_names() {
561
569
return return_array;
562
570
}
563
571
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
+
564
586
uint64_t Performance::get_monitor_modification_time () {
565
587
return _monitor_modification_time;
566
588
}
@@ -573,7 +595,8 @@ Performance::Performance() {
573
595
singleton = this ;
574
596
}
575
597
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;
577
600
_callable = p_callable;
578
601
_arguments = p_arguments;
579
602
}
@@ -598,3 +621,7 @@ Variant Performance::MonitorCall::call(bool &r_error, String &r_error_message) {
598
621
}
599
622
return return_value;
600
623
}
624
+
625
+ Performance::MonitorType Performance::MonitorCall::get_monitor_type () {
626
+ return _type;
627
+ }
0 commit comments