1 #include "mainwindow.h"
4 #include "apitracecall.h"
5 #include "apicalldelegate.h"
6 #include "apitracemodel.h"
7 #include "apitracefilter.h"
8 #include "argumentseditor.h"
9 #include "imageviewer.h"
10 #include "jumpwidget.h"
11 #include "profiledialog.h"
13 #include "searchwidget.h"
14 #include "settingsdialog.h"
15 #include "shaderssourcewidget.h"
16 #include "tracedialog.h"
17 #include "traceprocess.h"
18 #include "trimprocess.h"
19 #include "thumbnail.h"
20 #include "ui_retracerdialog.h"
21 #include "ui_profilereplaydialog.h"
22 #include "vertexdatainterpreter.h"
23 #include "trace_profiler.hpp"
26 #include <QApplication>
28 #include <QDesktopServices>
29 #include <QDesktopWidget>
31 #include <QFileDialog>
33 #include <QMessageBox>
34 #include <QProgressBar>
37 #include <QVBoxLayout>
42 MainWindow::MainWindow()
48 m_nonDefaultsLookupEvent(0)
51 updateActionsState(false);
56 MainWindow::~MainWindow()
65 void MainWindow::createTrace()
67 if (!m_traceProcess->canTrace()) {
71 tr("Current configuration doesn't support tracing."));
76 if (dialog.exec() == QDialog::Accepted) {
77 qDebug()<< "App : " <<dialog.applicationPath();
78 qDebug()<< " Arguments: "<<dialog.arguments();
79 m_traceProcess->setApi(dialog.api());
80 m_traceProcess->setExecutablePath(dialog.applicationPath());
81 m_traceProcess->setArguments(dialog.arguments());
82 m_traceProcess->start();
86 void MainWindow::openTrace()
89 QFileDialog::getOpenFileName(
93 tr("Trace Files (*.trace)"));
95 if (!fileName.isEmpty() && QFile::exists(fileName)) {
96 newTraceFile(fileName);
100 void MainWindow::loadTrace(const QString &fileName, int callNum)
102 if (!QFile::exists(fileName)) {
103 QMessageBox::warning(this, tr("File Missing"),
104 tr("File '%1' doesn't exist.").arg(fileName));
108 m_initalCallNum = callNum;
109 newTraceFile(fileName);
112 void MainWindow::setRemoteTarget(const QString &host)
114 m_retracer->setRemoteTarget(host);
117 void MainWindow::callItemSelected(const QModelIndex &index)
119 ApiTraceEvent *event =
120 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
122 if (event && event->type() == ApiTraceEvent::Call) {
123 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
124 m_ui.detailsDock->setWindowTitle(
125 tr("Details View. Frame %1, Call %2")
126 .arg(call->parentFrame() ? call->parentFrame()->number : 0)
127 .arg(call->index()));
128 m_ui.detailsWebView->setHtml(call->toHtml());
129 m_ui.detailsDock->show();
130 if (call->hasBinaryData()) {
132 call->arguments()[call->binaryDataIndex()].toByteArray();
133 m_vdataInterpreter->setData(data);
135 QVector<QVariant> args = call->arguments();
136 for (int i = 0; i < call->argNames().count(); ++i) {
137 QString name = call->argNames()[i];
138 if (name == QLatin1String("stride")) {
139 int stride = args[i].toInt();
140 m_ui.vertexStrideSB->setValue(stride);
141 } else if (name == QLatin1String("size")) {
142 int components = args[i].toInt();
143 m_ui.vertexComponentsSB->setValue(components);
144 } else if (name == QLatin1String("type")) {
145 QString val = args[i].toString();
146 int textIndex = m_ui.vertexTypeCB->findText(val);
147 if (textIndex >= 0) {
148 m_ui.vertexTypeCB->setCurrentIndex(textIndex);
153 m_ui.backtraceBrowser->setText(call->backtrace());
154 m_ui.backtraceDock->setVisible(!call->backtrace().isNull());
155 m_ui.vertexDataDock->setVisible(call->hasBinaryData());
156 m_selectedEvent = call;
158 if (event && event->type() == ApiTraceEvent::Frame) {
159 m_selectedEvent = static_cast<ApiTraceFrame*>(event);
163 m_ui.detailsDock->hide();
164 m_ui.backtraceDock->hide();
165 m_ui.vertexDataDock->hide();
167 if (m_selectedEvent && m_selectedEvent->hasState()) {
170 m_ui.stateDock->hide();
174 void MainWindow::callItemActivated(const QModelIndex &index) {
178 void MainWindow::replayStart()
180 if (m_trace->isSaving()) {
181 QMessageBox::warning(
184 tr("QApiTrace is currently saving the edited trace file. "
185 "Please wait until it finishes and try again."));
190 Ui_RetracerDialog dlgUi;
193 dlgUi.doubleBufferingCB->setChecked(
194 m_retracer->isDoubleBuffered());
196 dlgUi.errorCheckCB->setChecked(
197 !m_retracer->isBenchmarking());
199 if (dlg.exec() == QDialog::Accepted) {
200 m_retracer->setDoubleBuffered(
201 dlgUi.doubleBufferingCB->isChecked());
203 m_retracer->setBenchmarking(
204 !dlgUi.errorCheckCB->isChecked());
206 m_retracer->setProfiling(false, false, false);
208 replayTrace(false, false);
212 void MainWindow::replayProfile()
214 if (m_trace->isSaving()) {
215 QMessageBox::warning(
218 tr("QApiTrace is currently saving the edited trace file. "
219 "Please wait until it finishes and try again."));
224 Ui_ProfileReplayDialog dlgUi;
227 if (dlg.exec() == QDialog::Accepted) {
228 m_retracer->setProfiling(
229 dlgUi.gpuTimesCB->isChecked(),
230 dlgUi.cpuTimesCB->isChecked(),
231 dlgUi.pixelsDrawnCB->isChecked());
233 replayTrace(false, false);
237 void MainWindow::replayStop()
240 updateActionsState(true, true);
243 void MainWindow::newTraceFile(const QString &fileName)
245 qDebug()<< "Loading : " <<fileName;
247 m_progressBar->setValue(0);
248 m_trace->setFileName(fileName);
250 if (fileName.isEmpty()) {
251 updateActionsState(false);
252 setWindowTitle(tr("QApiTrace"));
254 updateActionsState(true);
255 QFileInfo info(fileName);
257 tr("QApiTrace - %1").arg(info.fileName()));
261 void MainWindow::replayFinished(const QString &message)
263 updateActionsState(true);
264 m_progressBar->hide();
265 statusBar()->showMessage(message, 2000);
267 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
268 m_ui.errorsDock->setVisible(m_trace->hasErrors());
269 if (!m_trace->hasErrors()) {
270 m_ui.errorsTreeWidget->clear();
274 void MainWindow::replayError(const QString &message)
276 updateActionsState(true);
278 m_nonDefaultsLookupEvent = 0;
280 m_progressBar->hide();
281 statusBar()->showMessage(
282 tr("Replaying unsuccessful."), 2000);
283 QMessageBox::warning(
284 this, tr("Replay Failed"), message);
287 void MainWindow::startedLoadingTrace()
290 m_progressBar->show();
291 QFileInfo info(m_trace->fileName());
292 statusBar()->showMessage(
293 tr("Loading %1...").arg(info.fileName()));
296 void MainWindow::finishedLoadingTrace()
298 m_progressBar->hide();
302 m_api = m_trace->api();
303 QFileInfo info(m_trace->fileName());
304 statusBar()->showMessage(
305 tr("Loaded %1").arg(info.fileName()), 3000);
306 if (m_initalCallNum >= 0) {
307 m_trace->findCallIndex(m_initalCallNum);
308 m_initalCallNum = -1;
312 void MainWindow::replayTrace(bool dumpState, bool dumpThumbnails)
314 if (m_trace->fileName().isEmpty()) {
318 m_retracer->setFileName(m_trace->fileName());
319 m_retracer->setAPI(m_api);
320 m_retracer->setCaptureState(dumpState);
321 m_retracer->setCaptureThumbnails(dumpThumbnails);
322 if (m_retracer->captureState() && m_selectedEvent) {
324 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
325 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
326 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
327 ApiTraceFrame *frame =
328 static_cast<ApiTraceFrame*>(m_selectedEvent);
329 if (frame->isEmpty()) {
330 //XXX i guess we could still get the current state
331 qDebug()<<"tried to get a state for an empty frame";
334 index = frame->lastCallIndex();
336 qDebug()<<"Unknown event type";
339 m_retracer->setCaptureAtCallNumber(index);
343 m_ui.actionStop->setEnabled(true);
344 m_progressBar->show();
345 if (dumpState || dumpThumbnails) {
346 if (dumpState && dumpThumbnails) {
347 statusBar()->showMessage(
348 tr("Looking up the state and capturing thumbnails..."));
349 } else if (dumpState) {
350 statusBar()->showMessage(
351 tr("Looking up the state..."));
352 } else if (dumpThumbnails) {
353 statusBar()->showMessage(
354 tr("Capturing thumbnails..."));
356 } else if (m_retracer->isProfiling()) {
357 statusBar()->showMessage(
358 tr("Profiling draw calls in trace file..."));
360 statusBar()->showMessage(
361 tr("Replaying the trace file..."));
365 void MainWindow::trimEvent()
369 if (m_trimEvent->type() == ApiTraceEvent::Call) {
370 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_trimEvent);
371 trimIndex = call->index();
372 } else if (m_trimEvent->type() == ApiTraceEvent::Frame) {
373 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(m_trimEvent);
374 const QList<ApiTraceFrame*> frames = m_trace->frames();
375 trimIndex = frame->lastCallIndex();
378 m_trimProcess->setTracePath(m_trace->fileName());
379 m_trimProcess->setTrimIndex(trimIndex);
381 m_trimProcess->start();
384 void MainWindow::lookupState()
386 if (!m_selectedEvent) {
387 QMessageBox::warning(
388 this, tr("Unknown Event"),
389 tr("To inspect the state select an event in the event list."));
392 if (m_trace->isSaving()) {
393 QMessageBox::warning(
396 tr("QApiTrace is currently saving the edited trace file. "
397 "Please wait until it finishes and try again."));
400 m_stateEvent = m_selectedEvent;
401 replayTrace(true, false);
404 void MainWindow::showThumbnails()
406 replayTrace(false, true);
409 void MainWindow::trim()
411 if (!m_selectedEvent) {
412 QMessageBox::warning(
413 this, tr("Unknown Event"),
414 tr("To trim select a frame or an event in the event list."));
417 m_trimEvent = m_selectedEvent;
422 variantToString(const QVariant &var, QString &str)
424 if (var.type() == QVariant::List) {
425 QVector<QVariant> lst = var.toList().toVector();
426 str += QLatin1String("[");
427 for (int i = 0; i < lst.count(); ++i) {
428 QVariant val = lst[i];
429 variantToString(val, str);
430 if (i < lst.count() - 1)
431 str += QLatin1String(", ");
433 str += QLatin1String("]");
434 } else if (var.type() == QVariant::Map) {
435 Q_ASSERT(!"unsupported state type");
436 } else if (var.type() == QVariant::Hash) {
437 Q_ASSERT(!"unsupported state type");
439 str += var.toString();
443 static QTreeWidgetItem *
444 variantToItem(const QString &key, const QVariant &var,
445 const QVariant &defaultVar);
448 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap,
449 QList<QTreeWidgetItem *> &items)
451 QVariantMap::const_iterator itr;
452 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
453 QString key = itr.key();
454 QVariant var = itr.value();
455 QVariant defaultVar = defaultMap[key];
457 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
465 variantListToItems(const QVector<QVariant> &lst,
466 const QVector<QVariant> &defaultLst,
467 QList<QTreeWidgetItem *> &items)
469 for (int i = 0; i < lst.count(); ++i) {
470 QString key = QString::number(i);
471 QVariant var = lst[i];
474 if (i < defaultLst.count()) {
475 defaultVar = defaultLst[i];
478 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
486 isVariantDeep(const QVariant &var)
488 if (var.type() == QVariant::List) {
489 QVector<QVariant> lst = var.toList().toVector();
490 for (int i = 0; i < lst.count(); ++i) {
491 if (isVariantDeep(lst[i])) {
496 } else if (var.type() == QVariant::Map) {
498 } else if (var.type() == QVariant::Hash) {
505 static QTreeWidgetItem *
506 variantToItem(const QString &key, const QVariant &var,
507 const QVariant &defaultVar)
509 if (var == defaultVar) {
515 bool deep = isVariantDeep(var);
517 variantToString(var, val);
520 //qDebug()<<"key = "<<key;
521 //qDebug()<<"val = "<<val;
526 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
529 QList<QTreeWidgetItem *> children;
530 if (var.type() == QVariant::Map) {
531 QVariantMap map = var.toMap();
532 QVariantMap defaultMap = defaultVar.toMap();
533 variantMapToItems(map, defaultMap, children);
535 if (var.type() == QVariant::List) {
536 QVector<QVariant> lst = var.toList().toVector();
537 QVector<QVariant> defaultLst = defaultVar.toList().toVector();
538 variantListToItems(lst, defaultLst, children);
540 item->addChildren(children);
546 static void addSurfaceItem(const ApiSurface &surface,
547 const QString &label,
548 QTreeWidgetItem *parent,
551 QIcon icon(QPixmap::fromImage(surface.thumb()));
552 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
553 item->setIcon(0, icon);
555 int width = surface.size().width();
556 int height = surface.size().height();
558 QString::fromLatin1("%1, %2, %3 x %4")
560 .arg(surface.formatName())
564 //item->setText(1, descr);
565 QLabel *l = new QLabel(descr, tree);
566 l->setWordWrap(true);
567 tree->setItemWidget(item, 1, l);
569 item->setData(0, Qt::UserRole, surface.image());
572 void MainWindow::fillStateForFrame()
574 if (!m_selectedEvent || !m_selectedEvent->hasState()) {
578 if (m_nonDefaultsLookupEvent) {
579 m_ui.nonDefaultsCB->blockSignals(true);
580 m_ui.nonDefaultsCB->setChecked(true);
581 m_ui.nonDefaultsCB->blockSignals(false);
584 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
585 QVariantMap defaultParams;
587 ApiTraceState defaultState = m_trace->defaultState();
588 defaultParams = defaultState.parameters();
591 const ApiTraceState &state = *m_selectedEvent->state();
592 m_ui.stateTreeWidget->clear();
593 QList<QTreeWidgetItem *> items;
594 variantMapToItems(state.parameters(), defaultParams, items);
595 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
597 QMap<QString, QString> shaderSources = state.shaderSources();
598 if (shaderSources.isEmpty()) {
599 m_sourcesWidget->setShaders(shaderSources);
601 m_sourcesWidget->setShaders(shaderSources);
604 m_ui.uniformsTreeWidget->clear();
605 QList<QTreeWidgetItem *> uniformsItems;
606 variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems);
607 m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems);
609 const QList<ApiTexture> &textures =
611 const QList<ApiFramebuffer> &fbos =
612 state.framebuffers();
614 m_ui.surfacesTreeWidget->clear();
615 if (textures.isEmpty() && fbos.isEmpty()) {
616 m_ui.surfacesTab->setDisabled(false);
618 m_ui.surfacesTreeWidget->setIconSize(QSize(THUMBNAIL_SIZE, THUMBNAIL_SIZE));
619 if (!textures.isEmpty()) {
620 QTreeWidgetItem *textureItem =
621 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
622 textureItem->setText(0, tr("Textures"));
623 if (textures.count() <= 6) {
624 textureItem->setExpanded(true);
627 for (int i = 0; i < textures.count(); ++i) {
628 const ApiTexture &texture =
630 addSurfaceItem(texture, texture.label(),
632 m_ui.surfacesTreeWidget);
635 if (!fbos.isEmpty()) {
636 QTreeWidgetItem *fboItem =
637 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
638 fboItem->setText(0, tr("Framebuffers"));
639 if (fbos.count() <= 6) {
640 fboItem->setExpanded(true);
643 for (int i = 0; i < fbos.count(); ++i) {
644 const ApiFramebuffer &fbo =
646 addSurfaceItem(fbo, fbo.type(),
648 m_ui.surfacesTreeWidget);
651 m_ui.surfacesTab->setEnabled(true);
653 m_ui.stateDock->show();
656 void MainWindow::showSettings()
658 SettingsDialog dialog;
659 dialog.setFilterModel(m_proxyModel);
664 void MainWindow::openHelp(const QUrl &url)
666 QDesktopServices::openUrl(url);
669 void MainWindow::showSurfacesMenu(const QPoint &pos)
671 QTreeWidget *tree = m_ui.surfacesTreeWidget;
672 QTreeWidgetItem *item = tree->itemAt(pos);
677 QMenu menu(tr("Surfaces"), this);
679 QAction *act = menu.addAction(tr("View Image"));
680 act->setStatusTip(tr("View the currently selected surface"));
681 connect(act, SIGNAL(triggered()),
682 SLOT(showSelectedSurface()));
684 act = menu.addAction(tr("Save Image"));
685 act->setStatusTip(tr("Save the currently selected surface"));
686 connect(act, SIGNAL(triggered()),
687 SLOT(saveSelectedSurface()));
689 menu.exec(tree->viewport()->mapToGlobal(pos));
692 void MainWindow::showSelectedSurface()
694 QTreeWidgetItem *item =
695 m_ui.surfacesTreeWidget->currentItem();
701 ImageViewer *viewer = new ImageViewer(this);
704 if (selectedCall()) {
705 title = tr("QApiTrace - Surface at %1 (%2)")
706 .arg(selectedCall()->name())
707 .arg(selectedCall()->index());
709 title = tr("QApiTrace - Surface Viewer");
711 viewer->setWindowTitle(title);
713 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
715 QVariant var = item->data(0, Qt::UserRole);
716 QImage img = var.value<QImage>();
717 viewer->setImage(img);
721 viewer->activateWindow();
724 void MainWindow::initObjects()
726 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
727 m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
729 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
730 QVBoxLayout *layout = new QVBoxLayout;
731 layout->addWidget(m_sourcesWidget);
732 m_ui.shadersTab->setLayout(layout);
734 m_trace = new ApiTrace();
735 m_retracer = new Retracer(this);
737 m_vdataInterpreter = new VertexDataInterpreter(this);
738 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
739 m_vdataInterpreter->setStride(
740 m_ui.vertexStrideSB->value());
741 m_vdataInterpreter->setComponents(
742 m_ui.vertexComponentsSB->value());
743 m_vdataInterpreter->setStartingOffset(
744 m_ui.startingOffsetSB->value());
745 m_vdataInterpreter->setTypeFromString(
746 m_ui.vertexTypeCB->currentText());
748 m_model = new ApiTraceModel();
749 m_model->setApiTrace(m_trace);
750 m_proxyModel = new ApiTraceFilter();
751 m_proxyModel->setSourceModel(m_model);
752 m_ui.callView->setModel(m_proxyModel);
753 m_ui.callView->setItemDelegate(
754 new ApiCallDelegate(m_ui.callView));
755 m_ui.callView->resizeColumnToContents(0);
756 m_ui.callView->header()->swapSections(0, 1);
757 m_ui.callView->setColumnWidth(1, 42);
758 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
760 m_progressBar = new QProgressBar();
761 m_progressBar->setRange(0, 100);
762 statusBar()->addPermanentWidget(m_progressBar);
763 m_progressBar->hide();
765 m_argsEditor = new ArgumentsEditor(this);
767 m_ui.detailsDock->hide();
768 m_ui.backtraceDock->hide();
769 m_ui.errorsDock->hide();
770 m_ui.vertexDataDock->hide();
771 m_ui.stateDock->hide();
772 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
774 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
775 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
776 tabifyDockWidget(m_ui.detailsDock, m_ui.backtraceDock);
778 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
780 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
781 QWebPage::DelegateExternalLinks);
783 m_jumpWidget = new JumpWidget(this);
784 m_ui.centralLayout->addWidget(m_jumpWidget);
785 m_jumpWidget->hide();
787 m_searchWidget = new SearchWidget(this);
788 m_ui.centralLayout->addWidget(m_searchWidget);
789 m_searchWidget->hide();
791 m_traceProcess = new TraceProcess(this);
792 m_trimProcess = new TrimProcess(this);
794 m_profileDialog = new ProfileDialog();
797 void MainWindow::initConnections()
799 connect(m_trace, SIGNAL(startedLoadingTrace()),
800 this, SLOT(startedLoadingTrace()));
801 connect(m_trace, SIGNAL(loaded(int)),
802 this, SLOT(loadProgess(int)));
803 connect(m_trace, SIGNAL(finishedLoadingTrace()),
804 this, SLOT(finishedLoadingTrace()));
805 connect(m_trace, SIGNAL(startedSaving()),
806 this, SLOT(slotStartedSaving()));
807 connect(m_trace, SIGNAL(saved()),
808 this, SLOT(slotSaved()));
809 connect(m_trace, SIGNAL(changed(ApiTraceEvent*)),
810 this, SLOT(slotTraceChanged(ApiTraceEvent*)));
811 connect(m_trace, SIGNAL(findResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)),
812 this, SLOT(slotSearchResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)));
813 connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)),
814 this, SLOT(slotFoundFrameStart(ApiTraceFrame*)));
815 connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)),
816 this, SLOT(slotFoundFrameEnd(ApiTraceFrame*)));
817 connect(m_trace, SIGNAL(foundCallIndex(ApiTraceCall*)),
818 this, SLOT(slotJumpToResult(ApiTraceCall*)));
820 connect(m_retracer, SIGNAL(finished(const QString&)),
821 this, SLOT(replayFinished(const QString&)));
822 connect(m_retracer, SIGNAL(error(const QString&)),
823 this, SLOT(replayError(const QString&)));
824 connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
825 this, SLOT(replayStateFound(ApiTraceState*)));
826 connect(m_retracer, SIGNAL(foundProfile(trace::Profile*)),
827 this, SLOT(replayProfileFound(trace::Profile*)));
828 connect(m_retracer, SIGNAL(foundThumbnails(const QList<QImage>&)),
829 this, SLOT(replayThumbnailsFound(const QList<QImage>&)));
830 connect(m_retracer, SIGNAL(retraceErrors(const QList<ApiTraceError>&)),
831 this, SLOT(slotRetraceErrors(const QList<ApiTraceError>&)));
833 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
834 m_vdataInterpreter, SLOT(interpretData()));
835 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
836 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
837 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
838 m_vdataInterpreter, SLOT(setStride(int)));
839 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
840 m_vdataInterpreter, SLOT(setComponents(int)));
841 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
842 m_vdataInterpreter, SLOT(setStartingOffset(int)));
845 connect(m_ui.actionNew, SIGNAL(triggered()),
846 this, SLOT(createTrace()));
847 connect(m_ui.actionOpen, SIGNAL(triggered()),
848 this, SLOT(openTrace()));
849 connect(m_ui.actionQuit, SIGNAL(triggered()),
850 this, SLOT(close()));
852 connect(m_ui.actionFind, SIGNAL(triggered()),
853 this, SLOT(slotSearch()));
854 connect(m_ui.actionGo, SIGNAL(triggered()),
855 this, SLOT(slotGoTo()));
856 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
857 this, SLOT(slotGoFrameStart()));
858 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
859 this, SLOT(slotGoFrameEnd()));
861 connect(m_ui.actionReplay, SIGNAL(triggered()),
862 this, SLOT(replayStart()));
863 connect(m_ui.actionProfile, SIGNAL(triggered()),
864 this, SLOT(replayProfile()));
865 connect(m_ui.actionStop, SIGNAL(triggered()),
866 this, SLOT(replayStop()));
867 connect(m_ui.actionLookupState, SIGNAL(triggered()),
868 this, SLOT(lookupState()));
869 connect(m_ui.actionTrim, SIGNAL(triggered()),
871 connect(m_ui.actionShowThumbnails, SIGNAL(triggered()),
872 this, SLOT(showThumbnails()));
873 connect(m_ui.actionOptions, SIGNAL(triggered()),
874 this, SLOT(showSettings()));
876 connect(m_ui.callView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
877 this, SLOT(callItemSelected(const QModelIndex &)));
878 connect(m_ui.callView, SIGNAL(doubleClicked(const QModelIndex &)),
879 this, SLOT(callItemActivated(const QModelIndex &)));
880 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
881 this, SLOT(customContextMenuRequested(QPoint)));
883 connect(m_ui.surfacesTreeWidget,
884 SIGNAL(customContextMenuRequested(const QPoint &)),
885 SLOT(showSurfacesMenu(const QPoint &)));
886 connect(m_ui.surfacesTreeWidget,
887 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
888 SLOT(showSelectedSurface()));
890 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
891 this, SLOT(openHelp(const QUrl&)));
893 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
894 this, SLOT(fillState(bool)));
896 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
897 SLOT(slotJumpTo(int)));
899 connect(m_searchWidget,
900 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
901 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
902 connect(m_searchWidget,
903 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
904 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
906 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
907 SLOT(createdTrace(const QString&)));
908 connect(m_traceProcess, SIGNAL(error(const QString&)),
909 SLOT(traceError(const QString&)));
911 connect(m_trimProcess, SIGNAL(trimmedFile(const QString&)),
912 SLOT(createdTrim(const QString&)));
913 connect(m_trimProcess, SIGNAL(error(const QString&)),
914 SLOT(trimError(const QString&)));
916 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
917 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
918 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
919 m_ui.errorsDock, SLOT(setVisible(bool)));
920 connect(m_ui.errorsTreeWidget,
921 SIGNAL(itemActivated(QTreeWidgetItem*, int)),
922 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
924 connect(m_ui.actionShowProfileDialog, SIGNAL(triggered(bool)),
925 m_profileDialog, SLOT(show()));
926 connect(m_profileDialog, SIGNAL(jumpToCall(int)),
927 this, SLOT(slotJumpTo(int)));
930 void MainWindow::updateActionsState(bool traceLoaded, bool stopped)
934 m_ui.actionFind ->setEnabled(true);
935 m_ui.actionGo ->setEnabled(true);
936 m_ui.actionGoFrameStart ->setEnabled(true);
937 m_ui.actionGoFrameEnd ->setEnabled(true);
941 m_ui.actionStop->setEnabled(false);
942 m_ui.actionReplay->setEnabled(true);
945 m_ui.actionStop->setEnabled(true);
946 m_ui.actionReplay->setEnabled(false);
949 m_ui.actionProfile ->setEnabled(true);
950 m_ui.actionLookupState ->setEnabled(true);
951 m_ui.actionShowThumbnails->setEnabled(true);
952 m_ui.actionTrim ->setEnabled(true);
956 m_ui.actionFind ->setEnabled(false);
957 m_ui.actionGo ->setEnabled(false);
958 m_ui.actionGoFrameStart ->setEnabled(false);
959 m_ui.actionGoFrameEnd ->setEnabled(false);
962 m_ui.actionReplay ->setEnabled(false);
963 m_ui.actionProfile ->setEnabled(false);
964 m_ui.actionStop ->setEnabled(false);
965 m_ui.actionLookupState ->setEnabled(false);
966 m_ui.actionShowThumbnails->setEnabled(false);
967 m_ui.actionTrim ->setEnabled(false);
971 void MainWindow::closeEvent(QCloseEvent * event)
973 m_profileDialog->close();
974 QMainWindow::closeEvent(event);
977 void MainWindow::replayProfileFound(trace::Profile *profile)
979 m_ui.actionShowProfileDialog->setEnabled(true);
980 m_profileDialog->setProfile(profile);
981 m_profileDialog->show();
982 m_profileDialog->activateWindow();
983 m_profileDialog->setFocus();
986 void MainWindow::replayStateFound(ApiTraceState *state)
988 m_stateEvent->setState(state);
989 m_model->stateSetOnEvent(m_stateEvent);
990 if (m_selectedEvent == m_stateEvent ||
991 m_nonDefaultsLookupEvent == m_selectedEvent) {
994 m_ui.stateDock->hide();
996 m_nonDefaultsLookupEvent = 0;
999 void MainWindow::replayThumbnailsFound(const QList<QImage> &thumbnails)
1001 m_ui.callView->setUniformRowHeights(false);
1002 m_trace->bindThumbnailsToFrames(thumbnails);
1005 void MainWindow::slotGoTo()
1007 m_searchWidget->hide();
1008 m_jumpWidget->show();
1011 void MainWindow::slotJumpTo(int callNum)
1013 m_trace->findCallIndex(callNum);
1016 void MainWindow::createdTrace(const QString &path)
1018 qDebug()<<"Done tracing "<<path;
1022 void MainWindow::traceError(const QString &msg)
1024 QMessageBox::warning(
1026 tr("Tracing Error"),
1030 void MainWindow::createdTrim(const QString &path)
1032 qDebug()<<"Done trimming "<<path;
1037 void MainWindow::trimError(const QString &msg)
1039 QMessageBox::warning(
1045 void MainWindow::slotSearch()
1047 m_jumpWidget->hide();
1048 m_searchWidget->show();
1051 void MainWindow::slotSearchNext(const QString &str,
1052 Qt::CaseSensitivity sensitivity)
1054 ApiTraceCall *call = currentCall();
1055 ApiTraceFrame *frame = currentFrame();
1057 Q_ASSERT(call || frame);
1059 frame = call->parentFrame();
1063 m_trace->findNext(frame, call, str, sensitivity);
1066 void MainWindow::slotSearchPrev(const QString &str,
1067 Qt::CaseSensitivity sensitivity)
1069 ApiTraceCall *call = currentCall();
1070 ApiTraceFrame *frame = currentFrame();
1072 Q_ASSERT(call || frame);
1074 frame = call->parentFrame();
1078 m_trace->findPrev(frame, call, str, sensitivity);
1081 void MainWindow::fillState(bool nonDefaults)
1084 ApiTraceState defaultState = m_trace->defaultState();
1085 if (defaultState.isEmpty()) {
1086 m_ui.nonDefaultsCB->blockSignals(true);
1087 m_ui.nonDefaultsCB->setChecked(false);
1088 m_ui.nonDefaultsCB->blockSignals(false);
1089 ApiTraceFrame *firstFrame =
1090 m_trace->frameAt(0);
1094 if (!firstFrame->isLoaded()) {
1095 m_trace->loadFrame(firstFrame);
1098 ApiTraceCall *firstCall = firstFrame->calls().first();
1099 ApiTraceEvent *oldSelected = m_selectedEvent;
1100 m_nonDefaultsLookupEvent = m_selectedEvent;
1101 m_selectedEvent = firstCall;
1103 m_selectedEvent = oldSelected;
1106 fillStateForFrame();
1109 void MainWindow::customContextMenuRequested(QPoint pos)
1111 QModelIndex index = m_ui.callView->indexAt(pos);
1113 callItemSelected(index);
1114 if (!index.isValid()) {
1118 ApiTraceEvent *event =
1119 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1125 menu.addAction(QIcon(":/resources/media-record.png"),
1126 tr("Lookup state"), this, SLOT(lookupState()));
1127 if (event->type() == ApiTraceEvent::Call) {
1128 menu.addAction(tr("Edit"), this, SLOT(editCall()));
1131 menu.exec(QCursor::pos());
1134 void MainWindow::editCall()
1136 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
1137 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1138 m_argsEditor->setCall(call);
1139 m_argsEditor->show();
1143 void MainWindow::slotStartedSaving()
1145 m_progressBar->show();
1146 statusBar()->showMessage(
1147 tr("Saving to %1").arg(m_trace->fileName()));
1150 void MainWindow::slotSaved()
1152 statusBar()->showMessage(
1153 tr("Saved to %1").arg(m_trace->fileName()), 2000);
1154 m_progressBar->hide();
1157 void MainWindow::slotGoFrameStart()
1159 ApiTraceFrame *frame = currentFrame();
1160 ApiTraceCall *call = currentCall();
1162 if (!frame && call) {
1163 frame = call->parentFrame();
1166 m_trace->findFrameStart(frame);
1169 void MainWindow::slotGoFrameEnd()
1171 ApiTraceFrame *frame = currentFrame();
1172 ApiTraceCall *call = currentCall();
1174 if (!frame && call) {
1175 frame = call->parentFrame();
1178 m_trace->findFrameEnd(frame);
1181 ApiTraceFrame * MainWindow::selectedFrame() const
1183 if (m_selectedEvent) {
1184 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1185 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1187 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1188 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1189 return call->parentFrame();
1195 void MainWindow::slotTraceChanged(ApiTraceEvent *event)
1198 if (event == m_selectedEvent) {
1199 if (event->type() == ApiTraceEvent::Call) {
1200 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
1201 m_ui.detailsWebView->setHtml(call->toHtml());
1206 void MainWindow::slotRetraceErrors(const QList<ApiTraceError> &errors)
1208 m_ui.errorsTreeWidget->clear();
1210 foreach(ApiTraceError error, errors) {
1211 m_trace->setCallError(error);
1213 QTreeWidgetItem *item =
1214 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1215 item->setData(0, Qt::DisplayRole, error.callIndex);
1216 item->setData(0, Qt::UserRole, error.callIndex);
1217 QString type = error.type;
1218 type[0] = type[0].toUpper();
1219 item->setData(1, Qt::DisplayRole, type);
1220 item->setData(2, Qt::DisplayRole, error.message);
1224 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1228 current->data(0, Qt::UserRole).toInt();
1229 m_trace->findCallIndex(callIndex);
1233 ApiTraceCall * MainWindow::selectedCall() const
1235 if (m_selectedEvent &&
1236 m_selectedEvent->type() == ApiTraceEvent::Call) {
1237 return static_cast<ApiTraceCall*>(m_selectedEvent);
1242 void MainWindow::saveSelectedSurface()
1244 QTreeWidgetItem *item =
1245 m_ui.surfacesTreeWidget->currentItem();
1247 if (!item || !m_trace) {
1251 QVariant var = item->data(0, Qt::UserRole);
1252 QImage img = var.value<QImage>();
1255 if (selectedCall()) {
1256 imageIndex = tr("_call_%1")
1257 .arg(selectedCall()->index());
1258 } else if (selectedFrame()) {
1259 ApiTraceCall *firstCall = selectedFrame()->call(0);
1261 imageIndex = tr("_frame_%1")
1262 .arg(firstCall->index());
1264 qDebug()<<"unknown frame number";
1265 imageIndex = tr("_frame_%1")
1266 .arg(firstCall->index());
1270 //which of the surfaces are we saving
1271 QTreeWidgetItem *parent = item->parent();
1273 m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
1274 if (parentIndex < 0) {
1279 childIndex = parent->indexOfChild(item);
1281 childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
1286 tr("%1%2-%3_%4.png")
1287 .arg(m_trace->fileName())
1291 //qDebug()<<"save "<<fileName;
1292 img.save(fileName, "PNG");
1293 statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
1296 void MainWindow::loadProgess(int percent)
1298 m_progressBar->setValue(percent);
1301 void MainWindow::slotSearchResult(const ApiTrace::SearchRequest &request,
1302 ApiTrace::SearchResult result,
1306 case ApiTrace::SearchResult_NotFound:
1307 m_searchWidget->setFound(false);
1309 case ApiTrace::SearchResult_Found: {
1310 QModelIndex index = m_proxyModel->indexForCall(call);
1312 if (index.isValid()) {
1313 m_ui.callView->setCurrentIndex(index);
1314 m_searchWidget->setFound(true);
1316 //call is filtered out, so continue searching but from the
1319 qDebug()<<"Error: search success with no call";
1322 // qDebug()<<"filtered! search from "<<call->searchText()
1323 // <<", call idx = "<<call->index();
1325 if (request.direction == ApiTrace::SearchRequest::Next) {
1326 m_trace->findNext(call->parentFrame(), call,
1327 request.text, request.cs);
1329 m_trace->findNext(call->parentFrame(), call,
1330 request.text, request.cs);
1335 case ApiTrace::SearchResult_Wrapped:
1336 m_searchWidget->setFound(false);
1341 ApiTraceFrame * MainWindow::currentFrame() const
1343 QModelIndex index = m_ui.callView->currentIndex();
1344 ApiTraceEvent *event = 0;
1346 if (!index.isValid()) {
1347 index = m_proxyModel->index(0, 0, QModelIndex());
1348 if (!index.isValid()) {
1349 qDebug()<<"no currently valid index";
1354 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1360 ApiTraceFrame *frame = 0;
1361 if (event->type() == ApiTraceCall::Frame) {
1362 frame = static_cast<ApiTraceFrame*>(event);
1367 ApiTraceCall * MainWindow::currentCall() const
1369 QModelIndex index = m_ui.callView->currentIndex();
1370 ApiTraceEvent *event = 0;
1372 if (!index.isValid()) {
1373 index = m_proxyModel->index(0, 0, QModelIndex());
1374 if (!index.isValid()) {
1375 qDebug()<<"no currently valid index";
1380 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1386 ApiTraceCall *call = 0;
1387 if (event->type() == ApiTraceCall::Call) {
1388 call = static_cast<ApiTraceCall*>(event);
1395 void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
1397 Q_ASSERT(frame->isLoaded());
1398 if (!frame || frame->isEmpty()) {
1402 QVector<ApiTraceCall*>::const_iterator itr;
1403 QVector<ApiTraceCall*> calls = frame->calls();
1405 itr = calls.constBegin();
1406 while (itr != calls.constEnd()) {
1407 ApiTraceCall *call = *itr;
1408 QModelIndex idx = m_proxyModel->indexForCall(call);
1409 if (idx.isValid()) {
1410 m_ui.callView->setCurrentIndex(idx);
1411 m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtTop);
1418 void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame)
1420 Q_ASSERT(frame->isLoaded());
1421 if (!frame || frame->isEmpty()) {
1424 QVector<ApiTraceCall*>::const_iterator itr;
1425 QVector<ApiTraceCall*> calls = frame->calls();
1427 itr = calls.constEnd();
1430 ApiTraceCall *call = *itr;
1431 QModelIndex idx = m_proxyModel->indexForCall(call);
1432 if (idx.isValid()) {
1433 m_ui.callView->setCurrentIndex(idx);
1434 m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtBottom);
1437 } while (itr != calls.constBegin());
1440 void MainWindow::slotJumpToResult(ApiTraceCall *call)
1442 QModelIndex idx = m_proxyModel->indexForCall(call);
1443 if (idx.isValid()) {
1445 m_ui.callView->setFocus();
1446 m_ui.callView->setCurrentIndex(idx);
1447 m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
1449 statusBar()->showMessage(tr("Call has been filtered out."));
1453 #include "mainwindow.moc"