summaryrefslogtreecommitdiff
path: root/servers/physics
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-05-21 21:18:16 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-05-21 21:18:16 -0300
commita75f8963380a1f6ae8501f21a1d3f3bef8a89d91 (patch)
treeae561ded247f81565c8287b6fd4b816f6ec762e6 /servers/physics
parentc195c0df6b36debc870216dd42e49fbda70fa861 (diff)
First version of Profiler
It is now possible to profile GDScript as well as some parts of Godot internals.
Diffstat (limited to 'servers/physics')
-rw-r--r--servers/physics/physics_server_sw.cpp42
-rw-r--r--servers/physics/space_sw.cpp4
-rw-r--r--servers/physics/space_sw.h16
-rw-r--r--servers/physics/step_sw.cpp38
4 files changed, 99 insertions, 1 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++;