From 2cd01db878dda5b95cc593cafcc32e9fd26d225b Mon Sep 17 00:00:00 2001 From: starfrost013 Date: Sun, 12 Jan 2025 00:58:43 +0000 Subject: [PATCH] initial attempt to "replay" log entries --- src/86box.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/86box.c b/src/86box.c index 2825535fd..f15ca4de3 100644 --- a/src/86box.c +++ b/src/86box.c @@ -254,12 +254,12 @@ static volatile atomic_int pause_ack = 0; #ifndef RELEASE_BUILD -#define LOG_SIZE_BUFFER 1024 /* Log size buffer */ -#define LOG_SIZE_BUFFER_CYCLIC 32 /* Cyclic log size buffer (number of lines that should be cehcked) */ -#define LOG_MINIMUM_REPEAT_ORDER 4 /* Minimum repeat size */ +#define LOG_SIZE_BUFFER 1024 /* Log size buffer */ +#define LOG_SIZE_BUFFER_CYCLIC_LINES 32 /* Cyclic log size buffer (number of lines that should be cehcked) */ +#define LOG_MINIMUM_REPEAT_ORDER 4 /* Minimum repeat size */ static char buff[LOG_SIZE_BUFFER]; -static char cyclic_buff[LOG_SIZE_BUFFER_CYCLIC][LOG_SIZE_BUFFER]; +static char cyclic_buff[LOG_SIZE_BUFFER_CYCLIC_LINES][LOG_SIZE_BUFFER]; static int32_t cyclic_last_line = 0; static int32_t log_cycles = 0; @@ -333,7 +333,7 @@ pclog_ex_cyclic(const char* fmt, va_list ap) #ifndef RELEASE_BUILD char temp[LOG_SIZE_BUFFER]; - cyclic_last_line %= LOG_SIZE_BUFFER_CYCLIC; + cyclic_last_line %= LOG_SIZE_BUFFER_CYCLIC_LINES; vsprintf(temp, fmt, ap); @@ -341,7 +341,7 @@ pclog_ex_cyclic(const char* fmt, va_list ap) strncpy(cyclic_buff[cyclic_last_line], temp, LOG_SIZE_BUFFER); - uint32_t hashes[LOG_SIZE_BUFFER_CYCLIC] = {0}; + uint32_t hashes[LOG_SIZE_BUFFER_CYCLIC_LINES] = {0}; // Random numbers uint32_t base = 257; @@ -351,7 +351,7 @@ pclog_ex_cyclic(const char* fmt, va_list ap) bool is_cycle = false; // compute the set of hashes for the current log buffer - for (int32_t log_line = 0; log_line < LOG_SIZE_BUFFER_CYCLIC; log_line++) + for (int32_t log_line = 0; log_line < LOG_SIZE_BUFFER_CYCLIC_LINES; log_line++) { if (cyclic_buff[log_line][0] == '\0') continue; // skip @@ -365,13 +365,13 @@ pclog_ex_cyclic(const char* fmt, va_list ap) // Now see if there are real cycles... // We implement a minimum repeat size. - for (int32_t check_size = LOG_MINIMUM_REPEAT_ORDER; check_size < LOG_SIZE_BUFFER_CYCLIC / 2; check_size++) + for (int32_t check_size = LOG_MINIMUM_REPEAT_ORDER; check_size < LOG_SIZE_BUFFER_CYCLIC_LINES / 2; check_size++) { //TODO: Log what we need for cycle 1. //TODO: Command line option that lets us turn off this behaviour. for (int32_t log_line_to_check = 0; log_line_to_check < check_size; log_line_to_check++) { - if (hashes[log_line_to_check] == hashes[(log_line_to_check + check_size) % LOG_SIZE_BUFFER_CYCLIC]) + if (hashes[log_line_to_check] == hashes[(log_line_to_check + check_size) % LOG_SIZE_BUFFER_CYCLIC_LINES]) { repeat_order = check_size; break; @@ -393,7 +393,22 @@ pclog_ex_cyclic(const char* fmt, va_list ap) log_cycles++; if (log_cycles == 1) + { + // 'Replay' the last few log entries so they actually show up + // Todo: is this right? + + for (uint32_t index = cyclic_last_line - 1; index > (cyclic_last_line - repeat_order); cyclic_last_line--) + { + // *very important* to prevent out of bounds index + uint32_t real_index = index % LOG_SIZE_BUFFER_CYCLIC_LINES; + fprintf(stdlog, "%s", temp); + + } + fprintf(stdlog, "%s", temp); // allow normal logging + } + + if (log_cycles > 1 && log_cycles < 100) fprintf(stdlog, "***** Cyclical Log Repeat of Order %d #%d *****\n", repeat_order, log_cycles); else if (log_cycles == 100)