[gamecode] Count calls to builtins in profile

It's a bit disconcerting seeing a builtin in the top 10 when builtins
are counted by call while progs functions are counted by instruction.

Also, show the total profile after the function top-10 list.
This commit is contained in:
Bill Currie 2022-02-04 21:49:59 +09:00
parent 974af36d13
commit 7731c469e2
2 changed files with 12 additions and 3 deletions

View file

@ -1787,11 +1787,17 @@ PR_StackTrace (progs_t *pr)
VISIBLE void
PR_Profile (progs_t * pr)
{
pr_uint_t max, num, i;
pr_ulong_t max, num, i;
pr_ulong_t total;
dfunction_t *f;
bfunction_t *best, *bf;
num = 0;
total = 0;
for (i = 0; i < pr->progs->functions.count; i++) {
bf = &pr->function_table[i];
total += bf->profile;
}
do {
max = 0;
best = NULL;
@ -1805,13 +1811,15 @@ PR_Profile (progs_t * pr)
if (best) {
if (num < 10) {
f = pr->pr_functions + (best - pr->function_table);
Sys_Printf ("%7i %s\n", best->profile,
PR_GetString (pr, f->name));
Sys_Printf ("%7"PRIu64" %s%s\n", best->profile,
PR_GetString (pr, f->name),
f->first_statement < 0 ? " (builtin)" : "");
}
num++;
best->profile = 0;
}
} while (best);
Sys_Printf ("total: %7"PRIu64"\n", total);
}
static void

View file

@ -455,6 +455,7 @@ PR_CallFunction (progs_t *pr, pr_func_t fnum, pr_type_t *return_ptr)
int builtin_depth = pr->pr_depth;
pr->pr_return = return_ptr;
f->func (pr);
f->profile++; // to show number times the builtin is called
if (builtin_depth == pr->pr_depth) {
pr->pr_return = saved_return;
} else if (builtin_depth < pr->pr_depth) {