summaryrefslogtreecommitdiffstats
path: root/core/script_debugger_local.cpp
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 /core/script_debugger_local.cpp
parentc195c0df6b36debc870216dd42e49fbda70fa861 (diff)
downloadredot-engine-a75f8963380a1f6ae8501f21a1d3f3bef8a89d91.tar.gz
First version of Profiler
It is now possible to profile GDScript as well as some parts of Godot internals.
Diffstat (limited to 'core/script_debugger_local.cpp')
-rw-r--r--core/script_debugger_local.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/core/script_debugger_local.cpp b/core/script_debugger_local.cpp
index 3e442f7f59..dfff54378a 100644
--- a/core/script_debugger_local.cpp
+++ b/core/script_debugger_local.cpp
@@ -179,6 +179,125 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script,bool p_can_continue) {
}
}
+struct _ScriptDebuggerLocalProfileInfoSort {
+
+ bool operator()(const ScriptLanguage::ProfilingInfo &A,const ScriptLanguage::ProfilingInfo &B) const {
+ return A.total_time > B.total_time;
+ }
+};
+
+void ScriptDebuggerLocal::profiling_set_frame_times(float p_frame_time,float p_idle_time,float p_fixed_time,float p_fixed_frame_time) {
+
+
+ frame_time=p_frame_time;
+ idle_time=p_idle_time;
+ fixed_time=p_fixed_time;
+ fixed_frame_time=p_fixed_frame_time;
+
+
+}
+
+void ScriptDebuggerLocal::idle_poll() {
+
+ if (!profiling)
+ return;
+
+ uint64_t diff = OS::get_singleton()->get_ticks_usec() - idle_accum;
+
+ if (diff<1000000) //show every one second
+ return;
+
+ idle_accum = OS::get_singleton()->get_ticks_usec();
+
+ int ofs=0;
+ for(int i=0;i<ScriptServer::get_language_count();i++) {
+ ofs+=ScriptServer::get_language(i)->profiling_get_frame_data(&pinfo[ofs],pinfo.size()-ofs);
+ }
+
+ SortArray<ScriptLanguage::ProfilingInfo,_ScriptDebuggerLocalProfileInfoSort> sort;
+ sort.sort(pinfo.ptr(),ofs);
+
+ //falta el frame time
+
+ uint64_t script_time_us=0;
+
+ for(int i=0;i<ofs;i++) {
+
+ script_time_us+=pinfo[i].self_time;
+ }
+
+
+ float script_time=USEC_TO_SEC(script_time_us);
+
+ float total_time=frame_time;
+
+ //print script total
+
+ print_line("FRAME: total: "+rtos(frame_time)+" script: "+rtos(script_time)+"/"+itos(script_time*100/total_time)+" %");
+
+ for(int i=0;i<ofs;i++) {
+
+ print_line(itos(i)+":"+pinfo[i].signature);
+ float tt=USEC_TO_SEC(pinfo[i].total_time);
+ float st=USEC_TO_SEC(pinfo[i].self_time);
+ print_line("\ttotal: "+rtos(tt)+"/"+itos(tt*100/total_time)+" % \tself: "+rtos(st)+"/"+itos(st*100/total_time)+" % tcalls: "+itos(pinfo[i].call_count));
+ }
+
+
+
+}
+
+void ScriptDebuggerLocal::profiling_start() {
+
+ for(int i=0;i<ScriptServer::get_language_count();i++) {
+ ScriptServer::get_language(i)->profiling_start();
+ }
+
+
+ print_line("BEGIN PROFILING");
+ profiling=true;
+ pinfo.resize(32768);
+ frame_time=0;
+ fixed_time=0;
+ idle_time=0;
+ fixed_frame_time=0;
+
+}
+
+
+void ScriptDebuggerLocal::profiling_end() {
+
+ int ofs=0;
+
+ for(int i=0;i<ScriptServer::get_language_count();i++) {
+ ofs+=ScriptServer::get_language(i)->profiling_get_accumulated_data(&pinfo[ofs],pinfo.size()-ofs);
+ }
+
+ SortArray<ScriptLanguage::ProfilingInfo,_ScriptDebuggerLocalProfileInfoSort> sort;
+ sort.sort(pinfo.ptr(),ofs);
+
+ uint64_t total_us=0;
+ for(int i=0;i<ofs;i++) {
+ total_us+=pinfo[i].self_time;
+ }
+
+ float total_time=total_us/1000000.0;
+
+ for(int i=0;i<ofs;i++) {
+
+ print_line(itos(i)+":"+pinfo[i].signature);
+ float tt=USEC_TO_SEC(pinfo[i].total_time);;
+ float st=USEC_TO_SEC(pinfo[i].self_time);
+ print_line("\ttotal_ms: "+rtos(tt)+"\tself_ms: "+rtos(st)+"total%: "+itos(tt*100/total_time)+"\tself%: "+itos(st*100/total_time)+"\tcalls: "+itos(pinfo[i].call_count));
+ }
+
+ for(int i=0;i<ScriptServer::get_language_count();i++) {
+ ScriptServer::get_language(i)->profiling_stop();
+ }
+
+ profiling=false;
+}
+
void ScriptDebuggerLocal::send_message(const String& p_message, const Array &p_args) {
print_line("MESSAGE: '"+p_message+"' - "+String(Variant(p_args)));
@@ -186,4 +305,6 @@ void ScriptDebuggerLocal::send_message(const String& p_message, const Array &p_a
ScriptDebuggerLocal::ScriptDebuggerLocal() {
+ profiling=false;
+ idle_accum=OS::get_singleton()->get_ticks_usec();
}