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 Q_ASSERT(m_trimEvent->type() == ApiTraceEvent::Call ||
376 m_trimEvent->type() == ApiTraceEvent::Frame);
378 if (m_trimEvent->type() == ApiTraceEvent::Call) {
379 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_trimEvent);
380 trimIndex = call->index();
381 } else if (m_trimEvent->type() == ApiTraceEvent::Frame) {
382 ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(m_trimEvent);
383 const QList<ApiTraceFrame*> frames = m_trace->frames();
384 trimIndex = frame->lastCallIndex();
387 m_trimProcess->setTracePath(m_trace->fileName());
388 m_trimProcess->setTrimIndex(trimIndex);
390 m_trimProcess->start();
393 void MainWindow::lookupState()
395 if (!m_selectedEvent) {
396 QMessageBox::warning(
397 this, tr("Unknown Event"),
398 tr("To inspect the state select an event in the event list."));
401 if (m_trace->isSaving()) {
402 QMessageBox::warning(
405 tr("QApiTrace is currently saving the edited trace file. "
406 "Please wait until it finishes and try again."));
409 m_stateEvent = m_selectedEvent;
410 replayTrace(true, false);
413 void MainWindow::showThumbnails()
415 replayTrace(false, true);
418 void MainWindow::trim()
420 if (!m_selectedEvent) {
421 QMessageBox::warning(
422 this, tr("Unknown Event"),
423 tr("To trim select a frame or an event in the event list."));
426 m_trimEvent = m_selectedEvent;
431 variantToString(const QVariant &var, QString &str)
433 if (var.type() == QVariant::List) {
434 QVector<QVariant> lst = var.toList().toVector();
435 str += QLatin1String("[");
436 for (int i = 0; i < lst.count(); ++i) {
437 QVariant val = lst[i];
438 variantToString(val, str);
439 if (i < lst.count() - 1)
440 str += QLatin1String(", ");
442 str += QLatin1String("]");
443 } else if (var.type() == QVariant::Map) {
444 Q_ASSERT(!"unsupported state type");
445 } else if (var.type() == QVariant::Hash) {
446 Q_ASSERT(!"unsupported state type");
448 str += var.toString();
452 static QTreeWidgetItem *
453 variantToItem(const QString &key, const QVariant &var,
454 const QVariant &defaultVar);
457 variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap,
458 QList<QTreeWidgetItem *> &items)
460 QVariantMap::const_iterator itr;
461 for (itr = map.constBegin(); itr != map.constEnd(); ++itr) {
462 QString key = itr.key();
463 QVariant var = itr.value();
464 QVariant defaultVar = defaultMap[key];
466 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
474 variantListToItems(const QVector<QVariant> &lst,
475 const QVector<QVariant> &defaultLst,
476 QList<QTreeWidgetItem *> &items)
478 for (int i = 0; i < lst.count(); ++i) {
479 QString key = QString::number(i);
480 QVariant var = lst[i];
483 if (i < defaultLst.count()) {
484 defaultVar = defaultLst[i];
487 QTreeWidgetItem *item = variantToItem(key, var, defaultVar);
495 isVariantDeep(const QVariant &var)
497 if (var.type() == QVariant::List) {
498 QVector<QVariant> lst = var.toList().toVector();
499 for (int i = 0; i < lst.count(); ++i) {
500 if (isVariantDeep(lst[i])) {
505 } else if (var.type() == QVariant::Map) {
507 } else if (var.type() == QVariant::Hash) {
514 static QTreeWidgetItem *
515 variantToItem(const QString &key, const QVariant &var,
516 const QVariant &defaultVar)
518 if (var == defaultVar) {
524 bool deep = isVariantDeep(var);
526 variantToString(var, val);
529 //qDebug()<<"key = "<<key;
530 //qDebug()<<"val = "<<val;
535 QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem *)0, lst);
538 QList<QTreeWidgetItem *> children;
539 if (var.type() == QVariant::Map) {
540 QVariantMap map = var.toMap();
541 QVariantMap defaultMap = defaultVar.toMap();
542 variantMapToItems(map, defaultMap, children);
544 if (var.type() == QVariant::List) {
545 QVector<QVariant> lst = var.toList().toVector();
546 QVector<QVariant> defaultLst = defaultVar.toList().toVector();
547 variantListToItems(lst, defaultLst, children);
549 item->addChildren(children);
555 static void addSurfaceItem(const ApiSurface &surface,
556 const QString &label,
557 QTreeWidgetItem *parent,
560 QIcon icon(QPixmap::fromImage(surface.thumb()));
561 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
562 item->setIcon(0, icon);
564 int width = surface.size().width();
565 int height = surface.size().height();
567 QString::fromLatin1("%1, %2, %3 x %4")
569 .arg(surface.formatName())
573 //item->setText(1, descr);
574 QLabel *l = new QLabel(descr, tree);
575 l->setWordWrap(true);
576 tree->setItemWidget(item, 1, l);
578 item->setData(0, Qt::UserRole, surface.base64Data());
581 void MainWindow::fillStateForFrame()
583 if (!m_selectedEvent || !m_selectedEvent->hasState()) {
587 if (m_nonDefaultsLookupEvent) {
588 m_ui.nonDefaultsCB->blockSignals(true);
589 m_ui.nonDefaultsCB->setChecked(true);
590 m_ui.nonDefaultsCB->blockSignals(false);
593 bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
594 QVariantMap defaultParams;
596 ApiTraceState defaultState = m_trace->defaultState();
597 defaultParams = defaultState.parameters();
600 const ApiTraceState &state = *m_selectedEvent->state();
601 m_ui.stateTreeWidget->clear();
602 QList<QTreeWidgetItem *> items;
603 variantMapToItems(state.parameters(), defaultParams, items);
604 m_ui.stateTreeWidget->insertTopLevelItems(0, items);
606 QMap<QString, QString> shaderSources = state.shaderSources();
607 if (shaderSources.isEmpty()) {
608 m_sourcesWidget->setShaders(shaderSources);
610 m_sourcesWidget->setShaders(shaderSources);
613 m_ui.uniformsTreeWidget->clear();
614 QList<QTreeWidgetItem *> uniformsItems;
615 variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems);
616 m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems);
618 const QList<ApiTexture> &textures =
620 const QList<ApiFramebuffer> &fbos =
621 state.framebuffers();
623 m_ui.surfacesTreeWidget->clear();
624 if (textures.isEmpty() && fbos.isEmpty()) {
625 m_ui.surfacesTab->setDisabled(false);
627 m_ui.surfacesTreeWidget->setIconSize(QSize(THUMBNAIL_SIZE, THUMBNAIL_SIZE));
628 if (!textures.isEmpty()) {
629 QTreeWidgetItem *textureItem =
630 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
631 textureItem->setText(0, tr("Textures"));
632 if (textures.count() <= 6) {
633 textureItem->setExpanded(true);
636 for (int i = 0; i < textures.count(); ++i) {
637 const ApiTexture &texture =
639 addSurfaceItem(texture, texture.label(),
641 m_ui.surfacesTreeWidget);
644 if (!fbos.isEmpty()) {
645 QTreeWidgetItem *fboItem =
646 new QTreeWidgetItem(m_ui.surfacesTreeWidget);
647 fboItem->setText(0, tr("Framebuffers"));
648 if (fbos.count() <= 6) {
649 fboItem->setExpanded(true);
652 for (int i = 0; i < fbos.count(); ++i) {
653 const ApiFramebuffer &fbo =
655 addSurfaceItem(fbo, fbo.type(),
657 m_ui.surfacesTreeWidget);
660 m_ui.surfacesTab->setEnabled(true);
662 m_ui.stateDock->show();
665 void MainWindow::showSettings()
667 SettingsDialog dialog;
668 dialog.setFilterModel(m_proxyModel);
673 void MainWindow::openHelp(const QUrl &url)
675 QDesktopServices::openUrl(url);
678 void MainWindow::showSurfacesMenu(const QPoint &pos)
680 QTreeWidget *tree = m_ui.surfacesTreeWidget;
681 QTreeWidgetItem *item = tree->itemAt(pos);
686 QMenu menu(tr("Surfaces"), this);
688 QAction *act = menu.addAction(tr("View Image"));
689 act->setStatusTip(tr("View the currently selected surface"));
690 connect(act, SIGNAL(triggered()),
691 SLOT(showSelectedSurface()));
693 act = menu.addAction(tr("Save Image"));
694 act->setStatusTip(tr("Save the currently selected surface"));
695 connect(act, SIGNAL(triggered()),
696 SLOT(saveSelectedSurface()));
698 menu.exec(tree->viewport()->mapToGlobal(pos));
701 void MainWindow::showSelectedSurface()
703 QTreeWidgetItem *item =
704 m_ui.surfacesTreeWidget->currentItem();
710 ImageViewer *viewer = new ImageViewer(this);
713 if (selectedCall()) {
714 title = tr("QApiTrace - Surface at %1 (%2)")
715 .arg(selectedCall()->name())
716 .arg(selectedCall()->index());
718 title = tr("QApiTrace - Surface Viewer");
720 viewer->setWindowTitle(title);
722 viewer->setAttribute(Qt::WA_DeleteOnClose, true);
724 QVariant var = item->data(0, Qt::UserRole);
725 QByteArray base64Data = var.value<QByteArray>();
726 viewer->setBase64Data(base64Data);
730 viewer->activateWindow();
733 void MainWindow::initObjects()
735 m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
736 m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
738 m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
739 QVBoxLayout *layout = new QVBoxLayout;
740 layout->addWidget(m_sourcesWidget);
741 m_ui.shadersTab->setLayout(layout);
743 m_trace = new ApiTrace();
744 m_retracer = new Retracer(this);
746 m_vdataInterpreter = new VertexDataInterpreter(this);
747 m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
748 m_vdataInterpreter->setStride(
749 m_ui.vertexStrideSB->value());
750 m_vdataInterpreter->setComponents(
751 m_ui.vertexComponentsSB->value());
752 m_vdataInterpreter->setStartingOffset(
753 m_ui.startingOffsetSB->value());
754 m_vdataInterpreter->setTypeFromString(
755 m_ui.vertexTypeCB->currentText());
757 m_model = new ApiTraceModel();
758 m_model->setApiTrace(m_trace);
759 m_proxyModel = new ApiTraceFilter();
760 m_proxyModel->setSourceModel(m_model);
761 m_ui.callView->setModel(m_proxyModel);
762 m_ui.callView->setItemDelegate(
763 new ApiCallDelegate(m_ui.callView));
764 m_ui.callView->resizeColumnToContents(0);
765 m_ui.callView->header()->swapSections(0, 1);
766 m_ui.callView->setColumnWidth(1, 42);
767 m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
769 m_progressBar = new QProgressBar();
770 m_progressBar->setRange(0, 100);
771 statusBar()->addPermanentWidget(m_progressBar);
772 m_progressBar->hide();
774 m_argsEditor = new ArgumentsEditor(this);
776 m_ui.detailsDock->hide();
777 m_ui.backtraceDock->hide();
778 m_ui.errorsDock->hide();
779 m_ui.vertexDataDock->hide();
780 m_ui.stateDock->hide();
781 setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
783 tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
784 tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
785 tabifyDockWidget(m_ui.detailsDock, m_ui.backtraceDock);
787 m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
789 m_ui.detailsWebView->page()->setLinkDelegationPolicy(
790 QWebPage::DelegateExternalLinks);
792 m_jumpWidget = new JumpWidget(this);
793 m_ui.centralLayout->addWidget(m_jumpWidget);
794 m_jumpWidget->hide();
796 m_searchWidget = new SearchWidget(this);
797 m_ui.centralLayout->addWidget(m_searchWidget);
798 m_searchWidget->hide();
800 m_traceProcess = new TraceProcess(this);
801 m_trimProcess = new TrimProcess(this);
803 m_profileDialog = new ProfileDialog();
806 void MainWindow::initConnections()
808 connect(m_trace, SIGNAL(startedLoadingTrace()),
809 this, SLOT(startedLoadingTrace()));
810 connect(m_trace, SIGNAL(loaded(int)),
811 this, SLOT(loadProgess(int)));
812 connect(m_trace, SIGNAL(finishedLoadingTrace()),
813 this, SLOT(finishedLoadingTrace()));
814 connect(m_trace, SIGNAL(startedSaving()),
815 this, SLOT(slotStartedSaving()));
816 connect(m_trace, SIGNAL(saved()),
817 this, SLOT(slotSaved()));
818 connect(m_trace, SIGNAL(changed(ApiTraceEvent*)),
819 this, SLOT(slotTraceChanged(ApiTraceEvent*)));
820 connect(m_trace, SIGNAL(findResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)),
821 this, SLOT(slotSearchResult(ApiTrace::SearchRequest,ApiTrace::SearchResult,ApiTraceCall*)));
822 connect(m_trace, SIGNAL(foundFrameStart(ApiTraceFrame*)),
823 this, SLOT(slotFoundFrameStart(ApiTraceFrame*)));
824 connect(m_trace, SIGNAL(foundFrameEnd(ApiTraceFrame*)),
825 this, SLOT(slotFoundFrameEnd(ApiTraceFrame*)));
826 connect(m_trace, SIGNAL(foundCallIndex(ApiTraceCall*)),
827 this, SLOT(slotJumpToResult(ApiTraceCall*)));
829 connect(m_retracer, SIGNAL(finished(const QString&)),
830 this, SLOT(replayFinished(const QString&)));
831 connect(m_retracer, SIGNAL(error(const QString&)),
832 this, SLOT(replayError(const QString&)));
833 connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
834 this, SLOT(replayStateFound(ApiTraceState*)));
835 connect(m_retracer, SIGNAL(foundProfile(trace::Profile*)),
836 this, SLOT(replayProfileFound(trace::Profile*)));
837 connect(m_retracer, SIGNAL(foundThumbnails(const QList<QImage>&)),
838 this, SLOT(replayThumbnailsFound(const QList<QImage>&)));
839 connect(m_retracer, SIGNAL(retraceErrors(const QList<ApiTraceError>&)),
840 this, SLOT(slotRetraceErrors(const QList<ApiTraceError>&)));
842 connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
843 m_vdataInterpreter, SLOT(interpretData()));
844 connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
845 m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
846 connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
847 m_vdataInterpreter, SLOT(setStride(int)));
848 connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
849 m_vdataInterpreter, SLOT(setComponents(int)));
850 connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
851 m_vdataInterpreter, SLOT(setStartingOffset(int)));
854 connect(m_ui.actionNew, SIGNAL(triggered()),
855 this, SLOT(createTrace()));
856 connect(m_ui.actionOpen, SIGNAL(triggered()),
857 this, SLOT(openTrace()));
858 connect(m_ui.actionQuit, SIGNAL(triggered()),
859 this, SLOT(close()));
861 connect(m_ui.actionFind, SIGNAL(triggered()),
862 this, SLOT(slotSearch()));
863 connect(m_ui.actionGo, SIGNAL(triggered()),
864 this, SLOT(slotGoTo()));
865 connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
866 this, SLOT(slotGoFrameStart()));
867 connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
868 this, SLOT(slotGoFrameEnd()));
870 connect(m_ui.actionReplay, SIGNAL(triggered()),
871 this, SLOT(replayStart()));
872 connect(m_ui.actionProfile, SIGNAL(triggered()),
873 this, SLOT(replayProfile()));
874 connect(m_ui.actionStop, SIGNAL(triggered()),
875 this, SLOT(replayStop()));
876 connect(m_ui.actionLookupState, SIGNAL(triggered()),
877 this, SLOT(lookupState()));
878 connect(m_ui.actionTrim, SIGNAL(triggered()),
880 connect(m_ui.actionShowThumbnails, SIGNAL(triggered()),
881 this, SLOT(showThumbnails()));
882 connect(m_ui.actionOptions, SIGNAL(triggered()),
883 this, SLOT(showSettings()));
885 connect(m_ui.callView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
886 this, SLOT(callItemSelected(const QModelIndex &)));
887 connect(m_ui.callView, SIGNAL(doubleClicked(const QModelIndex &)),
888 this, SLOT(callItemActivated(const QModelIndex &)));
889 connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
890 this, SLOT(customContextMenuRequested(QPoint)));
892 connect(m_ui.surfacesTreeWidget,
893 SIGNAL(customContextMenuRequested(const QPoint &)),
894 SLOT(showSurfacesMenu(const QPoint &)));
895 connect(m_ui.surfacesTreeWidget,
896 SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
897 SLOT(showSelectedSurface()));
899 connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
900 this, SLOT(openHelp(const QUrl&)));
902 connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
903 this, SLOT(fillState(bool)));
905 connect(m_jumpWidget, SIGNAL(jumpTo(int)),
906 SLOT(slotJumpTo(int)));
908 connect(m_searchWidget,
909 SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
910 SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
911 connect(m_searchWidget,
912 SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
913 SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
915 connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
916 SLOT(createdTrace(const QString&)));
917 connect(m_traceProcess, SIGNAL(error(const QString&)),
918 SLOT(traceError(const QString&)));
920 connect(m_trimProcess, SIGNAL(trimmedFile(const QString&)),
921 SLOT(createdTrim(const QString&)));
922 connect(m_trimProcess, SIGNAL(error(const QString&)),
923 SLOT(trimError(const QString&)));
925 connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
926 m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
927 connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
928 m_ui.errorsDock, SLOT(setVisible(bool)));
929 connect(m_ui.errorsTreeWidget,
930 SIGNAL(itemActivated(QTreeWidgetItem*, int)),
931 this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
933 connect(m_ui.actionShowProfileDialog, SIGNAL(triggered(bool)),
934 m_profileDialog, SLOT(show()));
935 connect(m_profileDialog, SIGNAL(jumpToCall(int)),
936 this, SLOT(slotJumpTo(int)));
939 void MainWindow::updateActionsState(bool traceLoaded, bool stopped)
943 m_ui.actionFind ->setEnabled(true);
944 m_ui.actionGo ->setEnabled(true);
945 m_ui.actionGoFrameStart ->setEnabled(true);
946 m_ui.actionGoFrameEnd ->setEnabled(true);
950 m_ui.actionStop->setEnabled(false);
951 m_ui.actionReplay->setEnabled(true);
954 m_ui.actionStop->setEnabled(true);
955 m_ui.actionReplay->setEnabled(false);
958 m_ui.actionProfile ->setEnabled(true);
959 m_ui.actionLookupState ->setEnabled(true);
960 m_ui.actionShowThumbnails->setEnabled(true);
961 m_ui.actionTrim ->setEnabled(true);
965 m_ui.actionFind ->setEnabled(false);
966 m_ui.actionGo ->setEnabled(false);
967 m_ui.actionGoFrameStart ->setEnabled(false);
968 m_ui.actionGoFrameEnd ->setEnabled(false);
971 m_ui.actionReplay ->setEnabled(false);
972 m_ui.actionProfile ->setEnabled(false);
973 m_ui.actionStop ->setEnabled(false);
974 m_ui.actionLookupState ->setEnabled(false);
975 m_ui.actionShowThumbnails->setEnabled(false);
976 m_ui.actionTrim ->setEnabled(false);
980 void MainWindow::closeEvent(QCloseEvent * event)
982 m_profileDialog->close();
983 QMainWindow::closeEvent(event);
986 void MainWindow::replayProfileFound(trace::Profile *profile)
988 m_ui.actionShowProfileDialog->setEnabled(true);
989 m_profileDialog->setProfile(profile);
990 m_profileDialog->show();
991 m_profileDialog->activateWindow();
992 m_profileDialog->setFocus();
995 void MainWindow::replayStateFound(ApiTraceState *state)
997 m_stateEvent->setState(state);
998 m_model->stateSetOnEvent(m_stateEvent);
999 if (m_selectedEvent == m_stateEvent ||
1000 m_nonDefaultsLookupEvent == m_selectedEvent) {
1001 fillStateForFrame();
1003 m_ui.stateDock->hide();
1005 m_nonDefaultsLookupEvent = 0;
1008 void MainWindow::replayThumbnailsFound(const QList<QImage> &thumbnails)
1010 m_ui.callView->setUniformRowHeights(false);
1011 m_trace->bindThumbnailsToFrames(thumbnails);
1014 void MainWindow::slotGoTo()
1016 m_searchWidget->hide();
1017 m_jumpWidget->show();
1020 void MainWindow::slotJumpTo(int callNum)
1022 m_trace->findCallIndex(callNum);
1025 void MainWindow::createdTrace(const QString &path)
1027 qDebug()<<"Done tracing "<<path;
1031 void MainWindow::traceError(const QString &msg)
1033 QMessageBox::warning(
1035 tr("Tracing Error"),
1039 void MainWindow::createdTrim(const QString &path)
1041 qDebug()<<"Done trimming "<<path;
1046 void MainWindow::trimError(const QString &msg)
1048 QMessageBox::warning(
1054 void MainWindow::slotSearch()
1056 m_jumpWidget->hide();
1057 m_searchWidget->show();
1060 void MainWindow::slotSearchNext(const QString &str,
1061 Qt::CaseSensitivity sensitivity)
1063 ApiTraceCall *call = currentCall();
1064 ApiTraceFrame *frame = currentFrame();
1066 Q_ASSERT(call || frame);
1068 frame = call->parentFrame();
1072 m_trace->findNext(frame, call, str, sensitivity);
1075 void MainWindow::slotSearchPrev(const QString &str,
1076 Qt::CaseSensitivity sensitivity)
1078 ApiTraceCall *call = currentCall();
1079 ApiTraceFrame *frame = currentFrame();
1081 Q_ASSERT(call || frame);
1083 frame = call->parentFrame();
1087 m_trace->findPrev(frame, call, str, sensitivity);
1090 void MainWindow::fillState(bool nonDefaults)
1093 ApiTraceState defaultState = m_trace->defaultState();
1094 if (defaultState.isEmpty()) {
1095 m_ui.nonDefaultsCB->blockSignals(true);
1096 m_ui.nonDefaultsCB->setChecked(false);
1097 m_ui.nonDefaultsCB->blockSignals(false);
1098 ApiTraceFrame *firstFrame =
1099 m_trace->frameAt(0);
1103 if (!firstFrame->isLoaded()) {
1104 m_trace->loadFrame(firstFrame);
1107 ApiTraceCall *firstCall = firstFrame->calls().first();
1108 ApiTraceEvent *oldSelected = m_selectedEvent;
1109 m_nonDefaultsLookupEvent = m_selectedEvent;
1110 m_selectedEvent = firstCall;
1112 m_selectedEvent = oldSelected;
1115 fillStateForFrame();
1118 void MainWindow::customContextMenuRequested(QPoint pos)
1120 QModelIndex index = m_ui.callView->indexAt(pos);
1122 callItemSelected(index);
1123 if (!index.isValid()) {
1127 ApiTraceEvent *event =
1128 index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1134 menu.addAction(QIcon(":/resources/media-record.png"),
1135 tr("Lookup state"), this, SLOT(lookupState()));
1136 if (event->type() == ApiTraceEvent::Call) {
1137 menu.addAction(tr("Edit"), this, SLOT(editCall()));
1140 menu.exec(QCursor::pos());
1143 void MainWindow::editCall()
1145 if (m_selectedEvent && m_selectedEvent->type() == ApiTraceEvent::Call) {
1146 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1147 m_argsEditor->setCall(call);
1148 m_argsEditor->show();
1152 void MainWindow::slotStartedSaving()
1154 m_progressBar->show();
1155 statusBar()->showMessage(
1156 tr("Saving to %1").arg(m_trace->fileName()));
1159 void MainWindow::slotSaved()
1161 statusBar()->showMessage(
1162 tr("Saved to %1").arg(m_trace->fileName()), 2000);
1163 m_progressBar->hide();
1166 void MainWindow::slotGoFrameStart()
1168 ApiTraceFrame *frame = currentFrame();
1169 ApiTraceCall *call = currentCall();
1171 if (!frame && call) {
1172 frame = call->parentFrame();
1175 m_trace->findFrameStart(frame);
1178 void MainWindow::slotGoFrameEnd()
1180 ApiTraceFrame *frame = currentFrame();
1181 ApiTraceCall *call = currentCall();
1183 if (!frame && call) {
1184 frame = call->parentFrame();
1187 m_trace->findFrameEnd(frame);
1190 ApiTraceFrame * MainWindow::selectedFrame() const
1192 if (m_selectedEvent) {
1193 if (m_selectedEvent->type() == ApiTraceEvent::Frame) {
1194 return static_cast<ApiTraceFrame*>(m_selectedEvent);
1196 Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call);
1197 ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent);
1198 return call->parentFrame();
1204 void MainWindow::slotTraceChanged(ApiTraceEvent *event)
1207 if (event == m_selectedEvent) {
1208 if (event->type() == ApiTraceEvent::Call) {
1209 ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
1210 m_ui.detailsWebView->setHtml(call->toHtml());
1215 void MainWindow::slotRetraceErrors(const QList<ApiTraceError> &errors)
1217 m_ui.errorsTreeWidget->clear();
1219 foreach(ApiTraceError error, errors) {
1220 m_trace->setCallError(error);
1222 QTreeWidgetItem *item =
1223 new QTreeWidgetItem(m_ui.errorsTreeWidget);
1224 item->setData(0, Qt::DisplayRole, error.callIndex);
1225 item->setData(0, Qt::UserRole, error.callIndex);
1226 QString type = error.type;
1227 type[0] = type[0].toUpper();
1228 item->setData(1, Qt::DisplayRole, type);
1229 item->setData(2, Qt::DisplayRole, error.message);
1233 void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
1237 current->data(0, Qt::UserRole).toInt();
1238 m_trace->findCallIndex(callIndex);
1242 ApiTraceCall * MainWindow::selectedCall() const
1244 if (m_selectedEvent &&
1245 m_selectedEvent->type() == ApiTraceEvent::Call) {
1246 return static_cast<ApiTraceCall*>(m_selectedEvent);
1251 void MainWindow::saveSelectedSurface()
1253 QTreeWidgetItem *item =
1254 m_ui.surfacesTreeWidget->currentItem();
1256 if (!item || !m_trace) {
1260 QVariant var = item->data(0, Qt::UserRole);
1261 QImage img = var.value<QImage>();
1264 if (selectedCall()) {
1265 imageIndex = tr("_call_%1")
1266 .arg(selectedCall()->index());
1267 } else if (selectedFrame()) {
1268 ApiTraceCall *firstCall = selectedFrame()->call(0);
1270 imageIndex = tr("_frame_%1")
1271 .arg(firstCall->index());
1273 qDebug()<<"unknown frame number";
1274 imageIndex = tr("_frame_%1")
1275 .arg(firstCall->index());
1279 //which of the surfaces are we saving
1280 QTreeWidgetItem *parent = item->parent();
1282 m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
1283 if (parentIndex < 0) {
1288 childIndex = parent->indexOfChild(item);
1290 childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
1295 tr("%1%2-%3_%4.png")
1296 .arg(m_trace->fileName())
1300 //qDebug()<<"save "<<fileName;
1301 img.save(fileName, "PNG");
1302 statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
1305 void MainWindow::loadProgess(int percent)
1307 m_progressBar->setValue(percent);
1310 void MainWindow::slotSearchResult(const ApiTrace::SearchRequest &request,
1311 ApiTrace::SearchResult result,
1315 case ApiTrace::SearchResult_NotFound:
1316 m_searchWidget->setFound(false);
1318 case ApiTrace::SearchResult_Found: {
1319 QModelIndex index = m_proxyModel->indexForCall(call);
1321 if (index.isValid()) {
1322 m_ui.callView->setCurrentIndex(index);
1323 m_searchWidget->setFound(true);
1325 //call is filtered out, so continue searching but from the
1328 qDebug()<<"Error: search success with no call";
1331 // qDebug()<<"filtered! search from "<<call->searchText()
1332 // <<", call idx = "<<call->index();
1334 if (request.direction == ApiTrace::SearchRequest::Next) {
1335 m_trace->findNext(call->parentFrame(), call,
1336 request.text, request.cs);
1338 m_trace->findNext(call->parentFrame(), call,
1339 request.text, request.cs);
1344 case ApiTrace::SearchResult_Wrapped:
1345 m_searchWidget->setFound(false);
1350 ApiTraceFrame * MainWindow::currentFrame() const
1352 QModelIndex index = m_ui.callView->currentIndex();
1353 ApiTraceEvent *event = 0;
1355 if (!index.isValid()) {
1356 index = m_proxyModel->index(0, 0, QModelIndex());
1357 if (!index.isValid()) {
1358 qDebug()<<"no currently valid index";
1363 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1369 ApiTraceFrame *frame = 0;
1370 if (event->type() == ApiTraceCall::Frame) {
1371 frame = static_cast<ApiTraceFrame*>(event);
1376 ApiTraceCall * MainWindow::currentCall() const
1378 QModelIndex index = m_ui.callView->currentIndex();
1379 ApiTraceEvent *event = 0;
1381 if (!index.isValid()) {
1382 index = m_proxyModel->index(0, 0, QModelIndex());
1383 if (!index.isValid()) {
1384 qDebug()<<"no currently valid index";
1389 event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
1395 ApiTraceCall *call = 0;
1396 if (event->type() == ApiTraceCall::Call) {
1397 call = static_cast<ApiTraceCall*>(event);
1404 void MainWindow::slotFoundFrameStart(ApiTraceFrame *frame)
1406 Q_ASSERT(frame->isLoaded());
1407 if (!frame || frame->isEmpty()) {
1411 QVector<ApiTraceCall*>::const_iterator itr;
1412 QVector<ApiTraceCall*> calls = frame->calls();
1414 itr = calls.constBegin();
1415 while (itr != calls.constEnd()) {
1416 ApiTraceCall *call = *itr;
1417 QModelIndex idx = m_proxyModel->indexForCall(call);
1418 if (idx.isValid()) {
1419 m_ui.callView->setCurrentIndex(idx);
1420 m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtTop);
1427 void MainWindow::slotFoundFrameEnd(ApiTraceFrame *frame)
1429 Q_ASSERT(frame->isLoaded());
1430 if (!frame || frame->isEmpty()) {
1433 QVector<ApiTraceCall*>::const_iterator itr;
1434 QVector<ApiTraceCall*> calls = frame->calls();
1436 itr = calls.constEnd();
1439 ApiTraceCall *call = *itr;
1440 QModelIndex idx = m_proxyModel->indexForCall(call);
1441 if (idx.isValid()) {
1442 m_ui.callView->setCurrentIndex(idx);
1443 m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtBottom);
1446 } while (itr != calls.constBegin());
1449 void MainWindow::slotJumpToResult(ApiTraceCall *call)
1451 QModelIndex idx = m_proxyModel->indexForCall(call);
1452 if (idx.isValid()) {
1454 m_ui.callView->setFocus();
1455 m_ui.callView->setCurrentIndex(idx);
1456 m_ui.callView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
1458 statusBar()->showMessage(tr("Call has been filtered out."));
1462 #include "mainwindow.moc"