From 84abed4f5fb96c3812143d967aa065e49e55d19d Mon Sep 17 00:00:00 2001
From: havoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Thu, 25 May 2006 03:57:50 +0000
Subject: [PATCH] changed qc profiling to use doubles instead of ints for
 profile counters, so it can now count beyond 4 billion

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6379 d7cf8633-e32d-0410-b094-e92efae38249
---
 pr_comp.h    |  7 ++++---
 progsvm.h    |  2 +-
 prvm_edict.c |  2 +-
 prvm_exec.c  | 25 ++++++++++++++-----------
 4 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/pr_comp.h b/pr_comp.h
index 912491e6..8ccdaf6d 100644
--- a/pr_comp.h
+++ b/pr_comp.h
@@ -163,9 +163,10 @@ typedef struct mfunction_s
 	int		parm_start;
 	int		locals;				// total ints of parms + locals
 
-	int		profile;		// runtime
-	int		builtinsprofile; // cost of builtin functions called by this function
-	int		callcount; // times the functions has been called since the last profile call
+	// these are doubles so that they can count up to 54bits or so rather than 32bit
+	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
 
 	int		s_name;
 	int		s_file;			// source file defined in
diff --git a/progsvm.h b/progsvm.h
index 8f77619d..8270615d 100644
--- a/progsvm.h
+++ b/progsvm.h
@@ -266,7 +266,7 @@ typedef struct prvm_prog_s
 
 	int					*statement_linenums; // NULL if not available
 
-	int					*statement_profile; // only incremented if prvm_statementprofiling is on
+	double				*statement_profile; // only incremented if prvm_statementprofiling is on
 
 	union {
 		float *generic;
diff --git a/prvm_edict.c b/prvm_edict.c
index 29e5998a..68f5197a 100644
--- a/prvm_edict.c
+++ b/prvm_edict.c
@@ -1349,7 +1349,7 @@ void PRVM_LoadProgs (const char * filename, int numrequiredfunc, char **required
 
 	prog->statements = (dstatement_t *)((unsigned char *)prog->progs + prog->progs->ofs_statements);
 
-	prog->statement_profile = (int *)Mem_Alloc(prog->progs_mempool, prog->progs->numstatements * sizeof(*prog->statement_profile));
+	prog->statement_profile = (double *)Mem_Alloc(prog->progs_mempool, prog->progs->numstatements * sizeof(*prog->statement_profile));
 
 	// moved edict_size calculation down below field adding code
 
diff --git a/prvm_exec.c b/prvm_exec.c
index eb8aa349..e7fb591a 100644
--- a/prvm_exec.c
+++ b/prvm_exec.c
@@ -132,7 +132,7 @@ void PRVM_PrintStatement (dstatement_t *s)
 		Con_Printf( "%s:%i: ", PRVM_GetString( prog->xfunction->s_file ), prog->statement_linenums[ opnum ] );
 
 	if (prvm_statementprofiling.integer)
-		Con_Printf("%7i ", prog->statement_profile[s - prog->statements]);
+		Con_Printf("%7.0f ", prog->statement_profile[s - prog->statements]);
 
 	if ( (unsigned)s->op < sizeof(prvm_opnames)/sizeof(prvm_opnames[0]))
 	{
@@ -275,12 +275,13 @@ PRVM_Profile_f
 void PRVM_Profile_f (void)
 {
 	mfunction_t *f, *best;
-	int i, num, max/*, howmany*/;
+	int i, num, howmany;
+	double max;
 
-	//howmany = 10;
-	//if (Cmd_Argc() == 2)
-	//	howmany = atoi(Cmd_Argv(1));
-	if(Cmd_Argc() != 2)
+	howmany = 1<<30;
+	if (Cmd_Argc() == 3)
+		howmany = atoi(Cmd_Argv(2));
+	else if (Cmd_Argc() != 2)
 	{
 		Con_Print("prvm_profile <program name>\n");
 		return;
@@ -308,11 +309,13 @@ void PRVM_Profile_f (void)
 		}
 		if (best)
 		{
-			//if (num < howmany)
-			if (best->first_statement < 0)
-				Con_Printf("%10i ----- builtin ----- %s\n", best->callcount, PRVM_GetString(best->s_name));
-			else
-				Con_Printf("%10i%10i%10i %s\n", best->callcount, best->profile, best->builtinsprofile, PRVM_GetString(best->s_name));
+			if (num < howmany)
+			{
+				if (best->first_statement < 0)
+					Con_Printf("%9.0f ----- builtin ----- %s\n", best->callcount, PRVM_GetString(best->s_name));
+				else
+					Con_Printf("%9.0f %9.0f %9.0f %s\n", best->callcount, best->profile, best->builtinsprofile, PRVM_GetString(best->s_name));
+			}
 			num++;
 			best->profile = 0;
 			best->builtinsprofile = 0;
-- 
2.39.5