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 dlgUi.singlethreadCB->setChecked(
200 m_retracer->isSinglethread());
202 if (dlg.exec() == QDialog::Accepted) {
203 m_retracer->setDoubleBuffered(
204 dlgUi.doubleBufferingCB->isChecked());
206 m_retracer->setBenchmarking(
207 !dlgUi.errorCheckCB->isChecked());
209 m_retracer->setSinglethread(
210 dlgUi.singlethreadCB->isChecked());
212 m_retracer->setProfiling(false, false, false);
214 replayTrace(false, false);
218 void MainWindow::replayProfile()
220 if (m_trace->isSaving()) {
221 QMessageBox::warning(
224 tr("QApiTrace is currently saving the edited trace file. "
225 "Please wait until it finishes and try again."));
230 Ui_ProfileReplayDialog dlgUi;
233 if (dlg.exec() == QDialog::Accepted) {
234 m_retracer->setProfiling(
235 dlgUi.gpuTimesCB->isChecked(),
236 dlgUi.cpuTimesCB->isChecked(),
237 dlgUi.pixelsDrawnCB->isChecked());
239 replayTrace(false, false);
243 void MainWindow::replayStop()
246 updateActionsState(true, true);
249 void MainWindow::newTraceFile(const QString &fileName)
251 qDebug()<< "Loading : " <<fileName;
253 m_progressBar->setValue(0);
254 m_trace->setFileName(fileName);
256 if (fileName.isEmpty()) {
257 updateActionsState(false);
258 setWindowTitle(tr("QApiTrace"));
260 updateActionsState(true);
261 QFileInfo info(fileName);
263 tr("QApiTrace - %1").arg(info.fileName()));
267 void MainWindow::replayFinished(const QString &message)
269 updateActionsState(true);
270 m_progressBar->hide();
271 statusBar()->showMessage(message, 2000);
273 m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors());
274 m_ui.errorsDock->setVisible(m_trace->hasErrors());
275 if (!m_trace->hasErrors()) {
276 m_ui.errorsTreeWidget->clear();
280 void MainWindow::replayError(const QString &message)
282 updateActionsState(true);
284 m_nonDefaultsLookupEvent = 0;
286 m_progressBar->hide();
287 statusBar()->showMessage(
288 tr("Replaying unsuccessful."), 2000);
289 QMessageBox::warning(
290 this, tr("Replay Failed"), message);
293 void MainWindow::startedLoadingTrace()
296 m_progressBar->show();
297 QFileInfo info(m_trace->fileName());
298 statusBar()->showMessage(
299 tr("Loading %1...").arg(info.fileName()));
302 void MainWindow::finishedLoadingTrace()
304 m_progressBar->hide();
308 m_api = m_trace->api();
309 QFileInfo info(m_trace->fileName());
310 statusBar()->showMessage(
311 tr("Loaded %1").arg(info.fileName()), 3000);
312 if (m_initalCallNum >= 0) {
313 m_trace->findCallIndex(m_initalCallNum);
314 m_initalCallNum = -1;
318 void MainWindow::replayTrace(bool dumpState, bool dumpThumbnails)
320 if (m_trace->fileName().isEmpty()) {
324 m_retracer->setFileName(m_trace->fileName());
325 m_retracer->setAPI(m_api);
326 m_retracer->setCaptureState(dumpState);
327 m_retracer->setCaptureThumbnails(dumpThumbnails);
328 if (m_retracer->captureState() && m_selectedEvent) {
330 if (m_selectedEvent->type() == ApiTraceEvent::Call) {
331 index = static_cast<ApiTraceCall*>(m_selectedEvent)->index();
332 } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
333 ApiTraceFrame *frame =
334 static_cast<ApiTraceFrame*>(m_selectedEvent);
335 if (frame->isEmpty()) {
336 //XXX i guess we could still get the current state
337 qDebug()<<"tried to get a state for an empty frame";
340 index = frame->lastCallIndex();
342 qDebug()<<"Unknown event type";
345 m_retracer->setCaptureAtCallNumber(index);
349 m_ui.actionStop->setEnabled(true);
350 m_progressBar->show();
351 if (dumpState || dumpThumbnails) {
352 if (dumpState && dumpThumbnails) {
353 statusBar()->showMessage(
354 tr("Looking up the state and capturing thumbnails..."));
355 } else if (dumpState) {
356 statusBar()->showMessage(
357 tr("Looking up the state..."));
358 } else if (dumpThumbnails) {
359 statusBar()->showMessage(
360 tr("Capturing thumbnails..."));
362 } else if (m_retracer->isProfiling()) {
363 statusBar()->showMessage(
364 tr("Profiling draw calls in trace file..."));
366 statusBar()->showMessage(
367 tr("Replaying the trace file..."));
371 void MainWindow::trimEvent()
375 if (m_trimEvent->type() == ApiTraceEvent::Call) {
376 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_trimEvent);
377 trimIndex = call->index();
378 } else if (m_trimEvent->type() == ApiTraceEvent::Frame) {
379 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(m_trimEvent);
380 const QList<ApiTraceFrame*> frames = m_trace->frames();
381 trimIndex = frame->lastCallIndex();
384 m_trimProcess->setTracePath(m_trace->fileName());
385 m_trimProcess->setTrimIndex(trimIndex);
387 m_trimProcess->start();
390 void MainWindow::lookupState()
392 if (!m_selectedEvent) {
393 QMessageBox::warning(
394 this, tr("Unknown Event"),
395 tr("To inspect the state select an event in the event list."));
398 if (m_trace->isSaving()) {
399 QMessageBox::warning(
402 tr("QApiTrace is currently saving the edited trace file. "
403 "Please wait until it finishes and try again."));
406 m_stateEvent = m_selectedEvent;
407 replayTrace(true, false);
410 void MainWindow::showThumbnails()
412 replayTrace(false, true);
415 void MainWindow::trim()
417 if (!m_selectedEvent) {
418 QMessageBox::warning(
419 this, tr("Unknown Event"),
420 tr("To trim select a frame or an event in the event list."));
423 m_trimEvent = m_selectedEvent;
428 variantToString(const QVariant &var, QString &str)
430 if (var.type() == QVariant::List) {
431 QVector<QVariant> lst = var.toList().toVector();
432 str += QLatin1String("[");
433 for (int i = 0; i < lst.count(); ++i) {
434 QVariant val = lst[i];
435 variantToString(val, str);
436 if (i < lst.count() - 1)
437 str += QLatin1String(", ");
439 str += QLatin1String("]");
440 } else if (var.type() == QVariant::Map) {
441 Q_ASSERT(!"unsupported state type");
442 } else if (var.type() == QVariant::Hash) {
443 Q_ASSERT(!"unsupported state type");
445 str += var.toString();
449 static QTreeWidgetItem *
450 variantToItem(const QString &key, const QVariant &var,
451 const QVariant &defaultVar);
454 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap,
455 QList<QTreeWidgetItem *> &items)
457 QVariantMap::const_iterator itr;
458 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
459 QString key = itr.key();
460 QVariant var = itr.value();
461 QVariant defaultVar = defaultMap[key];
463 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
471 variantListToItems(const QVector<QVariant> &lst,
472 const QVector<QVariant> &defaultLst,
473 QList<QTreeWidgetItem *> &items)
475 for (int i = 0; i < lst.count(); ++i) {
476 QString key = QString::number(i);
477 QVariant var = lst[i];
480 if (i < defaultLst.count()) {
481 defaultVar = defaultLst[i];
484 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
492 isVariantDeep(const QVariant &var)
494 if (var.type() == QVariant::List) {
495 QVector<QVariant> lst = var.toList().toVector();
496 for (int i = 0; i < lst.count(); ++i) {
497 if (isVariantDeep(lst[i])) {
502 } else if (var.type() == QVariant::Map) {
504 } else if (var.type() == QVariant::Hash) {
511 static QTreeWidgetItem *
512 variantToItem(const QString &key, const QVariant &var,
513 const QVariant &defaultVar)
515 if (var == defaultVar) {
521 bool deep = isVariantDeep(var);
523 variantToString(var, val);
526 //qDebug()<<"key = "<<key;
527 //qDebug()<<"val = "<<val;
532 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
535 QList<QTreeWidgetItem *> children;
536 if (var.type() == QVariant::Map) {
537 QVariantMap map = var.toMap();
538 QVariantMap defaultMap = defaultVar.toMap();
539 variantMapToItems(map, defaultMap, children);
541 if (var.type() == QVariant::List) {
542 QVector<QVariant> lst = var.toList().toVector();
543 QVector<QVariant> defaultLst = defaultVar.toList().toVector();
544 variantListToItems(lst, defaultLst, children);
546 item->addChildren(children);
552 static void addSurfaceItem(const ApiSurface &surface,
553 const QString &label,
554 QTreeWidgetItem *parent,
557 QIcon icon(QPixmap::fromImage(surface.thumb()));
558 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
559 item->setIcon(0, icon);
561 int width = surface.size().width();
562 int height = surface.size().height();
564 QString::fromLatin1("%1, %2, %3 x %4")
566 .arg(surface.formatName())
570 //item->setText(1, descr);
571 QLabel *l = new QLabel(descr, tree);
572 l->setWordWrap(true);
573 tree->setItemWidget(item, 1, l);
575 item->setData(0, Qt::UserRole, surface.image());
578 void MainWindow::fillStateForFrame()
580 if (!m_selectedEvent || !m_selectedEvent->hasState()) {
584 if (m_nonDefaultsLookupEvent) {
585 m_ui.nonDefaultsCB->blockSignals(true);
586 m_ui.nonDefaultsCB->setChecked(true);
587 m_ui.nonDefaultsCB->blockSignals(false);
590 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
591 QVariantMap defaultParams;
593 ApiTraceState defaultState = m_trace->defaultState();
594 defaultParams = defaultState.parameters();
597 const ApiTraceState &state = *m_selectedEvent->state();
598 m_ui.stateTreeWidget->clear();
599 QList<QTreeWidgetItem *> items;
600 variantMapToItems(state.parameters(), defaultParams, items);
601 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
603 QMap<QString, QString> shaderSources = state.shaderSources();
604 if (shaderSources.isEmpty()) {
605 m_sourcesWidget->setShaders(shaderSources);
607 m_sourcesWidget->setShaders(shaderSources);
610 m_ui.uniformsTreeWidget->clear();
611 QList<QTreeWidgetItem *> uniformsItems;
612 variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems);
613 m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems);
615 const QList<ApiTexture> &textures =
617 const QList<ApiFramebuffer> &fbos =
618 state.framebuffers();
620 m_ui.surfacesTreeWidget->clear();
621 if (textures.isEmpty() && fbos.isEmpty()) {
622 m_ui.surfacesTab->setDisabled(false);
624 m_ui.surfacesTreeWidget->setIconSize(QSize(THUMBNAIL_SIZE, THUMBNAIL_SIZE));
625 if (!textures.isEmpty()) {
626 QTreeWidgetItem *textureItem =
627 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
628 textureItem->setText(0, tr("Textures"));
629 if (textures.count() <= 6) {
630 textureItem->setExpanded(true);
633 for (int i = 0; i < textures.count(); ++i) {
634 const ApiTexture &texture =
636 addSurfaceItem(texture, texture.label(),
638 m_ui.surfacesTreeWidget);
641 if (!fbos.isEmpty()) {
642 QTreeWidgetItem *fboItem =
643 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
644 fboItem->setText(0, tr("Framebuffers"));
645 if (fbos.count() <= 6) {
646 fboItem->setExpanded(true);
649 for (int i = 0; i < fbos.count(); ++i) {
650 const ApiFramebuffer &fbo =
652 addSurfaceItem(fbo, fbo.type(),
654 m_ui.surfacesTreeWidget);
657 m_ui.surfacesTab->setEnabled(true);
659 m_ui.stateDock->show();
662 void MainWindow::showSettings()
664 SettingsDialog dialog;
665 dialog.setFilterModel(m_proxyModel);
670 void MainWindow::openHelp(const QUrl &url)
672 QDesktopServices::openUrl(url);
675 void MainWindow::showSurfacesMenu(const QPoint &pos)
677 QTreeWidget *tree = m_ui.surfacesTreeWidget;
678 QTreeWidgetItem *item = tree->itemAt(pos);
683 QMenu menu(tr("Surfaces"), this);
685 QAction *act = menu.addAction(tr("View Image"));
686 act->setStatusTip(tr("View the currently selected surface"));
687 connect(act, SIGNAL(triggered()),
688 SLOT(showSelectedSurface()));
690 act = menu.addAction(tr("Save Image"));
691 act->setStatusTip(tr("Save the currently selected surface"));
692 connect(act, SIGNAL(triggered()),
693 SLOT(saveSelectedSurface()));
695 menu.exec(tree->viewport()->mapToGlobal(pos));
698 void MainWindow::showSelectedSurface()
700 QTreeWidgetItem *item =
701 m_ui.surfacesTreeWidget->currentItem();
707 ImageViewer *viewer = new ImageViewer(this);
710 if (selectedCall()) {
711 title = tr("QApiTrace - Surface at %1 (%2)")
712 .arg(selectedCall()->name())
713 .arg(selectedCall()->index());
715 title = tr("QApiTrace - Surface Viewer");
717 viewer->setWindowTitle(title);
719 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
721 QVariant var = item->data(0, Qt::UserRole);
722 QImage img = var.value<QImage>();
723 viewer->setImage(img);
727 viewer->activateWindow();
730 void MainWindow::initObjects()
732 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
733 m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
735 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
736 QVBoxLayout *layout = new QVBoxLayout;
737 layout->addWidget(m_sourcesWidget);
738 m_ui.shadersTab->setLayout(layout);
740 m_trace = new ApiTrace();
741 m_retracer = new Retracer(this);
743 m_vdataInterpreter = new VertexDataInterpreter(this);
744 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
745 m_vdataInterpreter->setStride(
746 m_ui.vertexStrideSB->value());
747 m_vdataInterpreter->setComponents(
748 m_ui.vertexComponentsSB->value());
749 m_vdataInterpreter->setStartingOffset(
750 m_ui.startingOffsetSB->value());
751 m_vdataInterpreter->setTypeFromString(
752 m_ui.vertexTypeCB->currentText());
754 m_model = new ApiTraceModel();
755 m_model->setApiTrace(m_trace);
756 m_proxyModel = new ApiTraceFilter();
757 m_proxyModel->setSourceModel(m_model);
758 m_ui.callView->setModel(m_proxyModel);
759 m_ui.callView->setItemDelegate(
760 new ApiCallDelegate(m_ui.callView));
761 m_ui.callView->resizeColumnToContents(0);
762 m_ui.callView->header()->swapSections(0, 1);
763 m_ui.callView->setColumnWidth(1, 42);
764 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
766 m_progressBar = new QProgressBar();
767 m_progressBar->setRange(0, 100);
768 statusBar()->addPermanentWidget(m_progressBar);
769 m_progressBar->hide();
771 m_argsEditor = new ArgumentsEditor(this);
773 m_ui.detailsDock->hide();
774 m_ui.backtraceDock->hide();
775 m_ui.errorsDock->hide();
776 m_ui.vertexDataDock->hide();
777 m_ui.stateDock->hide();
778 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
780 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
781 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
782 tabifyDockWidget(m_ui.detailsDock, m_ui.backtraceDock);
784 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
786 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
787 QWebPage::DelegateExternalLinks);
789 m_jumpWidget = new JumpWidget(this);
790 m_ui.centralLayout->addWidget(m_jumpWidget);
791 m_jumpWidget->hide();
793 m_searchWidget = new SearchWidget(this);
794 m_ui.centralLayout->addWidget(m_searchWidget);
795 m_searchWidget->hide();
797 m_traceProcess = new TraceProcess(this);
798 m_trimProcess = new TrimProcess(this);
800 m_profileDialog = new ProfileDialog();
803 void MainWindow::initConnections()
805 connect(m_trace, SIGNAL(startedLoadingTrace()),
806 this, SLOT(startedLoadingTrace()));
807 connect(m_trace, SIGNAL(loaded(int)),
808 this, SLOT(loadProgess(int)));
809 connect(m_trace, SIGNAL(finishedLoadingTrace()),
810 this, SLOT(finishedLoadingTrace()));
811 connect(m_trace, SIGNAL(startedSaving()),
812 this, SLOT(slotStartedSaving()));
813 connect(m_trace, SIGNAL(saved()),
814 this, SLOT(slotSaved()));
815 connect(m_trace, SIGNAL(changed(ApiTraceEvent*)),
816 this, SLOT(slotTraceChanged(ApiTraceEvent*)));
817 connect(m_trace, SIGNAL(findResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)),
818 this, SLOT(slotSearchResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)));
819 connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)),
820 this, SLOT(slotFoundFrameStart(ApiTraceFrame*)));
821 connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)),
822 this, SLOT(slotFoundFrameEnd(ApiTraceFrame*)));
823 connect(m_trace, SIGNAL(foundCallIndex(ApiTraceCall*)),
824 this, SLOT(slotJumpToResult(ApiTraceCall*)));
826 connect(m_retracer, SIGNAL(finished(const QString&)),
827 this, SLOT(replayFinished(const QString&)));
828 connect(m_retracer, SIGNAL(error(const QString&)),
829 this, SLOT(replayError(const QString&)));
830 connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
831 this, SLOT(replayStateFound(ApiTraceState*)));
832 connect(m_retracer, SIGNAL(foundProfile(trace::Profile*)),
833 this, SLOT(replayProfileFound(trace::Profile*)));
834 connect(m_retracer, SIGNAL(foundThumbnails(const QList<QImage>&)),
835 this, SLOT(replayThumbnailsFound(const QList<QImage>&)));
836 connect(m_retracer, SIGNAL(retraceErrors(const QList<ApiTraceError>&)),
837 this, SLOT(slotRetraceErrors(const QList<ApiTraceError>&)));
839 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
840 m_vdataInterpreter, SLOT(interpretData()));
841 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
842 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
843 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
844 m_vdataInterpreter, SLOT(setStride(int)));
845 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
846 m_vdataInterpreter, SLOT(setComponents(int)));
847 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
848 m_vdataInterpreter, SLOT(setStartingOffset(int)));
851 connect(m_ui.actionNew, SIGNAL(triggered()),
852 this, SLOT(createTrace()));
853 connect(m_ui.actionOpen, SIGNAL(triggered()),
854 this, SLOT(openTrace()));
855 connect(m_ui.actionQuit, SIGNAL(triggered()),
856 this, SLOT(close()));
858 connect(m_ui.actionFind, SIGNAL(triggered()),
859 this, SLOT(slotSearch()));
860 connect(m_ui.actionGo, SIGNAL(triggered()),
861 this, SLOT(slotGoTo()));
862 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
863 this, SLOT(slotGoFrameStart()));
864 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
865 this, SLOT(slotGoFrameEnd()));
867 connect(m_ui.actionReplay, SIGNAL(triggered()),
868 this, SLOT(replayStart()));
869 connect(m_ui.actionProfile, SIGNAL(triggered()),
870 this, SLOT(replayProfile()));
871 connect(m_ui.actionStop, SIGNAL(triggered()),
872 this, SLOT(replayStop()));
873 connect(m_ui.actionLookupState, SIGNAL(triggered()),
874 this, SLOT(lookupState()));
875 connect(m_ui.actionTrim, SIGNAL(triggered()),
877 connect(m_ui.actionShowThumbnails, SIGNAL(triggered()),
878 this, SLOT(showThumbnails()));
879 connect(m_ui.actionOptions, SIGNAL(triggered()),
880 this, SLOT(showSettings()));
882 connect(m_ui.callView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
883 this, SLOT(callItemSelected(const QModelIndex &)));
884 connect(m_ui.callView, SIGNAL(doubleClicked(const QModelIndex &)),
885 this, SLOT(callItemActivated(const QModelIndex &)));
886 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
887 this, SLOT(customContextMenuRequested(QPoint)));
889 connect(m_ui.surfacesTreeWidget,
890 SIGNAL(customContextMenuRequested(const QPoint &)),
891 SLOT(showSurfacesMenu(const QPoint &)));
892 connect(m_ui.surfacesTreeWidget,
893 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
894 SLOT(showSelectedSurface()));
896 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
897 this, SLOT(openHelp(const QUrl&)));
899 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
900 this, SLOT(fillState(bool)));
902 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
903 SLOT(slotJumpTo(int)));
905 connect(m_searchWidget,
906 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
907 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
908 connect(m_searchWidget,
909 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
910 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
912 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
913 SLOT(createdTrace(const QString&)));
914 connect(m_traceProcess, SIGNAL(error(const QString&)),
915 SLOT(traceError(const QString&)));
917 connect(m_trimProcess, SIGNAL(trimmedFile(const QString&)),
918 SLOT(createdTrim(const QString&)));
919 connect(m_trimProcess, SIGNAL(error(const QString&)),
920 SLOT(trimError(const QString&)));
922 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
923 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
924 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
925 m_ui.errorsDock, SLOT(setVisible(bool)));
926 connect(m_ui.errorsTreeWidget,
927 SIGNAL(itemActivated(QTreeWidgetItem*, int)),
928 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
930 connect(m_ui.actionShowProfileDialog, SIGNAL(triggered(bool)),
931 m_profileDialog, SLOT(show()));
932 connect(m_profileDialog, SIGNAL(jumpToCall(int)),
933 this, SLOT(slotJumpTo(int)));
936 void MainWindow::updateActionsState(bool traceLoaded, bool stopped)
940 m_ui.actionFind ->setEnabled(true);
941 m_ui.actionGo ->setEnabled(true);
942 m_ui.actionGoFrameStart ->setEnabled(true);
943 m_ui.actionGoFrameEnd ->setEnabled(true);
947 m_ui.actionStop->setEnabled(false);
948 m_ui.actionReplay->setEnabled(true);
951 m_ui.actionStop->setEnabled(true);
952 m_ui.actionReplay->setEnabled(false);
955 m_ui.actionProfile ->setEnabled(true);
956 m_ui.actionLookupState ->setEnabled(true);
957 m_ui.actionShowThumbnails->setEnabled(true);
958 m_ui.actionTrim ->setEnabled(true);
962 m_ui.actionFind ->setEnabled(false);
963 m_ui.actionGo ->setEnabled(false);
964 m_ui.actionGoFrameStart ->setEnabled(false);
965 m_ui.actionGoFrameEnd ->setEnabled(false);
968 m_ui.actionReplay ->setEnabled(false);
969 m_ui.actionProfile ->setEnabled(false);
970 m_ui.actionStop ->setEnabled(false);
971 m_ui.actionLookupState ->setEnabled(false);
972 m_ui.actionShowThumbnails->setEnabled(false);
973 m_ui.actionTrim ->setEnabled(false);
977 void MainWindow::closeEvent(QCloseEvent * event)
979 m_profileDialog->close();
980 QMainWindow::closeEvent(event);
983 void MainWindow::replayProfileFound(trace::Profile *profile)
985 m_ui.actionShowProfileDialog->setEnabled(true);
986 m_profileDialog->setProfile(profile);
987 m_profileDialog->show();
988 m_profileDialog->activateWindow();
989 m_profileDialog->setFocus();
992 void MainWindow::replayStateFound(ApiTraceState *state)
994 m_stateEvent->setState(state);
995 m_model->stateSetOnEvent(m_stateEvent);
996 if (m_selectedEvent == m_stateEvent ||
997 m_nonDefaultsLookupEvent == m_selectedEvent) {
1000 m_ui.stateDock->hide();
1002 m_nonDefaultsLookupEvent = 0;
1005 void MainWindow::replayThumbnailsFound(const QList<QImage> &thumbnails)
1007 m_ui.callView->setUniformRowHeights(false);
1008 m_trace->bindThumbnailsToFrames(thumbnails);
1011 void MainWindow::slotGoTo()
1013 m_searchWidget->hide();
1014 m_jumpWidget->show();
1017 void MainWindow::slotJumpTo(int callNum)
1019 m_trace->findCallIndex(callNum);
1022 void MainWindow::createdTrace(const QString &path)
1024 qDebug()<<"Done tracing "<<path;
1028 void MainWindow::traceError(const QString &msg)
1030 QMessageBox::warning(
1032 tr("Tracing Error"),
1036 void MainWindow::createdTrim(const QString &path)
1038 qDebug()<<"Done trimming "<<path;
1043 void MainWindow::trimError(const QString &msg)
1045 QMessageBox::warning(
1051 void MainWindow::slotSearch()
1053 m_jumpWidget->hide();
1054 m_searchWidget->show();
1057 void MainWindow::slotSearchNext(const QString &str,
1058 Qt::CaseSensitivity sensitivity)
1060 ApiTraceCall *call = currentCall();
1061 ApiTraceFrame *frame = currentFrame();
1063 Q_ASSERT(call || frame);
1065 frame = call->parentFrame();
1069 m_trace->findNext(frame, call, str, sensitivity);
1072 void MainWindow::slotSearchPrev(const QString &str,
1073 Qt::CaseSensitivity sensitivity)
1075 ApiTraceCall *call = currentCall();
1076 ApiTraceFrame *frame = currentFrame();
1078 Q_ASSERT(call || frame);
1080 frame = call->parentFrame();
1084 m_trace->findPrev(frame, call, str, sensitivity);
1087 void MainWindow::fillState(bool nonDefaults)
1090 ApiTraceState defaultState = m_trace->defaultState();
1091 if (defaultState.isEmpty()) {
1092 m_ui.nonDefaultsCB->blockSignals(true);
1093 m_ui.nonDefaultsCB->setChecked(false);
1094 m_ui.nonDefaultsCB->blockSignals(false);
1095 ApiTraceFrame *firstFrame =
1096 m_trace->frameAt(0);
1100 if (!firstFrame->isLoaded()) {
1101 m_trace->loadFrame(firstFrame);
1104 ApiTraceCall *firstCall = firstFrame->calls().first();
1105 ApiTraceEvent *oldSelected = m_selectedEvent;
1106 m_nonDefaultsLookupEvent = m_selectedEvent;
1107 m_selectedEvent = firstCall;
1109 m_selectedEvent = oldSelected;
1112 fillStateForFrame();
1115 void MainWindow::customContextMenuRequested(QPoint pos)
1117 QModelIndex index = m_ui.callView->indexAt(pos);
1119 callItemSelected(index);
1120 if (!index.isValid()) {
1124 ApiTraceEvent *event =
1125 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1131 menu.addAction(QIcon(":/resources/media-record.png"),
1132 tr("Lookup state"), this, SLOT(lookupState()));
1133 if (event->type() == ApiTraceEvent::Call) {
1134 menu.addAction(tr("Edit"), this, SLOT(editCall()));
1137 menu.exec(QCursor::pos());
1140 void MainWindow::editCall()
1142 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
1143 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1144 m_argsEditor->setCall(call);
1145 m_argsEditor->show();
1149 void MainWindow::slotStartedSaving()
1151 m_progressBar->show();
1152 statusBar()->showMessage(
1153 tr("Saving to %1").arg(m_trace->fileName()));
1156 void MainWindow::slotSaved()
1158 statusBar()->showMessage(
1159 tr("Saved to %1").arg(m_trace->fileName()), 2000);
1160 m_progressBar->hide();
1163 void MainWindow::slotGoFrameStart()
1165 ApiTraceFrame *frame = currentFrame();
1166 ApiTraceCall *call = currentCall();
1168 if (!frame && call) {
1169 frame = call->parentFrame();
1172 m_trace->findFrameStart(frame);
1175 void MainWindow::slotGoFrameEnd()
1177 ApiTraceFrame *frame = currentFrame();
1178 ApiTraceCall *call = currentCall();
1180 if (!frame && call) {
1181 frame = call->parentFrame();
1184 m_trace->findFrameEnd(frame);
1187 ApiTraceFrame * MainWindow::selectedFrame() const
1189 if (m_selectedEvent) {
1190 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1191 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1193 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1194 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1195 return call->parentFrame();
1201 void MainWindow::slotTraceChanged(ApiTraceEvent *event)
1204 if (event == m_selectedEvent) {
1205 if (event->type() == ApiTraceEvent::Call) {
1206 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
1207 m_ui.detailsWebView->setHtml(call->toHtml());
1212 void MainWindow::slotRetraceErrors(const QList<ApiTraceError> &errors)
1214 m_ui.errorsTreeWidget->clear();
1216 foreach(ApiTraceError error, errors) {
1217 m_trace->setCallError(error);
1219 QTreeWidgetItem *item =
1220 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1221 item->setData(0, Qt::DisplayRole, error.callIndex);
1222 item->setData(0, Qt::UserRole, error.callIndex);
1223 QString type = error.type;
1224 type[0] = type[0].toUpper();
1225 item->setData(1, Qt::DisplayRole, type);
1226 item->setData(2, Qt::DisplayRole, error.message);
1230 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1234 current->data(0, Qt::UserRole).toInt();
1235 m_trace->findCallIndex(callIndex);
1239 ApiTraceCall * MainWindow::selectedCall() const
1241 if (m_selectedEvent &&
1242 m_selectedEvent->type() == ApiTraceEvent::Call) {
1243 return static_cast<ApiTraceCall*>(m_selectedEvent);
1248 void MainWindow::saveSelectedSurface()
1250 QTreeWidgetItem *item =
1251 m_ui.surfacesTreeWidget->currentItem();
1253 if (!item || !m_trace) {
1257 QVariant var = item->data(0, Qt::UserRole);
1258 QImage img = var.value<QImage>();
1261 if (selectedCall()) {
1262 imageIndex = tr("_call_%1")
1263 .arg(selectedCall()->index());
1264 } else if (selectedFrame()) {
1265 ApiTraceCall *firstCall = selectedFrame()->call(0);
1267 imageIndex = tr("_frame_%1")
1268 .arg(firstCall->index());
1270 qDebug()<<"unknown frame number";
1271 imageIndex = tr("_frame_%1")
1272 .arg(firstCall->index());
1276 //which of the surfaces are we saving
1277 QTreeWidgetItem *parent = item->parent();
1279 m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
1280 if (parentIndex < 0) {
1285 childIndex = parent->indexOfChild(item);
1287 childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
1292 tr("%1%2-%3_%4.png")
1293 .arg(m_trace->fileName())
1297 //qDebug()<<"save "<<fileName;
1298 img.save(fileName, "PNG");
1299 statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
1302 void MainWindow::loadProgess(int percent)
1304 m_progressBar->setValue(percent);
1307 void MainWindow::slotSearchResult(const ApiTrace::SearchRequest &request,
1308 ApiTrace::SearchResult result,
1312 case ApiTrace::SearchResult_NotFound:
1313 m_searchWidget->setFound(false);
1315 case ApiTrace::SearchResult_Found: {
1316 QModelIndex index = m_proxyModel->indexForCall(call);
1318 if (index.isValid()) {
1319 m_ui.callView->setCurrentIndex(index);
1320 m_searchWidget->setFound(true);
1322 //call is filtered out, so continue searching but from the
1325 qDebug()<<"Error: search success with no call";
1328 // qDebug()<<"filtered! search from "<<call->searchText()
1329 // <<", call idx = "<<call->index();
1331 if (request.direction == ApiTrace::SearchRequest::Next) {
1332 m_trace->findNext(call->parentFrame(), call,
1333 request.text, request.cs);
1335 m_trace->findNext(call->parentFrame(), call,
1336 request.text, request.cs);
1341 case ApiTrace::SearchResult_Wrapped:
1342 m_searchWidget->setFound(false);
1347 ApiTraceFrame * MainWindow::currentFrame() const
1349 QModelIndex index = m_ui.callView->currentIndex();
1350 ApiTraceEvent *event = 0;
1352 if (!index.isValid()) {
1353 index = m_proxyModel->index(0, 0, QModelIndex());
1354 if (!index.isValid()) {
1355 qDebug()<<"no currently valid index";
1360 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1366 ApiTraceFrame *frame = 0;
1367 if (event->type() == ApiTraceCall::Frame) {
1368 frame = static_cast<ApiTraceFrame*>(event);
1373 ApiTraceCall * MainWindow::currentCall() const
1375 QModelIndex index = m_ui.callView->currentIndex();
1376 ApiTraceEvent *event = 0;
1378 if (!index.isValid()) {
1379 index = m_proxyModel->index(0, 0, QModelIndex());
1380 if (!index.isValid()) {
1381 qDebug()<<"no currently valid index";
1386 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1392 ApiTraceCall *call = 0;
1393 if (event->type() == ApiTraceCall::Call) {
1394 call = static_cast<ApiTraceCall*>(event);
1401 void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
1403 Q_ASSERT(frame->isLoaded());
1404 if (!frame || frame->isEmpty()) {
1408 QVector<ApiTraceCall*>::const_iterator itr;
1409 QVector<ApiTraceCall*> calls = frame->calls();
1411 itr = calls.constBegin();
1412 while (itr != calls.constEnd()) {
1413 ApiTraceCall *call = *itr;
1414 QModelIndex idx = m_proxyModel->indexForCall(call);
1415 if (idx.isValid()) {
1416 m_ui.callView->setCurrentIndex(idx);
1417 m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtTop);
1424 void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame)
1426 Q_ASSERT(frame->isLoaded());
1427 if (!frame || frame->isEmpty()) {
1430 QVector<ApiTraceCall*>::const_iterator itr;
1431 QVector<ApiTraceCall*> calls = frame->calls();
1433 itr = calls.constEnd();
1436 ApiTraceCall *call = *itr;
1437 QModelIndex idx = m_proxyModel->indexForCall(call);
1438 if (idx.isValid()) {
1439 m_ui.callView->setCurrentIndex(idx);
1440 m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtBottom);
1443 } while (itr != calls.constBegin());
1446 void MainWindow::slotJumpToResult(ApiTraceCall *call)
1448 QModelIndex idx = m_proxyModel->indexForCall(call);
1449 if (idx.isValid()) {
1451 m_ui.callView->setFocus();
1452 m_ui.callView->setCurrentIndex(idx);
1453 m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
1455 statusBar()->showMessage(tr("Call has been filtered out."));
1459 #include "mainwindow.moc"