Skip to content

Commit

Permalink
debugLogFromGfxCallback: Add repeated message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Nov 29, 2023
1 parent a86f856 commit d4808ba
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions lib/framework/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ static void debugDisplayFatalErrorMsgBox(const char* outputLogLine)
// Special version of _debug that doesn't use any global debug-logging state (or special sauce) *except* the callbackRegistry (via printToDebugCallbacks)
void _debugFromGfxCallback(int line, code_part part, const char *function, const char *str, ...)
{
thread_local char lastGfxCallbackMsg[MAX_LEN_LOG_LINE] = {'\0'};
thread_local unsigned int repeated = 0; /* times last message repeated */
thread_local unsigned int prev = 0; /* total on last update */

char outputBuffer[MAX_LEN_LOG_LINE];

time_t rawtime;
Expand All @@ -549,11 +553,54 @@ void _debugFromGfxCallback(int line, code_part part, const char *function, const
vsnprintf(pStartOutputLineContents, remainingLength, str, ap);
va_end(ap);

printToDebugCallbacks(outputBuffer, part);
if (strncmp(lastGfxCallbackMsg, pStartOutputLineContents, MAX_LEN_LOG_LINE) == 0)
{
// last message, duplicated
++repeated;
bool isRepeatedPowOf2 = repeated >= 2 && ((repeated & (repeated - 1)) == 0);
if (isRepeatedPowOf2)
{
if (repeated > 2)
{
snprintf(pStartOutputLineContents, remainingLength, "last message repeated %u times (total %u repeats)", repeated - prev, repeated);
}
else
{
snprintf(pStartOutputLineContents, remainingLength, "last message repeated %u times", repeated - prev);
}
printToDebugCallbacks(outputBuffer, part);
prev = repeated;
}
}
else
{
// Received another line, cleanup the old
if (repeated > 0 && repeated != prev && repeated != 1)
{
/* just repeat the previous message when only one repeat occurred */
if (repeated > 2)
{
ssprintf(lastGfxCallbackMsg, "last message repeated %u times (total %u repeats)", repeated - prev, repeated);
}
else
{
ssprintf(lastGfxCallbackMsg, "last message repeated %u times", repeated - prev);
}
printToDebugCallbacks(lastGfxCallbackMsg, part);
}
repeated = 0;
prev = 0;
sstrcpy(lastGfxCallbackMsg, pStartOutputLineContents);
}

if (part == LOG_FATAL)
if (!repeated)
{
debugDisplayFatalErrorMsgBox(pStartOutputLineContents);
printToDebugCallbacks(outputBuffer, part);

if (part == LOG_FATAL)
{
debugDisplayFatalErrorMsgBox(pStartOutputLineContents);
}
}
}

Expand Down

0 comments on commit d4808ba

Please sign in to comment.