From bc200c582457b4166be8f3fd9fb27a37495ad6b7 Mon Sep 17 00:00:00 2001 From: divverent Date: Tue, 7 Jan 2014 16:29:29 +0000 Subject: [PATCH] Better coverage output. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12043 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=15f3ecf8b59f74d65d3382c729034790650f6264 --- progsvm.h | 2 +- prvm_cmds.c | 2 +- prvm_exec.c | 23 +++++++++++++++++++---- prvm_execprogram.h | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/progsvm.h b/progsvm.h index fb40545e..02cb4bea 100644 --- a/progsvm.h +++ b/progsvm.h @@ -897,6 +897,6 @@ void VM_FrameBlendFromFrameGroupBlend(frameblend_t *frameblend, const framegroup void VM_UpdateEdictSkeleton(prvm_prog_t *prog, prvm_edict_t *ed, const dp_model_t *edmodel, const frameblend_t *frameblend); void VM_RemoveEdictSkeleton(prvm_prog_t *prog, prvm_edict_t *ed); -void PRVM_ExplicitCoverageEvent(prvm_prog_t *prog, int statement); +void PRVM_ExplicitCoverageEvent(prvm_prog_t *prog, mfunction_t *func, int statement); #endif diff --git a/prvm_cmds.c b/prvm_cmds.c index e375a50d..3b8a629d 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -7346,5 +7346,5 @@ void VM_coverage(prvm_prog_t *prog) { VM_SAFEPARMCOUNT(0, VM_coverage); if (prog->explicit_profile[prog->xstatement]++ == 0 && (prvm_coverage.integer & 2)) - PRVM_ExplicitCoverageEvent(prog, prog->xstatement); + PRVM_ExplicitCoverageEvent(prog, prog->xfunction, prog->xstatement); } diff --git a/prvm_exec.c b/prvm_exec.c index 1be07894..b926f26c 100644 --- a/prvm_exec.c +++ b/prvm_exec.c @@ -685,20 +685,35 @@ void PRVM_Init_Exec(prvm_prog_t *prog) Coverage ================== */ +// Note: in these two calls, prog->xfunction is assumed to be sane. +static const char *PRVM_WhereAmI(char *buf, size_t bufsize, prvm_prog_t *prog, mfunction_t *func, int statement) +{ + if (prog->statement_linenums) + { + if (prog->statement_columnnums) + return va(buf, bufsize, "%s:%i:%i(%s, %i)", PRVM_GetString(prog, func->s_file), prog->statement_linenums[statement], prog->statement_columnnums[statement], PRVM_GetString(prog, func->s_name), statement - func->first_statement); + else + return va(buf, bufsize, "%s:%i(%s, %i)", PRVM_GetString(prog, func->s_file), prog->statement_linenums[statement], PRVM_GetString(prog, func->s_name), statement - func->first_statement); + } + else + return va(buf, bufsize, "%s(%s, %i)", PRVM_GetString(prog, func->s_file), PRVM_GetString(prog, func->s_name), statement - func->first_statement); +} static void PRVM_FunctionCoverageEvent(prvm_prog_t *prog, mfunction_t *func) { ++prog->functions_covered; Con_Printf("prvm_coverage: %s just called %s for the first time. Coverage: %.2f%%.\n", prog->name, PRVM_GetString(prog, func->s_name), prog->functions_covered * 100.0 / prog->numfunctions); } -void PRVM_ExplicitCoverageEvent(prvm_prog_t *prog, int statement) +void PRVM_ExplicitCoverageEvent(prvm_prog_t *prog, mfunction_t *func, int statement) { + char vabuf[128]; ++prog->explicit_covered; - Con_Printf("prvm_coverage: %s just executed a coverage() statement for the first time. Coverage: %.2f%%.\n", prog->name, prog->explicit_covered * 100.0 / prog->numexplicitcoveragestatements); + Con_Printf("prvm_coverage: %s just executed a coverage() statement at %s for the first time. Coverage: %.2f%%.\n", prog->name, PRVM_WhereAmI(vabuf, sizeof(vabuf), prog, func, statement), prog->explicit_covered * 100.0 / prog->numexplicitcoveragestatements); } -static void PRVM_StatementCoverageEvent(prvm_prog_t *prog, int statement) +static void PRVM_StatementCoverageEvent(prvm_prog_t *prog, mfunction_t *func, int statement) { + char vabuf[128]; ++prog->statements_covered; - Con_Printf("prvm_coverage: %s just executed a statement for the first time. Coverage: %.2f%%.\n", prog->name, prog->statements_covered * 100.0 / prog->numstatements); + Con_Printf("prvm_coverage: %s just executed a statement at %s for the first time. Coverage: %.2f%%.\n", prog->name, PRVM_WhereAmI(vabuf, sizeof(vabuf), prog, func, statement), prog->statements_covered * 100.0 / prog->numstatements); } diff --git a/prvm_execprogram.h b/prvm_execprogram.h index ea2ba374..d7182fc7 100644 --- a/prvm_execprogram.h +++ b/prvm_execprogram.h @@ -37,7 +37,7 @@ if (prog->trace) PRVM_PrintStatement(prog, st); if (prog->statement_profile[st - cached_statements]++ == 0 && (prvm_coverage.integer & 4)) - PRVM_StatementCoverageEvent(prog, st - cached_statements); + PRVM_StatementCoverageEvent(prog, prog->xfunction, st - cached_statements); if (prog->break_statement >= 0) if ((st - cached_statements) == prog->break_statement) { -- 2.39.2