From 1c3ddde4d8cd6a1c57b48caa2bfc278fbbaeee5b Mon Sep 17 00:00:00 2001 From: Dan McCabe Date: Wed, 21 Mar 2012 09:53:45 -0700 Subject: [PATCH] Add trim support to qapitrace GUI app. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch adds support for trimming of traces via the qapitrace GUI. We enhance the GUI by adding a Trim entry to the Trace menu. When the user selects either a frame or a call, the "apitrace trim" command will be invoked to trim all calls after the selected call or frame. New trace files are created automatically and named according to the last call number in the trimmed trace. For example, if the original trace file is: /path/foo.trace and the trace is trimmed after call 1234, the name of the trimmed trace file will be named: /path/foo.1234.trim.trace Upon trimming, the trimmed trace file will be loaded into qapitrace. First, we enhance the Trace menu of the GUI app. Next, we add a TrimProcess class. This is modelled on the TraceProcess class, but takes into account differences and simplifications. Next, we tie the TrimProcess class into the main window by accessing that class and its members appropriately as well as tieing in message communication with that class. Finally, we add a reference to the source of TrimProcess to the make system. Signed-off-by: José Fonseca --- gui/CMakeLists.txt | 1 + gui/mainwindow.cpp | 56 ++++++++++++++++++++ gui/mainwindow.h | 9 ++++ gui/trimprocess.cpp | 120 +++++++++++++++++++++++++++++++++++++++++++ gui/trimprocess.h | 45 ++++++++++++++++ gui/ui/mainwindow.ui | 12 +++++ 6 files changed, 243 insertions(+) create mode 100644 gui/trimprocess.cpp create mode 100644 gui/trimprocess.h diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 26346f2..070aca7 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -22,6 +22,7 @@ set(qapitrace_SRCS tracedialog.cpp traceloader.cpp traceprocess.cpp + trimprocess.cpp vertexdatainterpreter.cpp ) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 5e2a55d..2e39bb8 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -14,6 +14,7 @@ #include "shaderssourcewidget.h" #include "tracedialog.h" #include "traceprocess.h" +#include "trimprocess.h" #include "thumbnail.h" #include "ui_retracerdialog.h" #include "vertexdatainterpreter.h" @@ -207,6 +208,7 @@ void MainWindow::newTraceFile(const QString &fileName) m_ui.actionReplay->setEnabled(true); m_ui.actionLookupState->setEnabled(true); m_ui.actionShowThumbnails->setEnabled(true); + m_ui.actionTrim->setEnabled(true); setWindowTitle( tr("QApiTrace - %1").arg(info.fileName())); } @@ -320,6 +322,25 @@ void MainWindow::replayTrace(bool dumpState, bool dumpThumbnails) } } +void MainWindow::trimEvent() +{ + + int trimIndex; + if (m_trimEvent->type() == ApiTraceEvent::Call) { + ApiTraceCall *call = static_cast(m_trimEvent); + trimIndex = call->index(); + } else if (m_trimEvent->type() == ApiTraceEvent::Frame) { + ApiTraceFrame *frame = static_cast(m_trimEvent); + const QList frames = m_trace->frames(); + trimIndex = frame->lastCallIndex(); + } + + m_trimProcess->setTracePath(m_trace->fileName()); + m_trimProcess->setTrimIndex(trimIndex); + + m_trimProcess->start(); +} + void MainWindow::lookupState() { if (!m_selectedEvent) { @@ -345,6 +366,18 @@ void MainWindow::showThumbnails() replayTrace(false, true); } +void MainWindow::trim() +{ + if (!m_selectedEvent) { + QMessageBox::warning( + this, tr("Unknown Event"), + tr("To trim select a frame or an event in the event list.")); + return; + } + m_trimEvent = m_selectedEvent; + trimEvent(); +} + MainWindow::~MainWindow() { delete m_trace; @@ -726,6 +759,7 @@ void MainWindow::initObjects() m_searchWidget->hide(); m_traceProcess = new TraceProcess(this); + m_trimProcess = new TrimProcess(this); } void MainWindow::initConnections() @@ -796,6 +830,8 @@ void MainWindow::initConnections() this, SLOT(replayStop())); connect(m_ui.actionLookupState, SIGNAL(triggered()), this, SLOT(lookupState())); + connect(m_ui.actionTrim, SIGNAL(triggered()), + this, SLOT(trim())); connect(m_ui.actionShowThumbnails, SIGNAL(triggered()), this, SLOT(showThumbnails())); connect(m_ui.actionOptions, SIGNAL(triggered()), @@ -836,6 +872,11 @@ void MainWindow::initConnections() connect(m_traceProcess, SIGNAL(error(const QString&)), SLOT(traceError(const QString&))); + connect(m_trimProcess, SIGNAL(trimmedFile(const QString&)), + SLOT(createdTrim(const QString&))); + connect(m_trimProcess, SIGNAL(error(const QString&)), + SLOT(trimError(const QString&))); + connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)), m_ui.actionShowErrorsDock, SLOT(setChecked(bool))); connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)), @@ -889,6 +930,21 @@ void MainWindow::traceError(const QString &msg) msg); } +void MainWindow::createdTrim(const QString &path) +{ + qDebug()<<"Done trimming "<hide(); diff --git a/gui/mainwindow.h b/gui/mainwindow.h index a8f8c1d..1346b86 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -29,6 +29,7 @@ class Retracer; class SearchWidget; class ShadersSourceWidget; class TraceProcess; +class TrimProcess; class VertexDataInterpreter; class MainWindow : public QMainWindow @@ -57,6 +58,7 @@ private slots: void finishedLoadingTrace(); void lookupState(); void showThumbnails(); + void trim(); void showSettings(); void openHelp(const QUrl &url); void showSurfacesMenu(const QPoint &pos); @@ -66,6 +68,8 @@ private slots: void slotJumpTo(int callNum); void createdTrace(const QString &path); void traceError(const QString &msg); + void createdTrim(const QString &path); + void trimError(const QString &msg); void slotSearch(); void slotSearchNext(const QString &str, Qt::CaseSensitivity sensitivity); void slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitivity); @@ -91,6 +95,7 @@ private: void initConnections(); void newTraceFile(const QString &fileName); void replayTrace(bool dumpState, bool dumpThumbnails); + void trimEvent(); void fillStateForFrame(); /* there's a difference between selected frame/call and @@ -120,6 +125,8 @@ private: ApiTraceEvent *m_stateEvent; + ApiTraceEvent *m_trimEvent; + Retracer *m_retracer; VertexDataInterpreter *m_vdataInterpreter; @@ -129,6 +136,8 @@ private: TraceProcess *m_traceProcess; + TrimProcess *m_trimProcess; + ArgumentsEditor *m_argsEditor; ApiTraceEvent *m_nonDefaultsLookupEvent; diff --git a/gui/trimprocess.cpp b/gui/trimprocess.cpp new file mode 100644 index 0000000..c23475d --- /dev/null +++ b/gui/trimprocess.cpp @@ -0,0 +1,120 @@ +#include "trimprocess.h" +#include "apitrace.h" + +#include +#include +#include +#include + +TrimProcess::TrimProcess(QObject *parent) + : QObject(parent) +{ + m_process = new QProcess(this); + + connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), + this, SLOT(trimFinished())); + connect(m_process, SIGNAL(error(QProcess::ProcessError)), + this, SLOT(trimError(QProcess::ProcessError))); + +#ifdef Q_OS_WIN + QString format = QLatin1String("%1;"); +#else + QString format = QLatin1String("%1:"); +#endif + QString buildPath = format.arg(APITRACE_BINARY_DIR); + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + env.insert("PATH", buildPath + env.value("PATH")); + qputenv("PATH", env.value("PATH").toLatin1()); +} + +TrimProcess::~TrimProcess() +{ +} + +void TrimProcess::trimFinished() +{ + // consume verbose output spew + QByteArray outputStrings = m_process->readAllStandardOutput(); + QByteArray errorStrings = m_process->readAllStandardError(); +#if 0 + qDebug()<<"trim finished on " << m_trimPath; + qDebug()<<"\terr = "<start(QLatin1String("apitrace"), arguments); +} + +int TrimProcess::trimIndex() +{ + return m_trimIndex; +} + +void TrimProcess::setTrimIndex(int trimIndex) +{ + m_trimIndex = trimIndex; + + updateTrimPath(); +} + +void TrimProcess::setTracePath(const QString &str) +{ + m_tracePath = str; + + updateTrimPath(); +} + +QString TrimProcess::tracePath() const +{ + return m_tracePath; +} + +void TrimProcess::updateTrimPath() +{ + + QFileInfo fi(m_tracePath); + QString baseName = fi.baseName(); + QString path = fi.path(); + + QString format = QString::fromLatin1("%1/%2.%3.trim.trace"); + + m_trimPath = format + .arg(path) + .arg(baseName) + .arg(m_trimIndex); +} + +#include "trimprocess.moc" diff --git a/gui/trimprocess.h b/gui/trimprocess.h new file mode 100644 index 0000000..1cc796c --- /dev/null +++ b/gui/trimprocess.h @@ -0,0 +1,45 @@ +#ifndef TRIMPROCESS_H +#define TRIMPROCESS_H + +#include "apitrace.h" + +#include +#include + +class TrimProcess : public QObject +{ + Q_OBJECT +public: + TrimProcess(QObject *parent=0); + ~TrimProcess(); + + void setTrimIndex(int trimIndex); + int trimIndex(); + + void setTracePath(const QString &str); + QString tracePath() const; + +private: + void updateTrimPath(); + +public slots: + void start(); + +signals: + void trimmedFile(const QString &trimPath); + void error(const QString &msg); + +private slots: + void trimFinished(); + void trimError(QProcess::ProcessError err); + +private: + QStringList m_args; + QString m_tracePath; + QString m_trimPath; + ApiTraceEvent *m_trimEvent; + int m_trimIndex; + QProcess *m_process; +}; + +#endif diff --git a/gui/ui/mainwindow.ui b/gui/ui/mainwindow.ui index 52cf49e..cb60ad9 100644 --- a/gui/ui/mainwindow.ui +++ b/gui/ui/mainwindow.ui @@ -76,6 +76,7 @@ + @@ -537,6 +538,17 @@ Ctrl+T + + + false + + + Tr&im + + + Ctrl+I + + Options -- 2.43.0