Enable minitrace support

This commit is contained in:
Cacodemon345
2022-02-04 15:19:18 +06:00
parent 33f2a16921
commit ff437835bb
4 changed files with 132 additions and 38 deletions

View File

@@ -30,6 +30,7 @@
#include <pthread.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdatomic.h>
#endif
#include <minitrace/minitrace.h>
@@ -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();
}

View File

@@ -17,6 +17,10 @@ extern "C" {
#include <86box/video.h>
#include <86box/vid_ega.h>
#include <86box/version.h>
#ifdef MTR_ENABLED
#include <minitrace/minitrace.h>
#endif
};
#include <QGuiApplication>
@@ -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);
}

View File

@@ -13,11 +13,38 @@
<property name="windowTitle">
<string>New Image</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>File name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="FileField" name="fileField" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Disk size:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBoxSize"/>
</item>
<item row="4" column="0">
<item row="2" column="0">
<widget class="QLabel" name="labelRpm">
<property name="text">
<string>RPM mode:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboBoxRpm"/>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -30,7 +57,7 @@
</property>
</spacer>
</item>
<item row="5" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -40,33 +67,6 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>File name:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Disk size:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="FileField" name="fileField" native="true"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelRpm">
<property name="text">
<string>RPM mode:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboBoxRpm"/>
</item>
</layout>
</widget>
<customwidgets>

View File

@@ -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);