1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

First version of Profiler

It is now possible to profile GDScript as well as some parts of Godot
internals.
This commit is contained in:
Juan Linietsky
2016-05-21 21:18:16 -03:00
parent c195c0df6b
commit a75f896338
35 changed files with 2245 additions and 180 deletions

View File

@@ -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();
}