X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=gui%2Fmainwindow.cpp;h=d6ebd2f9e1ecbe3a107222b684cda6c1e826c7e3;hb=1af9409e5ade504829e8d3260921e5905cbf8f11;hp=3ee8cc29aab6f68ce30e1c6eb121235b5e6c2cf1;hpb=bde6db84069fd9dfbc645de02cb22cacff17c298;p=apitrace diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 3ee8cc2..d6ebd2f 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -8,14 +8,19 @@ #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 #include @@ -36,15 +41,27 @@ MainWindow::MainWindow() : QMainWindow(), + m_api(trace::API_GL), + m_initalCallNum(-1), m_selectedEvent(0), m_stateEvent(0), 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()) { @@ -59,6 +76,7 @@ void MainWindow::createTrace() if (dialog.exec() == QDialog::Accepted) { qDebug()<< "App : " <setApi(dialog.api()); m_traceProcess->setExecutablePath(dialog.applicationPath()); m_traceProcess->setArguments(dialog.arguments()); m_traceProcess->start(); @@ -79,7 +97,7 @@ void MainWindow::openTrace() } } -void MainWindow::loadTrace(const QString &fileName) +void MainWindow::loadTrace(const QString &fileName, int callNum) { if (!QFile::exists(fileName)) { QMessageBox::warning(this, tr("File Missing"), @@ -87,6 +105,7 @@ void MainWindow::loadTrace(const QString &fileName) return; } + m_initalCallNum = callNum; newTraceFile(fileName); } @@ -97,6 +116,10 @@ void MainWindow::callItemSelected(const QModelIndex &index) if (event && event->type() == ApiTraceEvent::Call) { ApiTraceCall *call = static_cast(event); + m_ui.detailsDock->setWindowTitle( + tr("Details View. Frame %1, Call %2") + .arg(call->parentFrame() ? call->parentFrame()->number : 0) + .arg(call->index())); m_ui.detailsWebView->setHtml(call->toHtml()); m_ui.detailsDock->show(); if (call->hasBinaryData()) { @@ -140,6 +163,10 @@ void MainWindow::callItemSelected(const QModelIndex &index) } } +void MainWindow::callItemActivated(const QModelIndex &index) { + lookupState(); +} + void MainWindow::replayStart() { if (m_trace->isSaving()) { @@ -150,30 +177,59 @@ void MainWindow::replayStart() "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()); if (dlg.exec() == QDialog::Accepted) { m_retracer->setDoubleBuffered( dlgUi.doubleBufferingCB->isChecked()); + m_retracer->setBenchmarking( !dlgUi.errorCheckCB->isChecked()); - replayTrace(false); + + 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); + updateActionsState(true, true); } void MainWindow::newTraceFile(const QString &fileName) @@ -184,44 +240,32 @@ void MainWindow::newTraceFile(const QString &fileName) m_trace->setFileName(fileName); if (fileName.isEmpty()) { - m_ui.actionReplay->setEnabled(false); - m_ui.actionLookupState->setEnabled(false); + updateActionsState(false); setWindowTitle(tr("QApiTrace")); } else { + updateActionsState(true); QFileInfo info(fileName); - m_ui.actionReplay->setEnabled(true); - m_ui.actionLookupState->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); - + 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); + updateActionsState(true); m_stateEvent = 0; m_nonDefaultsLookupEvent = 0; @@ -247,19 +291,26 @@ void MainWindow::finishedLoadingTrace() if (!m_trace) { return; } + m_api = m_trace->api(); QFileInfo info(m_trace->fileName()); statusBar()->showMessage( tr("Loaded %1").arg(info.fileName()), 3000); + if (m_initalCallNum >= 0) { + m_trace->findCallIndex(m_initalCallNum); + m_initalCallNum = -1; + } } -void MainWindow::replayTrace(bool dumpState) +void MainWindow::replayTrace(bool dumpState, bool dumpThumbnails) { if (m_trace->fileName().isEmpty()) { return; } m_retracer->setFileName(m_trace->fileName()); + m_retracer->setAPI(m_api); m_retracer->setCaptureState(dumpState); + m_retracer->setCaptureThumbnails(dumpThumbnails); if (m_retracer->captureState() && m_selectedEvent) { int index = 0; if (m_selectedEvent->type() == ApiTraceEvent::Call) { @@ -283,15 +334,45 @@ void MainWindow::replayTrace(bool dumpState) m_ui.actionStop->setEnabled(true); m_progressBar->show(); - if (dumpState) { + if (dumpState || dumpThumbnails) { + if (dumpState && dumpThumbnails) { + statusBar()->showMessage( + tr("Looking up the state and capturing thumbnails...")); + } else if (dumpState) { + statusBar()->showMessage( + tr("Looking up the state...")); + } else if (dumpThumbnails) { + statusBar()->showMessage( + tr("Capturing thumbnails...")); + } + } else if (m_retracer->isProfiling()) { statusBar()->showMessage( - tr("Looking up the state...")); + tr("Profiling draw calls in trace file...")); } else { statusBar()->showMessage( tr("Replaying the trace file...")); } } +void MainWindow::trimEvent() +{ + + int trimIndex; + if (m_trimEvent->type() == ApiTraceEvent::Call) { + ApiTraceCall *call = static_cast(m_trimEvent); + trimIndex = call->index(); + } else if (m_trimEvent->type() == ApiTraceEvent::Frame) { + ApiTraceFrame *frame = static_cast(m_trimEvent); + const QList 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) { @@ -309,16 +390,24 @@ void MainWindow::lookupState() return; } m_stateEvent = m_selectedEvent; - replayTrace(true); + replayTrace(true, false); } -MainWindow::~MainWindow() +void MainWindow::showThumbnails() { - delete m_trace; - m_trace = 0; + replayTrace(false, true); +} - delete m_proxyModel; - delete m_model; +void MainWindow::trim() +{ + 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 @@ -458,8 +547,9 @@ static void addSurfaceItem(const ApiSurface &surface, int width = surface.size().width(); int height = surface.size().height(); QString descr = - QString::fromLatin1("%1, %2 x %3") + QString::fromLatin1("%1, %2, %3 x %4") .arg(label) + .arg(surface.formatName()) .arg(width) .arg(height); @@ -517,7 +607,7 @@ void MainWindow::fillStateForFrame() if (textures.isEmpty() && fbos.isEmpty()) { m_ui.surfacesTab->setDisabled(false); } else { - m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64)); + m_ui.surfacesTreeWidget->setIconSize(QSize(THUMBNAIL_SIZE, THUMBNAIL_SIZE)); if (!textures.isEmpty()) { QTreeWidgetItem *textureItem = new QTreeWidgetItem(m_ui.surfacesTreeWidget); @@ -689,6 +779,9 @@ void MainWindow::initObjects() m_searchWidget->hide(); m_traceProcess = new TraceProcess(this); + m_trimProcess = new TrimProcess(this); + + m_profileDialog = new ProfileDialog(); } void MainWindow::initConnections() @@ -703,10 +796,10 @@ void MainWindow::initConnections() this, SLOT(slotStartedSaving())); connect(m_trace, SIGNAL(saved()), this, SLOT(slotSaved())); - connect(m_trace, SIGNAL(changed(ApiTraceCall*)), - this, SLOT(slotTraceChanged(ApiTraceCall*))); - connect(m_trace, SIGNAL(findResult(ApiTrace::SearchResult,ApiTraceCall*)), - this, SLOT(slotSearchResult(ApiTrace::SearchResult,ApiTraceCall*))); + connect(m_trace, SIGNAL(changed(ApiTraceEvent*)), + this, SLOT(slotTraceChanged(ApiTraceEvent*))); + connect(m_trace, SIGNAL(findResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)), + this, SLOT(slotSearchResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*))); connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)), this, SLOT(slotFoundFrameStart(ApiTraceFrame*))); connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)), @@ -720,6 +813,10 @@ 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&)), + this, SLOT(replayThumbnailsFound(const QList&))); connect(m_retracer, SIGNAL(retraceErrors(const QList&)), this, SLOT(slotRetraceErrors(const QList&))); @@ -753,15 +850,23 @@ void MainWindow::initConnections() 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()), this, SLOT(showSettings())); - connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)), + connect(m_ui.callView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(callItemSelected(const QModelIndex &))); + connect(m_ui.callView, SIGNAL(doubleClicked(const QModelIndex &)), + this, SLOT(callItemActivated(const QModelIndex &))); connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint))); @@ -793,13 +898,79 @@ void MainWindow::initConnections() 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)), m_ui.errorsDock, SLOT(setVisible(bool))); connect(m_ui.errorsTreeWidget, - SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), + 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) @@ -815,6 +986,12 @@ void MainWindow::replayStateFound(ApiTraceState *state) m_nonDefaultsLookupEvent = 0; } +void MainWindow::replayThumbnailsFound(const QList &thumbnails) +{ + m_ui.callView->setUniformRowHeights(false); + m_trace->bindThumbnailsToFrames(thumbnails); +} + void MainWindow::slotGoTo() { m_searchWidget->hide(); @@ -840,6 +1017,21 @@ void MainWindow::traceError(const QString &msg) msg); } +void MainWindow::createdTrim(const QString &path) +{ + qDebug()<<"Done trimming "<hide(); @@ -990,11 +1182,14 @@ ApiTraceFrame * MainWindow::selectedFrame() const return NULL; } -void MainWindow::slotTraceChanged(ApiTraceCall *call) +void MainWindow::slotTraceChanged(ApiTraceEvent *event) { - Q_ASSERT(call); - if (call == m_selectedEvent) { - m_ui.detailsWebView->setHtml(call->toHtml()); + Q_ASSERT(event); + if (event == m_selectedEvent) { + if (event->type() == ApiTraceEvent::Call) { + ApiTraceCall *call = static_cast(event); + m_ui.detailsWebView->setHtml(call->toHtml()); + } } } @@ -1093,7 +1288,8 @@ void MainWindow::loadProgess(int percent) m_progressBar->setValue(percent); } -void MainWindow::slotSearchResult(ApiTrace::SearchResult result, +void MainWindow::slotSearchResult(const ApiTrace::SearchRequest &request, + ApiTrace::SearchResult result, ApiTraceCall *call) { switch (result) { @@ -1102,8 +1298,28 @@ void MainWindow::slotSearchResult(ApiTrace::SearchResult result, break; case ApiTrace::SearchResult_Found: { QModelIndex index = m_proxyModel->indexForCall(call); - m_ui.callView->setCurrentIndex(index); - m_searchWidget->setFound(true); + + if (index.isValid()) { + m_ui.callView->setCurrentIndex(index); + m_searchWidget->setFound(true); + } else { + //call is filtered out, so continue searching but from the + // filtered call + if (!call) { + qDebug()<<"Error: search success with no call"; + return; + } +// qDebug()<<"filtered! search from "<searchText() +// <<", call idx = "<index(); + + if (request.direction == ApiTrace::SearchRequest::Next) { + m_trace->findNext(call->parentFrame(), call, + request.text, request.cs); + } else { + m_trace->findNext(call->parentFrame(), call, + request.text, request.cs); + } + } } break; case ApiTrace::SearchResult_Wrapped: @@ -1182,6 +1398,7 @@ void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame) QModelIndex idx = m_proxyModel->indexForCall(call); if (idx.isValid()) { m_ui.callView->setCurrentIndex(idx); + m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtTop); break; } ++itr; @@ -1204,6 +1421,7 @@ void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame) 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()); @@ -1211,9 +1429,12 @@ void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame) 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.")); }