Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/fceux.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorharry <hrosen2016@gmail.com>2022-08-05 13:45:10 +0300
committerzeromus <zeromus@users.noreply.github.com>2022-08-10 04:28:58 +0300
commitd834ac4e53635c0b03d464155a1b89711ae6db52 (patch)
tree30e772de79585a6f36f8d364893bf7e0c5ff395d /src
parentd225d4863c0ebb85ff507a4b75ef7c242e87c134 (diff)
Qt trace logger optimization. Added code to flush data to disk when emulation is paused. This allows the file to updated with latest data when hitting breakpoints during debugging.
Diffstat (limited to 'src')
-rw-r--r--src/drivers/Qt/TraceLogger.cpp47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/drivers/Qt/TraceLogger.cpp b/src/drivers/Qt/TraceLogger.cpp
index 47528131..8107eee7 100644
--- a/src/drivers/Qt/TraceLogger.cpp
+++ b/src/drivers/Qt/TraceLogger.cpp
@@ -26,6 +26,7 @@
#ifdef WIN32
#include <windows.h>
#else
+#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -111,8 +112,11 @@ static int recBufHead = 0;
static int recBufNum = 0;
static traceRecord_t *logBuf = NULL;
static int logBufMax = 3000000;
-static int logBufHead = 0;
-static int logBufTail = 0;
+// logBufHead and logBufTail are volatile because they are shared use by both the emulation and disk logger threads.
+// Ensure that the compiler doesn't do any thread caching optimizations on them so that changes to these
+// variables are immediately visible by the other thread.
+static volatile int logBufHead = 0;
+static volatile int logBufTail = 0;
static bool overrunWarningArmed = true;
static TraceLoggerDialog_t *traceLogWindow = NULL;
static void pushMsgToLogBuffer(const char *msg);
@@ -2515,6 +2519,8 @@ void TraceLogDiskThread_t::run(void)
char buf[8192];
int i,idx=0;
int blockSize = 4 * 1024;
+ bool dataNeedsFlush = true;
+ bool isPaused = false;
//printf("Trace Log Disk Start\n");
@@ -2557,6 +2563,8 @@ void TraceLogDiskThread_t::run(void)
while ( !isInterruptionRequested() )
{
+ isPaused = FCEUI_EmulationPaused() ? true : false;
+
while (logBufHead != logBufTail)
{
logBuf[logBufTail].convToText(line);
@@ -2582,6 +2590,41 @@ void TraceLogDiskThread_t::run(void)
}
idx = 0;
#endif
+ dataNeedsFlush = true;
+ }
+ }
+
+ if (isPaused)
+ {
+ // If paused, the user might be at a breakpoint or doing some
+ // debugging. So make sure all data is flushed to disk for viewing.
+ // Only flush data when paused, to keep write efficiency up.
+ if ( idx > 0 )
+ {
+ #ifdef WIN32
+ DWORD bytesWritten;
+ WriteFile( logFile, buf, idx, &bytesWritten, NULL ); idx = 0;
+ #else
+ if ( write( logFile, buf, idx ) < 0 )
+ {
+ // HANDLE ERROR TODO
+ }
+ idx = 0;
+ #endif
+ dataNeedsFlush = true;
+ }
+ if (dataNeedsFlush)
+ {
+ //printf("Flushing Trace Log Disk Buffers\n");
+ #ifdef WIN32
+ FlushFileBuffers( logFile );
+ #else
+ if ( fsync( logFile ) )
+ {
+ printf("Trace Log fsync error\n");
+ }
+ #endif
+ dataNeedsFlush = false;
}
}
SDL_Delay(1);