#include "argumentseditor.h"
#include "imageviewer.h"
#include "jumpwidget.h"
+#include "profiledialog.h"
#include "retracer.h"
#include "searchwidget.h"
#include "settingsdialog.h"
#include "shaderssourcewidget.h"
#include "tracedialog.h"
#include "traceprocess.h"
+#include "trimprocess.h"
#include "thumbnail.h"
#include "ui_retracerdialog.h"
+#include "ui_profilereplaydialog.h"
#include "vertexdatainterpreter.h"
+#include "trace_profiler.hpp"
#include <QAction>
#include <QApplication>
m_nonDefaultsLookupEvent(0)
{
m_ui.setupUi(this);
+ updateActionsState(false);
initObjects();
initConnections();
}
+MainWindow::~MainWindow()
+{
+ delete m_trace;
+ m_trace = 0;
+
+ delete m_proxyModel;
+ delete m_model;
+}
+
void MainWindow::createTrace()
{
if (!m_traceProcess->canTrace()) {
newTraceFile(fileName);
}
+void MainWindow::setRemoteTarget(const QString &host)
+{
+ m_retracer->setRemoteTarget(host);
+}
+
void MainWindow::callItemSelected(const QModelIndex &index)
{
ApiTraceEvent *event =
}
}
}
+ m_ui.backtraceBrowser->setText(call->backtrace());
+ m_ui.backtraceDock->setVisible(!call->backtrace().isNull());
m_ui.vertexDataDock->setVisible(call->hasBinaryData());
m_selectedEvent = call;
} else {
m_selectedEvent = 0;
}
m_ui.detailsDock->hide();
+ m_ui.backtraceDock->hide();
m_ui.vertexDataDock->hide();
}
if (m_selectedEvent && m_selectedEvent->hasState()) {
"Please wait until it finishes and try again."));
return;
}
+
QDialog dlg;
Ui_RetracerDialog dlgUi;
dlgUi.setupUi(&dlg);
dlgUi.doubleBufferingCB->setChecked(
m_retracer->isDoubleBuffered());
+
dlgUi.errorCheckCB->setChecked(
!m_retracer->isBenchmarking());
+ dlgUi.singlethreadCB->setChecked(
+ m_retracer->isSinglethread());
+
if (dlg.exec() == QDialog::Accepted) {
m_retracer->setDoubleBuffered(
dlgUi.doubleBufferingCB->isChecked());
+
m_retracer->setBenchmarking(
!dlgUi.errorCheckCB->isChecked());
- replayTrace(false, true);
+
+ m_retracer->setSinglethread(
+ dlgUi.singlethreadCB->isChecked());
+
+ m_retracer->setProfiling(false, false, false);
+
+ replayTrace(false, false);
+ }
+}
+
+void MainWindow::replayProfile()
+{
+ if (m_trace->isSaving()) {
+ QMessageBox::warning(
+ this,
+ tr("Trace Saving"),
+ tr("QApiTrace is currently saving the edited trace file. "
+ "Please wait until it finishes and try again."));
+ return;
+ }
+
+ QDialog dlg;
+ Ui_ProfileReplayDialog dlgUi;
+ dlgUi.setupUi(&dlg);
+
+ if (dlg.exec() == QDialog::Accepted) {
+ m_retracer->setProfiling(
+ dlgUi.gpuTimesCB->isChecked(),
+ dlgUi.cpuTimesCB->isChecked(),
+ dlgUi.pixelsDrawnCB->isChecked());
+
+ replayTrace(false, false);
}
}
void MainWindow::replayStop()
{
m_retracer->quit();
- m_ui.actionStop->setEnabled(false);
- m_ui.actionReplay->setEnabled(true);
- m_ui.actionLookupState->setEnabled(true);
- m_ui.actionShowThumbnails->setEnabled(true);
+ updateActionsState(true, true);
}
void MainWindow::newTraceFile(const QString &fileName)
m_trace->setFileName(fileName);
if (fileName.isEmpty()) {
- m_ui.actionReplay->setEnabled(false);
- m_ui.actionLookupState->setEnabled(false);
- m_ui.actionShowThumbnails->setEnabled(false);
+ updateActionsState(false);
setWindowTitle(tr("QApiTrace"));
} else {
+ updateActionsState(true);
QFileInfo info(fileName);
- m_ui.actionReplay->setEnabled(true);
- m_ui.actionLookupState->setEnabled(true);
- m_ui.actionShowThumbnails->setEnabled(true);
setWindowTitle(
tr("QApiTrace - %1").arg(info.fileName()));
}
}
-void MainWindow::replayFinished(const QString &output)
+void MainWindow::replayFinished(const QString &message)
{
- m_ui.actionStop->setEnabled(false);
- m_ui.actionReplay->setEnabled(true);
- m_ui.actionLookupState->setEnabled(true);
- m_ui.actionShowThumbnails->setEnabled(true);
-
+ updateActionsState(true);
m_progressBar->hide();
- if (output.length() < 80) {
- statusBar()->showMessage(output);
- }
+ statusBar()->showMessage(message, 2000);
m_stateEvent = 0;
m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
m_ui.errorsDock->setVisible(m_trace->hasErrors());
if (!m_trace->hasErrors()) {
m_ui.errorsTreeWidget->clear();
}
-
- statusBar()->showMessage(
- tr("Replaying finished!"), 2000);
}
void MainWindow::replayError(const QString &message)
{
- m_ui.actionStop->setEnabled(false);
- m_ui.actionReplay->setEnabled(true);
- m_ui.actionLookupState->setEnabled(true);
- m_ui.actionShowThumbnails->setEnabled(true);
+ updateActionsState(true);
m_stateEvent = 0;
m_nonDefaultsLookupEvent = 0;
statusBar()->showMessage(
tr("Capturing thumbnails..."));
}
+ } else if (m_retracer->isProfiling()) {
+ statusBar()->showMessage(
+ tr("Profiling draw calls in trace file..."));
} else {
statusBar()->showMessage(
tr("Replaying the trace file..."));
}
}
+void MainWindow::trimEvent()
+{
+ int trimIndex = 0;
+
+ Q_ASSERT(m_trimEvent->type() == ApiTraceEvent::Call ||
+ m_trimEvent->type() == ApiTraceEvent::Frame);
+
+ if (m_trimEvent->type() == ApiTraceEvent::Call) {
+ ApiTraceCall *call = static_cast<ApiTraceCall*>(m_trimEvent);
+ trimIndex = call->index();
+ } else if (m_trimEvent->type() == ApiTraceEvent::Frame) {
+ ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(m_trimEvent);
+ const QList<ApiTraceFrame*> frames = m_trace->frames();
+ trimIndex = frame->lastCallIndex();
+ }
+
+ m_trimProcess->setTracePath(m_trace->fileName());
+ m_trimProcess->setTrimIndex(trimIndex);
+
+ m_trimProcess->start();
+}
+
void MainWindow::lookupState()
{
if (!m_selectedEvent) {
replayTrace(false, true);
}
-MainWindow::~MainWindow()
+void MainWindow::trim()
{
- delete m_trace;
- m_trace = 0;
-
- delete m_proxyModel;
- delete m_model;
+ if (!m_selectedEvent) {
+ QMessageBox::warning(
+ this, tr("Unknown Event"),
+ tr("To trim select a frame or an event in the event list."));
+ return;
+ }
+ m_trimEvent = m_selectedEvent;
+ trimEvent();
}
static void
l->setWordWrap(true);
tree->setItemWidget(item, 1, l);
- item->setData(0, Qt::UserRole, surface.image());
+ item->setData(0, Qt::UserRole, surface.base64Data());
}
void MainWindow::fillStateForFrame()
void MainWindow::showSettings()
{
SettingsDialog dialog;
- dialog.setAPI(m_api);
dialog.setFilterModel(m_proxyModel);
dialog.exec();
-
- m_api = dialog.getAPI();
}
void MainWindow::openHelp(const QUrl &url)
viewer->setAttribute(Qt::WA_DeleteOnClose, true);
QVariant var = item->data(0, Qt::UserRole);
- QImage img = var.value<QImage>();
- viewer->setImage(img);
+ QByteArray base64Data = var.value<QByteArray>();
+ viewer->setBase64Data(base64Data);
viewer->show();
viewer->raise();
m_argsEditor = new ArgumentsEditor(this);
m_ui.detailsDock->hide();
+ m_ui.backtraceDock->hide();
m_ui.errorsDock->hide();
m_ui.vertexDataDock->hide();
m_ui.stateDock->hide();
tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
+ tabifyDockWidget(m_ui.detailsDock, m_ui.backtraceDock);
m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
m_searchWidget->hide();
m_traceProcess = new TraceProcess(this);
+ m_trimProcess = new TrimProcess(this);
+
+ m_profileDialog = new ProfileDialog();
}
void MainWindow::initConnections()
this, SLOT(replayError(const QString&)));
connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
this, SLOT(replayStateFound(ApiTraceState*)));
+ connect(m_retracer, SIGNAL(foundProfile(trace::Profile*)),
+ this, SLOT(replayProfileFound(trace::Profile*)));
connect(m_retracer, SIGNAL(foundThumbnails(const QList<QImage>&)),
this, SLOT(replayThumbnailsFound(const QList<QImage>&)));
connect(m_retracer, SIGNAL(retraceErrors(const QList<ApiTraceError>&)),
connect(m_ui.actionReplay, SIGNAL(triggered()),
this, SLOT(replayStart()));
+ connect(m_ui.actionProfile, SIGNAL(triggered()),
+ this, SLOT(replayProfile()));
connect(m_ui.actionStop, SIGNAL(triggered()),
this, SLOT(replayStop()));
connect(m_ui.actionLookupState, SIGNAL(triggered()),
this, SLOT(lookupState()));
+ connect(m_ui.actionTrim, SIGNAL(triggered()),
+ this, SLOT(trim()));
connect(m_ui.actionShowThumbnails, SIGNAL(triggered()),
this, SLOT(showThumbnails()));
connect(m_ui.actionOptions, SIGNAL(triggered()),
connect(m_traceProcess, SIGNAL(error(const QString&)),
SLOT(traceError(const QString&)));
+ connect(m_trimProcess, SIGNAL(trimmedFile(const QString&)),
+ SLOT(createdTrim(const QString&)));
+ connect(m_trimProcess, SIGNAL(error(const QString&)),
+ SLOT(trimError(const QString&)));
+
connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
connect(m_ui.errorsTreeWidget,
SIGNAL(itemActivated(QTreeWidgetItem*, int)),
this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
+
+ connect(m_ui.actionShowProfileDialog, SIGNAL(triggered(bool)),
+ m_profileDialog, SLOT(show()));
+ connect(m_profileDialog, SIGNAL(jumpToCall(int)),
+ this, SLOT(slotJumpTo(int)));
+}
+
+void MainWindow::updateActionsState(bool traceLoaded, bool stopped)
+{
+ if (traceLoaded) {
+ /* Edit */
+ m_ui.actionFind ->setEnabled(true);
+ m_ui.actionGo ->setEnabled(true);
+ m_ui.actionGoFrameStart ->setEnabled(true);
+ m_ui.actionGoFrameEnd ->setEnabled(true);
+
+ /* Trace */
+ if (stopped) {
+ m_ui.actionStop->setEnabled(false);
+ m_ui.actionReplay->setEnabled(true);
+ }
+ else {
+ m_ui.actionStop->setEnabled(true);
+ m_ui.actionReplay->setEnabled(false);
+ }
+
+ m_ui.actionProfile ->setEnabled(true);
+ m_ui.actionLookupState ->setEnabled(true);
+ m_ui.actionShowThumbnails->setEnabled(true);
+ m_ui.actionTrim ->setEnabled(true);
+ }
+ else {
+ /* Edit */
+ m_ui.actionFind ->setEnabled(false);
+ m_ui.actionGo ->setEnabled(false);
+ m_ui.actionGoFrameStart ->setEnabled(false);
+ m_ui.actionGoFrameEnd ->setEnabled(false);
+
+ /* Trace */
+ m_ui.actionReplay ->setEnabled(false);
+ m_ui.actionProfile ->setEnabled(false);
+ m_ui.actionStop ->setEnabled(false);
+ m_ui.actionLookupState ->setEnabled(false);
+ m_ui.actionShowThumbnails->setEnabled(false);
+ m_ui.actionTrim ->setEnabled(false);
+ }
+}
+
+void MainWindow::closeEvent(QCloseEvent * event)
+{
+ m_profileDialog->close();
+ QMainWindow::closeEvent(event);
+}
+
+void MainWindow::replayProfileFound(trace::Profile *profile)
+{
+ m_ui.actionShowProfileDialog->setEnabled(true);
+ m_profileDialog->setProfile(profile);
+ m_profileDialog->show();
+ m_profileDialog->activateWindow();
+ m_profileDialog->setFocus();
}
void MainWindow::replayStateFound(ApiTraceState *state)
msg);
}
+void MainWindow::createdTrim(const QString &path)
+{
+ qDebug()<<"Done trimming "<<path;
+
+ newTraceFile(path);
+}
+
+void MainWindow::trimError(const QString &msg)
+{
+ QMessageBox::warning(
+ this,
+ tr("Trim Error"),
+ msg);
+}
+
void MainWindow::slotSearch()
{
m_jumpWidget->hide();
imageIndex = tr("_call_%1")
.arg(selectedCall()->index());
} else if (selectedFrame()) {
- ApiTraceCall *firstCall = selectedFrame()->call(0);
+ ApiTraceCall *firstCall =
+ static_cast<ApiTraceCall *>(selectedFrame()->eventAtRow(0));
if (firstCall) {
imageIndex = tr("_frame_%1")
.arg(firstCall->index());
QModelIndex idx = m_proxyModel->indexForCall(call);
if (idx.isValid()) {
m_ui.callView->setCurrentIndex(idx);
+ m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtTop);
break;
}
++itr;
QModelIndex idx = m_proxyModel->indexForCall(call);
if (idx.isValid()) {
m_ui.callView->setCurrentIndex(idx);
+ m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtBottom);
break;
}
} while (itr != calls.constBegin());
void MainWindow::slotJumpToResult(ApiTraceCall *call)
{
- QModelIndex index = m_proxyModel->indexForCall(call);
- if (index.isValid()) {
- m_ui.callView->setCurrentIndex(index);
+ QModelIndex idx = m_proxyModel->indexForCall(call);
+ if (idx.isValid()) {
+ activateWindow();
+ m_ui.callView->setFocus();
+ m_ui.callView->setCurrentIndex(idx);
+ m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
} else {
statusBar()->showMessage(tr("Call has been filtered out."));
}