From ff437835bb2c762ac9219604bb2f76cade7f9a0f Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 4 Feb 2022 15:19:18 +0600 Subject: [PATCH] Enable minitrace support --- src/minitrace/minitrace.c | 38 ++++++++++++++++---- src/qt/qt_mainwindow.cpp | 67 ++++++++++++++++++++++++++++++++++++ src/qt/qt_newfloppydialog.ui | 62 ++++++++++++++++----------------- src/qt/qt_progsettings.hpp | 3 ++ 4 files changed, 132 insertions(+), 38 deletions(-) diff --git a/src/minitrace/minitrace.c b/src/minitrace/minitrace.c index 11cae6b9a..32d2ebcae 100644 --- a/src/minitrace/minitrace.c +++ b/src/minitrace/minitrace.c @@ -30,6 +30,7 @@ #include #include #include +#include #endif #include @@ -66,8 +67,8 @@ typedef struct raw_event { static raw_event_t *event_buffer; static raw_event_t *flush_buffer; static volatile int event_count; -static __attribute__ ((aligned (32))) volatile long is_tracing = FALSE; -static __attribute__ ((aligned (32))) volatile long stop_flushing_requested = FALSE; +static __attribute__ ((aligned (32))) atomic_long is_tracing = FALSE; +static __attribute__ ((aligned (32))) atomic_long stop_flushing_requested = FALSE; static int is_flushing = FALSE; static int events_in_progress = 0; static int64_t time_offset; @@ -93,8 +94,6 @@ void mtr_flush_with_state(int); // mtr_time_s() // pthread basics #ifdef _WIN32 -#define atomic_load(a) InterlockedOr((a), 0) -#define atomic_store(a, b) InterlockedExchange((a), b) static int get_cur_thread_id() { return (int)GetCurrentThreadId(); @@ -162,6 +161,31 @@ static inline int get_cur_process_id() { return (int)getpid(); } +static pthread_t thread_handle = 0; +static void* thread_flush_proc(void* param) { + while(1) { + mtr_flush_with_state(0); + if(atomic_load(&stop_flushing_requested)) { + break; + } + } + return 0; +} +static void init_flushing_thread(void) { + pthread_mutex_lock(&mutex); + is_flushing = FALSE; + pthread_mutex_unlock(&mutex); + if (pthread_create(&thread_handle, NULL, thread_flush_proc, NULL) != 0) + { + thread_handle = 0; + } +} + +static void join_flushing_thread(void) { + if (thread_handle) pthread_join(thread_handle, NULL); + thread_handle = 0; +} + #if defined(BLACKBERRY) double mtr_time_s() { struct timespec time; @@ -269,9 +293,9 @@ void mtr_start() { #ifndef MTR_ENABLED return; #endif - pthread_cond_init(&buffer_not_full_cond); - pthread_cond_init(&buffer_full_cond); - atomic_store(&is_tracing, TRUE); + pthread_cond_init(&buffer_not_full_cond, NULL); + pthread_cond_init(&buffer_full_cond, NULL); + atomic_store(&is_tracing, TRUE); init_flushing_thread(); } diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 8e6a5c371..6d017dc7a 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -17,6 +17,10 @@ extern "C" { #include <86box/video.h> #include <86box/vid_ega.h> #include <86box/version.h> + +#ifdef MTR_ENABLED +#include +#endif }; #include @@ -338,6 +342,63 @@ MainWindow::MainWindow(QWidget *parent) : } }); } + +#ifdef MTR_ENABLED + { + ui->menuTools->addSeparator(); + static auto actionBegin_trace = ui->menuTools->addAction(tr("Begin trace")); + static auto actionEnd_trace = ui->menuTools->addAction(tr("End trace")); + actionBegin_trace->setShortcut(QKeySequence(Qt::Key_Control + Qt::Key_T)); + actionEnd_trace->setShortcut(QKeySequence(Qt::Key_Control + Qt::Key_T)); + actionEnd_trace->setDisabled(true); + static auto init_trace = [&] + { + mtr_init("trace.json"); + mtr_start(); + }; + static auto shutdown_trace = [&] + { + mtr_stop(); + mtr_shutdown(); + }; +#ifdef Q_OS_MACOS + actionBegin_trace->setShortcutVisibleInContextMenu(true); + actionEnd_trace->setShortcutVisibleInContextMenu(true); +#endif + static bool trace = false; + connect(actionBegin_trace, &QAction::triggered, this, [this] + { + if (trace) return; + actionBegin_trace->setDisabled(true); + actionEnd_trace->setDisabled(false); + init_trace(); + trace = true; + }); + connect(actionEnd_trace, &QAction::triggered, this, [this] + { + if (!trace) return; + actionBegin_trace->setDisabled(false); + actionEnd_trace->setDisabled(true); + shutdown_trace(); + trace = false; + }); + } +#endif + +#ifdef ENABLE_VRAM_DUMP + { +#ifndef MTR_ENABLED + ui->menuTools->addSeparator(); +#endif + auto actionDump_video_RAM = ui->menuTools->addAction(tr("Dump &video RAM")); + actionDump_video_RAM->setShortcut(QKeySequence(Qt::Key_Control + Qt::Key_F1)); +#ifdef Q_OS_MACOS + actionDump_video_RAM->setShortcutVisibleInContextMenu(true); +#endif + connect(actionDump_video_RAM, &QAction::triggered, this, [this] + { svga_dump_vram(); }); + } +#endif } void MainWindow::closeEvent(QCloseEvent *event) { @@ -1068,6 +1129,12 @@ bool MainWindow::eventFilter(QObject* receiver, QEvent* event) } } + if (receiver == this) + { + static auto curdopause = dopause; + if (event->type() == QEvent::WindowBlocked) { curdopause = dopause; plat_pause(1); } + else if (event->type() == QEvent::WindowUnblocked) { plat_pause(curdopause); } + } return QMainWindow::eventFilter(receiver, event); } diff --git a/src/qt/qt_newfloppydialog.ui b/src/qt/qt_newfloppydialog.ui index e016f3a9b..c9e744845 100644 --- a/src/qt/qt_newfloppydialog.ui +++ b/src/qt/qt_newfloppydialog.ui @@ -13,11 +13,38 @@ New Image - - + + + + + File name: + + + + + + + + + + Disk size: + + + + - + + + + RPM mode: + + + + + + + Qt::Vertical @@ -30,7 +57,7 @@ - + Qt::Horizontal @@ -40,33 +67,6 @@ - - - - File name: - - - - - - - Disk size: - - - - - - - - - - RPM mode: - - - - - - diff --git a/src/qt/qt_progsettings.hpp b/src/qt/qt_progsettings.hpp index a21fe9203..39b3e6819 100644 --- a/src/qt/qt_progsettings.hpp +++ b/src/qt/qt_progsettings.hpp @@ -30,6 +30,9 @@ public: if (strcmp(sourceText, "&Fullscreen") == 0) sourceText = "&Fullscreen\tCtrl+Alt+PageUP"; if (strcmp(sourceText, "&Ctrl+Alt+Del") == 0) sourceText = "&Ctrl+Alt+Del\tCtrl+F12"; if (strcmp(sourceText, "Take s&creenshot") == 0) sourceText = "Take s&creenshot\tCtrl+F11"; + if (strcmp(sourceText, "Begin trace") == 0) sourceText = "Begin trace\tCtrl+T"; + if (strcmp(sourceText, "End trace") == 0) sourceText = "End trace\tCtrl+T"; + if (strcmp(sourceText, "Dump &video RAM") == 0) sourceText = "Dump &video RAM\tCtrl+F1"; if (strcmp(sourceText, "&Qt (Software)") == 0) { QString finalstr = QTranslator::translate("", "&SDL (Software)", disambiguation, n);