50
50
#include " core/object/script_language.h"
51
51
#include " core/os/os.h"
52
52
#include " core/os/time.h"
53
+ #include " core/profiling.h"
53
54
#include " core/register_core_types.h"
54
55
#include " core/string/translation_server.h"
55
56
#include " core/version.h"
@@ -957,6 +958,7 @@ int Main::test_entrypoint(int argc, char *argv[], bool &tests_need_run) {
957
958
*/
958
959
959
960
Error Main::setup (const char *execpath, int argc, char *argv[], bool p_second_phase) {
961
+ GodotProfileZone (" setup" );
960
962
Thread::make_main_thread ();
961
963
set_current_thread_safe_for_nodes (true );
962
964
@@ -2882,6 +2884,7 @@ Error _parse_resource_dummy(void *p_data, VariantParser::Stream *p_stream, Ref<R
2882
2884
}
2883
2885
2884
2886
Error Main::setup2 (bool p_show_boot_logo) {
2887
+ GodotProfileZone (" setup2" );
2885
2888
OS::get_singleton ()->benchmark_begin_measure (" Startup" , " Main::Setup2" );
2886
2889
2887
2890
Thread::make_main_thread (); // Make whatever thread call this the main thread.
@@ -3693,6 +3696,7 @@ Error Main::setup2(bool p_show_boot_logo) {
3693
3696
}
3694
3697
3695
3698
void Main::setup_boot_logo () {
3699
+ GodotProfileZone (" setup_boot_logo" );
3696
3700
MAIN_PRINT (" Main: Load Boot Image" );
3697
3701
3698
3702
#if !defined(TOOLS_ENABLED) && defined(WEB_ENABLED)
@@ -3783,6 +3787,7 @@ static MainTimerSync main_timer_sync;
3783
3787
// and should move on to `OS::run`, and EXIT_FAILURE otherwise for
3784
3788
// an early exit with that error code.
3785
3789
int Main::start () {
3790
+ GodotProfileZone (" start" );
3786
3791
OS::get_singleton ()->benchmark_begin_measure (" Startup" , " Main::Start" );
3787
3792
3788
3793
ERR_FAIL_COND_V (!_start_success, false );
@@ -4601,6 +4606,8 @@ static uint64_t navigation_process_max = 0;
4601
4606
// will terminate the program. In case of failure, the OS exit code needs
4602
4607
// to be set explicitly here (defaults to EXIT_SUCCESS).
4603
4608
bool Main::iteration () {
4609
+ GodotProfileZone (" Main::iteration" );
4610
+ GodotProfileZoneGroupedFirst (_profile_zone, " prepare" );
4604
4611
iterating++;
4605
4612
4606
4613
const uint64_t ticks = OS::get_singleton ()->get_ticks_usec ();
@@ -4646,6 +4653,8 @@ bool Main::iteration() {
4646
4653
#endif // XR_DISABLED
4647
4654
4648
4655
for (int iters = 0 ; iters < advance.physics_steps ; ++iters) {
4656
+ GodotProfileZone (" Physics Step" );
4657
+ GodotProfileZoneGroupedFirst (_physics_zone, " setup" );
4649
4658
if (Input::get_singleton ()->is_agile_input_event_flushing ()) {
4650
4659
Input::get_singleton ()->flush_buffered_events ();
4651
4660
}
@@ -4658,18 +4667,22 @@ bool Main::iteration() {
4658
4667
// Prepare the fixed timestep interpolated nodes BEFORE they are updated
4659
4668
// by the physics server, otherwise the current and previous transforms
4660
4669
// may be the same, and no interpolation takes place.
4670
+ GodotProfileZoneGrouped (_physics_zone, " main loop iteration prepare" );
4661
4671
OS::get_singleton ()->get_main_loop ()->iteration_prepare ();
4662
4672
4663
4673
#ifndef PHYSICS_3D_DISABLED
4674
+ GodotProfileZoneGrouped (_physics_zone, " PhysicsServer3D::sync" );
4664
4675
PhysicsServer3D::get_singleton ()->sync ();
4665
4676
PhysicsServer3D::get_singleton ()->flush_queries ();
4666
4677
#endif // PHYSICS_3D_DISABLED
4667
4678
4668
4679
#ifndef PHYSICS_2D_DISABLED
4680
+ GodotProfileZoneGrouped (_physics_zone, " PhysicsServer2D::sync" );
4669
4681
PhysicsServer2D::get_singleton ()->sync ();
4670
4682
PhysicsServer2D::get_singleton ()->flush_queries ();
4671
4683
#endif // PHYSICS_2D_DISABLED
4672
4684
4685
+ GodotProfileZoneGrouped (_physics_zone, " physics_process" );
4673
4686
if (OS::get_singleton ()->get_main_loop ()->physics_process (physics_step * time_scale)) {
4674
4687
#ifndef PHYSICS_3D_DISABLED
4675
4688
PhysicsServer3D::get_singleton ()->end_sync ();
@@ -4687,9 +4700,11 @@ bool Main::iteration() {
4687
4700
uint64_t navigation_begin = OS::get_singleton ()->get_ticks_usec ();
4688
4701
4689
4702
#ifndef NAVIGATION_2D_DISABLED
4703
+ GodotProfileZoneGrouped (_profile_zone, " NavigationServer2D::physics_process" );
4690
4704
NavigationServer2D::get_singleton ()->physics_process (physics_step * time_scale);
4691
4705
#endif // NAVIGATION_2D_DISABLED
4692
4706
#ifndef NAVIGATION_3D_DISABLED
4707
+ GodotProfileZoneGrouped (_profile_zone, " NavigationServer3D::physics_process" );
4693
4708
NavigationServer3D::get_singleton ()->physics_process (physics_step * time_scale);
4694
4709
#endif // NAVIGATION_3D_DISABLED
4695
4710
@@ -4700,17 +4715,20 @@ bool Main::iteration() {
4700
4715
#endif // !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)
4701
4716
4702
4717
#ifndef PHYSICS_3D_DISABLED
4718
+ GodotProfileZoneGrouped (_profile_zone, " 3D physics" );
4703
4719
PhysicsServer3D::get_singleton ()->end_sync ();
4704
4720
PhysicsServer3D::get_singleton ()->step (physics_step * time_scale);
4705
4721
#endif // PHYSICS_3D_DISABLED
4706
4722
4707
4723
#ifndef PHYSICS_2D_DISABLED
4724
+ GodotProfileZoneGrouped (_profile_zone, " 2D physics" );
4708
4725
PhysicsServer2D::get_singleton ()->end_sync ();
4709
4726
PhysicsServer2D::get_singleton ()->step (physics_step * time_scale);
4710
4727
#endif // PHYSICS_2D_DISABLED
4711
4728
4712
4729
message_queue->flush ();
4713
4730
4731
+ GodotProfileZoneGrouped (_profile_zone, " main loop iteration end" );
4714
4732
OS::get_singleton ()->get_main_loop ()->iteration_end ();
4715
4733
4716
4734
physics_process_ticks = MAX (physics_process_ticks, OS::get_singleton ()->get_ticks_usec () - physics_begin); // keep the largest one for reference
@@ -4725,20 +4743,25 @@ bool Main::iteration() {
4725
4743
4726
4744
uint64_t process_begin = OS::get_singleton ()->get_ticks_usec ();
4727
4745
4746
+ GodotProfileZoneGrouped (_profile_zone, " process" );
4728
4747
if (OS::get_singleton ()->get_main_loop ()->process (process_step * time_scale)) {
4729
4748
exit = true ;
4730
4749
}
4731
4750
message_queue->flush ();
4732
4751
4733
4752
#ifndef NAVIGATION_2D_DISABLED
4753
+ GodotProfileZoneGrouped (_profile_zone, " process 2D navigation" );
4734
4754
NavigationServer2D::get_singleton ()->process (process_step * time_scale);
4735
4755
#endif // NAVIGATION_2D_DISABLED
4736
4756
#ifndef NAVIGATION_3D_DISABLED
4757
+ GodotProfileZoneGrouped (_profile_zone, " process 3D navigation" );
4737
4758
NavigationServer3D::get_singleton ()->process (process_step * time_scale);
4738
4759
#endif // NAVIGATION_3D_DISABLED
4739
4760
4761
+ GodotProfileZoneGrouped (_profile_zone, " RenderingServer::sync" );
4740
4762
RenderingServer::get_singleton ()->sync (); // sync if still drawing from previous frames.
4741
4763
4764
+ GodotProfileZoneGrouped (_profile_zone, " RenderingServer::draw" );
4742
4765
const bool has_pending_resources_for_processing = RD::get_singleton () && RD::get_singleton ()->has_pending_resources_for_processing ();
4743
4766
bool wants_present = (DisplayServer::get_singleton ()->can_any_window_draw () ||
4744
4767
DisplayServer::get_singleton ()->has_additional_outputs ()) &&
@@ -4762,10 +4785,12 @@ bool Main::iteration() {
4762
4785
process_max = MAX (process_ticks, process_max);
4763
4786
uint64_t frame_time = OS::get_singleton ()->get_ticks_usec () - ticks;
4764
4787
4788
+ GodotProfileZoneGrouped (_profile_zone, " ScriptServer::frame" );
4765
4789
for (int i = 0 ; i < ScriptServer::get_language_count (); i++) {
4766
4790
ScriptServer::get_language (i)->frame ();
4767
4791
}
4768
4792
4793
+ GodotProfileZoneGrouped (_profile_zone, " AudioServer::update" );
4769
4794
AudioServer::get_singleton ()->update ();
4770
4795
4771
4796
if (EngineDebugger::is_active ()) {
@@ -4804,6 +4829,7 @@ bool Main::iteration() {
4804
4829
iterating--;
4805
4830
4806
4831
if (movie_writer) {
4832
+ GodotProfileZoneGrouped (_profile_zone, " movie_writer->add_frame" );
4807
4833
movie_writer->add_frame ();
4808
4834
}
4809
4835
@@ -4831,6 +4857,7 @@ bool Main::iteration() {
4831
4857
bool skip_delay = scene_tree && scene_tree->is_accessibility_enabled ();
4832
4858
4833
4859
if (!skip_delay) {
4860
+ GodotProfileZoneGrouped (_profile_zone, " OS::add_frame_delay" );
4834
4861
OS::get_singleton ()->add_frame_delay (DisplayServer::get_singleton ()->window_can_draw ());
4835
4862
}
4836
4863
@@ -4871,6 +4898,7 @@ void Main::force_redraw() {
4871
4898
* The order matters as some of those steps are linked with each other.
4872
4899
*/
4873
4900
void Main::cleanup (bool p_force) {
4901
+ GodotProfileZone (" cleanup" );
4874
4902
OS::get_singleton ()->benchmark_begin_measure (" Shutdown" , " Main::Cleanup" );
4875
4903
if (!p_force) {
4876
4904
ERR_FAIL_COND (!_start_success);
0 commit comments