]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_exec.c
DP_QC_URI_ESCAPE
[xonotic/darkplaces.git] / prvm_exec.c
index 7481114822f751e2948290990a8ca322f7ff11f8..95a94196b5f721690d4ef124f0b604c5a22774f1 100644 (file)
@@ -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 ; i<prog->progs->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 <program name>\n");
+               return;
+       }
+
+       PRVM_Begin;
+       if(!PRVM_SetProgFromString(Cmd_Argv(1)))
+               return;
+
+       PRVM_CallProfile();
+
+       PRVM_End;
+}
+
 /*
 ============
 PRVM_Profile_f
@@ -369,6 +429,8 @@ void PRVM_Crash(void)
        if (prog == NULL)
                return;
 
+       prog->funcoffsets.SV_Shutdown = 0; // don't call SV_Shutdown on crash
+
        if( prog->depth > 0 )
        {
                Con_Printf("QuakeC crash report for %s:\n", PRVM_NAME);
@@ -485,7 +547,9 @@ PRVM_ExecuteProgram
 #define OPA ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->a])
 #define OPB ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->b])
 #define OPC ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->c])
+#ifdef PRVM_BOUNDSCHECK_CVAR
 extern cvar_t prvm_boundscheck;
+#endif
 extern cvar_t prvm_traceqc;
 extern cvar_t prvm_statementprofiling;
 extern sizebuf_t vm_tempstringsbuf;
@@ -497,11 +561,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);
        }
 
@@ -531,7 +598,9 @@ chooseexecprogram:
        if (prvm_statementprofiling.integer)
        {
 #define PRVMSTATEMENTPROFILING 1
+#ifdef PRVM_BOUNDSCHECK_CVAR
                if (prvm_boundscheck.integer)
+#endif
                {
 #define PRVMBOUNDSCHECK 1
                        if (prog->trace)
@@ -546,6 +615,7 @@ chooseexecprogram:
                        }
 #undef PRVMBOUNDSCHECK
                }
+#ifdef PRVM_BOUNDSCHECK_CVAR
                else
                {
                        if (prog->trace)
@@ -559,11 +629,14 @@ chooseexecprogram:
 #include "prvm_execprogram.h"
                        }
                }
+#endif
 #undef PRVMSTATEMENTPROFILING
        }
        else
        {
+#ifdef PRVM_BOUNDSCHECK_CVAR
                if (prvm_boundscheck.integer)
+#endif
                {
 #define PRVMBOUNDSCHECK 1
                        if (prog->trace)
@@ -578,6 +651,7 @@ chooseexecprogram:
                        }
 #undef PRVMBOUNDSCHECK
                }
+#ifdef PRVM_BOUNDSCHECK_CVAR
                else
                {
                        if (prog->trace)
@@ -591,6 +665,7 @@ chooseexecprogram:
 #include "prvm_execprogram.h"
                        }
                }
+#endif
        }
 
 cleanup:
@@ -598,4 +673,8 @@ cleanup:
                Con_Printf("PRVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog->functions[fnum].s_name), vm_tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize);
        // delete tempstrings created by this function
        vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
+
+       prog->functions[fnum].totaltime += (Sys_DoubleTime() - calltime);
+
+       SV_FlushBroadcastMessages();
 }