X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=prvm_exec.c;h=80287cab1ae37ea8054bf2f573df5409fcfc38de;hb=26580cf9927d86097895733e661f66ea0827fe35;hp=2a6d44aa395aa6a79b1aa2308ce4bfcbdeb5bac2;hpb=5c00b1379d819146fb18968fd9b5fa84bf4a770a;p=xonotic%2Fdarkplaces.git diff --git a/prvm_exec.c b/prvm_exec.c index 2a6d44aa..80287cab 100644 --- a/prvm_exec.c +++ b/prvm_exec.c @@ -266,6 +266,43 @@ void PRVM_StackTrace (void) } +void PRVM_CallProfile () +{ + mfunction_t *f, *best; + int i; + double max; + double sum; + + Con_Printf( "%s Call Profile:\n", PRVM_NAME ); + + sum = 0; + do + { + max = 0; + best = NULL; + for (i=0 ; iprogs->numfunctions ; i++) + { + f = &prog->functions[i]; + if (max < f->totaltime) + { + max = f->totaltime; + best = f; + } + } + if (best) + { + sum += best->totaltime; + Con_Printf("%9.4f %s\n", best->totaltime, PRVM_GetString(best->s_name)); + best->totaltime = 0; + } + } while (best); + + Con_Printf("Total time since last profile reset: %9.4f\n", Sys_DoubleTime() - prog->starttime); + Con_Printf(" - used by QC code of this VM: %9.4f\n", sum); + + prog->starttime = Sys_DoubleTime(); +} + void PRVM_Profile (int maxfunctions, int mininstructions) { mfunction_t *f, *best; @@ -305,6 +342,29 @@ void PRVM_Profile (int maxfunctions, int mininstructions) } while (best); } +/* +============ +PRVM_CallProfile_f + +============ +*/ +void PRVM_CallProfile_f (void) +{ + if (Cmd_Argc() != 2) + { + Con_Print("prvm_callprofile \n"); + return; + } + + PRVM_Begin; + if(!PRVM_SetProgFromString(Cmd_Argv(1))) + return; + + PRVM_CallProfile(); + + PRVM_End; +} + /* ============ PRVM_Profile_f @@ -497,11 +557,14 @@ void PRVM_ExecuteProgram (func_t fnum, const char *errormessage) prvm_eval_t *ptr; int jumpcount, cachedpr_trace, exitdepth; int restorevm_tempstringsbuf_cursize; + double calltime; + + calltime = Sys_DoubleTime(); if (!fnum || fnum >= (unsigned int)prog->progs->numfunctions) { if (prog->globaloffsets.self >= 0 && PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict) - PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict)); + PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict), NULL); PRVM_ERROR ("PRVM_ExecuteProgram: %s", errormessage); } @@ -599,5 +662,7 @@ cleanup: // delete tempstrings created by this function vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize; + prog->functions[fnum].totaltime += (Sys_DoubleTime() - calltime); + SV_FlushBroadcastMessages(); }