diff options
Diffstat (limited to 'servers')
-rw-r--r-- | servers/physics/physics_server_sw.cpp | 42 | ||||
-rw-r--r-- | servers/physics/space_sw.cpp | 4 | ||||
-rw-r--r-- | servers/physics/space_sw.h | 16 | ||||
-rw-r--r-- | servers/physics/step_sw.cpp | 38 | ||||
-rw-r--r-- | servers/physics_2d/physics_2d_server_sw.cpp | 45 | ||||
-rw-r--r-- | servers/physics_2d/physics_2d_server_sw.h | 1 | ||||
-rw-r--r-- | servers/physics_2d/space_2d_sw.cpp | 3 | ||||
-rw-r--r-- | servers/physics_2d/space_2d_sw.h | 17 | ||||
-rw-r--r-- | servers/physics_2d/step_2d_sw.cpp | 40 | ||||
-rw-r--r-- | servers/physics_2d_server.h | 4 |
10 files changed, 204 insertions, 6 deletions
diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index 5307f1ce88..6c098a6df2 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -34,7 +34,8 @@ #include "joints/slider_joint_sw.h" #include "joints/cone_twist_joint_sw.h" #include "joints/generic_6dof_joint_sw.h" - +#include "script_language.h" +#include "os/os.h" RID PhysicsServerSW::shape_create(ShapeType p_shape) { @@ -1509,12 +1510,51 @@ void PhysicsServerSW::flush_queries() { return; doing_sync=true; + + uint64_t time_beg = OS::get_singleton()->get_ticks_usec(); + for( Set<const SpaceSW*>::Element *E=active_spaces.front();E;E=E->next()) { SpaceSW *space=(SpaceSW *)E->get(); space->call_queries(); } + + if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_profiling()) { + + uint64_t total_time[SpaceSW::ELAPSED_TIME_MAX]; + static const char* time_name[SpaceSW::ELAPSED_TIME_MAX]={ + "integrate_forces", + "generate_islands", + "setup_constraints", + "solve_constraints", + "integrate_velocities" + }; + + for(int i=0;i<SpaceSW::ELAPSED_TIME_MAX;i++) { + total_time[i]=0; + } + + for( Set<const SpaceSW*>::Element *E=active_spaces.front();E;E=E->next()) { + + for(int i=0;i<SpaceSW::ELAPSED_TIME_MAX;i++) { + total_time[i]+=E->get()->get_elapsed_time(SpaceSW::ElapsedTime(i)); + } + + } + + Array values; + values.resize(SpaceSW::ELAPSED_TIME_MAX*2); + for(int i=0;i<SpaceSW::ELAPSED_TIME_MAX;i++) { + values[i*2+0]=time_name[i]; + values[i*2+1]=USEC_TO_SEC(total_time[i]); + } + values.push_back("flush_queries"); + values.push_back(USEC_TO_SEC(OS::get_singleton()->get_ticks_usec()-time_beg)); + + ScriptDebugger::get_singleton()->add_profiling_frame_data("physics",values); + + } }; diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index 4cf7729b09..1e6f42aa02 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -736,6 +736,10 @@ SpaceSW::SpaceSW() { direct_access = memnew( PhysicsDirectSpaceStateSW ); direct_access->space=this; + + for(int i=0;i<ELAPSED_TIME_MAX;i++) + elapsed_time[i]=0; + } SpaceSW::~SpaceSW() { diff --git a/servers/physics/space_sw.h b/servers/physics/space_sw.h index 6300c206d8..3fdef7e62b 100644 --- a/servers/physics/space_sw.h +++ b/servers/physics/space_sw.h @@ -59,6 +59,20 @@ public: class SpaceSW { +public: + + enum ElapsedTime { + ELAPSED_TIME_INTEGRATE_FORCES, + ELAPSED_TIME_GENERATE_ISLANDS, + ELAPSED_TIME_SETUP_CONSTRAINTS, + ELAPSED_TIME_SOLVE_CONSTRAINTS, + ELAPSED_TIME_INTEGRATE_VELOCITIES, + ELAPSED_TIME_MAX + + }; +private: + + uint64_t elapsed_time[ELAPSED_TIME_MAX]; PhysicsDirectSpaceStateSW *direct_access; RID self; @@ -178,6 +192,8 @@ public: void set_static_global_body(RID p_body) { static_global_body=p_body; } RID get_static_global_body() { return static_global_body; } + void set_elapsed_time(ElapsedTime p_time,uint64_t p_msec) { elapsed_time[p_time]=p_msec; } + uint64_t get_elapsed_time(ElapsedTime p_time) const { return elapsed_time[p_time]; } SpaceSW(); ~SpaceSW(); diff --git a/servers/physics/step_sw.cpp b/servers/physics/step_sw.cpp index f10dadf81a..5b7ebce817 100644 --- a/servers/physics/step_sw.cpp +++ b/servers/physics/step_sw.cpp @@ -29,6 +29,8 @@ #include "step_sw.h" #include "joints_sw.h" +#include "os/os.h" + void StepSW::_populate_island(BodySW* p_body,BodySW** p_island,ConstraintSW **p_constraint_island) { p_body->set_island_step(_step); @@ -152,6 +154,10 @@ void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) { const SelfList<BodySW>::List * body_list = &p_space->get_active_body_list(); /* INTEGRATE FORCES */ + + uint64_t profile_begtime = OS::get_singleton()->get_ticks_usec(); + uint64_t profile_endtime=0; + int active_count=0; const SelfList<BodySW>*b = body_list->first(); @@ -165,6 +171,12 @@ void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) { p_space->set_active_objects(active_count); + { //profile + profile_endtime=OS::get_singleton()->get_ticks_usec(); + p_space->set_elapsed_time(SpaceSW::ELAPSED_TIME_INTEGRATE_FORCES,profile_endtime-profile_begtime); + profile_begtime=profile_endtime; + } + /* GENERATE CONSTRAINT ISLANDS */ BodySW *island_list=NULL; @@ -214,6 +226,13 @@ void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) { p_space->area_remove_from_moved_list((SelfList<AreaSW>*)aml.first()); //faster to remove here } + { //profile + profile_endtime=OS::get_singleton()->get_ticks_usec(); + p_space->set_elapsed_time(SpaceSW::ELAPSED_TIME_GENERATE_ISLANDS,profile_endtime-profile_begtime); + profile_begtime=profile_endtime; + } + + // print_line("island count: "+itos(island_count)+" active count: "+itos(active_count)); /* SETUP CONSTRAINT ISLANDS */ @@ -226,6 +245,12 @@ void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) { } } + { //profile + profile_endtime=OS::get_singleton()->get_ticks_usec(); + p_space->set_elapsed_time(SpaceSW::ELAPSED_TIME_SETUP_CONSTRAINTS,profile_endtime-profile_begtime); + profile_begtime=profile_endtime; + } + /* SOLVE CONSTRAINT ISLANDS */ { @@ -237,6 +262,13 @@ void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) { } } + + { //profile + profile_endtime=OS::get_singleton()->get_ticks_usec(); + p_space->set_elapsed_time(SpaceSW::ELAPSED_TIME_SOLVE_CONSTRAINTS,profile_endtime-profile_begtime); + profile_begtime=profile_endtime; + } + /* INTEGRATE VELOCITIES */ b = body_list->first(); @@ -257,6 +289,12 @@ void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) { } } + { //profile + profile_endtime=OS::get_singleton()->get_ticks_usec(); + p_space->set_elapsed_time(SpaceSW::ELAPSED_TIME_INTEGRATE_VELOCITIES,profile_endtime-profile_begtime); + profile_begtime=profile_endtime; + } + p_space->update(); p_space->unlock(); _step++; diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index 3796ddd961..54cd929c2f 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -31,6 +31,9 @@ #include "broad_phase_2d_hash_grid.h" #include "collision_solver_2d_sw.h" #include "globals.h" +#include "script_language.h" +#include "os/os.h" + RID Physics2DServerSW::shape_create(ShapeType p_shape) { Shape2DSW *shape=NULL; @@ -1276,6 +1279,8 @@ void Physics2DServerSW::step(float p_step) { active_objects+=E->get()->get_active_objects(); collision_pairs+=E->get()->get_collision_pairs(); } + + }; void Physics2DServerSW::sync() { @@ -1288,6 +1293,7 @@ void Physics2DServerSW::flush_queries() { if (!active) return; + uint64_t time_beg = OS::get_singleton()->get_ticks_usec(); for( Set<const Space2DSW*>::Element *E=active_spaces.front();E;E=E->next()) { @@ -1295,7 +1301,44 @@ void Physics2DServerSW::flush_queries() { space->call_queries(); } -}; + + if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_profiling()) { + + uint64_t total_time[Space2DSW::ELAPSED_TIME_MAX]; + static const char* time_name[Space2DSW::ELAPSED_TIME_MAX]={ + "integrate_forces", + "generate_islands", + "setup_constraints", + "solve_constraints", + "integrate_velocities" + }; + + for(int i=0;i<Space2DSW::ELAPSED_TIME_MAX;i++) { + total_time[i]=0; + } + + for( Set<const Space2DSW*>::Element *E=active_spaces.front();E;E=E->next()) { + + for(int i=0;i<Space2DSW::ELAPSED_TIME_MAX;i++) { + total_time[i]+=E->get()->get_elapsed_time(Space2DSW::ElapsedTime(i)); + } + + } + + Array values; + values.resize(Space2DSW::ELAPSED_TIME_MAX*2); + for(int i=0;i<Space2DSW::ELAPSED_TIME_MAX;i++) { + values[i*2+0]=time_name[i]; + values[i*2+1]=USEC_TO_SEC(total_time[i]); + } + values.push_back("flush_queries"); + values.push_back(USEC_TO_SEC(OS::get_singleton()->get_ticks_usec()-time_beg)); + + ScriptDebugger::get_singleton()->add_profiling_frame_data("physics_2d",values); + + } + +} void Physics2DServerSW::end_sync() { doing_sync=false; diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index 6415786803..d557688b91 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -55,6 +55,7 @@ friend class Physics2DDirectBodyStateSW; bool using_threads; + Step2DSW *stepper; Set<const Space2DSW*> active_spaces; diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index d83efeea9c..ddef5fc86b 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -1325,7 +1325,8 @@ Space2DSW::Space2DSW() { direct_access->space=this; - + for(int i=0;i<ELAPSED_TIME_MAX;i++) + elapsed_time[i]=0; } diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h index 5f35f224b2..f8e1f32838 100644 --- a/servers/physics_2d/space_2d_sw.h +++ b/servers/physics_2d/space_2d_sw.h @@ -60,6 +60,20 @@ public: class Space2DSW { +public: + + enum ElapsedTime { + ELAPSED_TIME_INTEGRATE_FORCES, + ELAPSED_TIME_GENERATE_ISLANDS, + ELAPSED_TIME_SETUP_CONSTRAINTS, + ELAPSED_TIME_SOLVE_CONSTRAINTS, + ELAPSED_TIME_INTEGRATE_VELOCITIES, + ELAPSED_TIME_MAX + + }; +private: + + uint64_t elapsed_time[ELAPSED_TIME_MAX]; Physics2DDirectSpaceStateSW *direct_access; RID self; @@ -182,6 +196,9 @@ public: Physics2DDirectSpaceStateSW *get_direct_state(); + void set_elapsed_time(ElapsedTime p_time,uint64_t p_msec) { elapsed_time[p_time]=p_msec; } + uint64_t get_elapsed_time(ElapsedTime p_time) const { return elapsed_time[p_time]; } + Space2DSW(); ~Space2DSW(); }; diff --git a/servers/physics_2d/step_2d_sw.cpp b/servers/physics_2d/step_2d_sw.cpp index 4f9d06ee96..4f86168c1e 100644 --- a/servers/physics_2d/step_2d_sw.cpp +++ b/servers/physics_2d/step_2d_sw.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "step_2d_sw.h" - +#include "os/os.h" void Step2DSW::_populate_island(Body2DSW* p_body,Body2DSW** p_island,Constraint2DSW **p_constraint_island) { @@ -142,6 +142,11 @@ void Step2DSW::step(Space2DSW* p_space,float p_delta,int p_iterations) { const SelfList<Body2DSW>::List * body_list = &p_space->get_active_body_list(); /* INTEGRATE FORCES */ + + uint64_t profile_begtime = OS::get_singleton()->get_ticks_usec(); + uint64_t profile_endtime=0; + + int active_count=0; const SelfList<Body2DSW>*b = body_list->first(); @@ -154,6 +159,13 @@ void Step2DSW::step(Space2DSW* p_space,float p_delta,int p_iterations) { p_space->set_active_objects(active_count); + + { //profile + profile_endtime=OS::get_singleton()->get_ticks_usec(); + p_space->set_elapsed_time(Space2DSW::ELAPSED_TIME_INTEGRATE_FORCES,profile_endtime-profile_begtime); + profile_begtime=profile_endtime; + } + /* GENERATE CONSTRAINT ISLANDS */ Body2DSW *island_list=NULL; @@ -190,7 +202,6 @@ void Step2DSW::step(Space2DSW* p_space,float p_delta,int p_iterations) { const SelfList<Area2DSW>::List &aml = p_space->get_moved_area_list(); - while(aml.first()) { for(const Set<Constraint2DSW*>::Element *E=aml.first()->self()->get_constraints().front();E;E=E->next()) { @@ -206,6 +217,13 @@ void Step2DSW::step(Space2DSW* p_space,float p_delta,int p_iterations) { } // print_line("island count: "+itos(island_count)+" active count: "+itos(active_count)); + + { //profile + profile_endtime=OS::get_singleton()->get_ticks_usec(); + p_space->set_elapsed_time(Space2DSW::ELAPSED_TIME_GENERATE_ISLANDS,profile_endtime-profile_begtime); + profile_begtime=profile_endtime; + } + /* SETUP CONSTRAINT ISLANDS */ { @@ -248,6 +266,12 @@ void Step2DSW::step(Space2DSW* p_space,float p_delta,int p_iterations) { } } + { //profile + profile_endtime=OS::get_singleton()->get_ticks_usec(); + p_space->set_elapsed_time(Space2DSW::ELAPSED_TIME_SETUP_CONSTRAINTS,profile_endtime-profile_begtime); + profile_begtime=profile_endtime; + } + /* SOLVE CONSTRAINT ISLANDS */ { @@ -259,6 +283,12 @@ void Step2DSW::step(Space2DSW* p_space,float p_delta,int p_iterations) { } } + { //profile + profile_endtime=OS::get_singleton()->get_ticks_usec(); + p_space->set_elapsed_time(Space2DSW::ELAPSED_TIME_SOLVE_CONSTRAINTS,profile_endtime-profile_begtime); + profile_begtime=profile_endtime; + } + /* INTEGRATE VELOCITIES */ b = body_list->first(); @@ -280,6 +310,12 @@ void Step2DSW::step(Space2DSW* p_space,float p_delta,int p_iterations) { } } + { //profile + profile_endtime=OS::get_singleton()->get_ticks_usec(); + p_space->set_elapsed_time(Space2DSW::ELAPSED_TIME_INTEGRATE_VELOCITIES,profile_endtime-profile_begtime); + //profile_begtime=profile_endtime; + } + p_space->update(); p_space->unlock(); _step++; diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index dd04f0f6b8..53c5a9ecc0 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -562,7 +562,9 @@ public: INFO_ACTIVE_OBJECTS, INFO_COLLISION_PAIRS, - INFO_ISLAND_COUNT + INFO_ISLAND_COUNT, + INFO_STEP_TIME, + INFO_BROAD_PHASE_TIME }; virtual int get_process_info(ProcessInfo p_info)=0; |