double profile; // runtime
double builtinsprofile; // cost of builtin functions called by this function
double callcount; // times the functions has been called since the last profile call
+ double totaltime; // total execution time of this function DIRECTLY FROM THE ENGINE
int s_name;
int s_file; // source file defined in
// NOTE: external code has to create and free the mempools but everything else is done by prvm !
typedef struct prvm_prog_s
{
+ double starttime;
dprograms_t *progs;
mfunction_t *functions;
char *strings;
void PRVM_Profile (int maxfunctions, int mininstructions);
void PRVM_Profile_f (void);
+void PRVM_CallProfile_f (void);
void PRVM_PrintFunction_f (void);
void PRVM_PrintState(void);
PRVM_GCALL(reset_cmd)();
Mem_FreePool(&prog->progs_mempool);
memset(prog,0,sizeof(prvm_prog_t));
+ prog->starttime = Sys_DoubleTime();
}
/*
Cmd_AddCommand ("prvm_edicts", PRVM_ED_PrintEdicts_f, "prints all data about all entities in the selected VM (server, client, menu)");
Cmd_AddCommand ("prvm_edictcount", PRVM_ED_Count_f, "prints number of active entities in the selected VM (server, client, menu)");
Cmd_AddCommand ("prvm_profile", PRVM_Profile_f, "prints execution statistics about the most used QuakeC functions in the selected VM (server, client, menu)");
+ Cmd_AddCommand ("prvm_callprofile", PRVM_CallProfile_f, "prints execution statistics about the most time consuming QuakeC calls from the engine in the selected VM (server, client, menu)");
Cmd_AddCommand ("prvm_fields", PRVM_Fields_f, "prints usage statistics on properties (how many entities have non-zero values) in the selected VM (server, client, menu)");
Cmd_AddCommand ("prvm_globals", PRVM_Globals_f, "prints all global variables in the selected VM (server, client, menu)");
Cmd_AddCommand ("prvm_global", PRVM_Global_f, "prints value of a specified global variable in the selected VM (server, client, menu)");
PRVM_ResetProg();
memset(prog, 0, sizeof(prvm_prog_t));
+ prog->starttime = Sys_DoubleTime();
prog->error_cmd = Host_Error;
}
}
+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;
} 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
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)
{
// delete tempstrings created by this function
vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
+ prog->functions[fnum].totaltime += (Sys_DoubleTime() - calltime);
+
SV_FlushBroadcastMessages();
}