From: Zack Rusin Date: Wed, 6 Apr 2011 05:11:55 +0000 (-0400) Subject: Abstract retracing into a class of its own. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=3acde366b677d3d68e85116f795c7a569ee3d18a;p=apitrace Abstract retracing into a class of its own. preparing for adding options to benchmark and use double buffering from the gui. --- diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 7917104..620f424 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -7,6 +7,7 @@ set(qapitrace_SRCS loaderthread.cpp mainwindow.cpp main.cpp + retracer.cpp settingsdialog.cpp ) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 0a3349b..f221112 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -5,6 +5,7 @@ #include "apicalldelegate.h" #include "apitracemodel.h" #include "apitracefilter.h" +#include "retracer.h" #include "settingsdialog.h" #include @@ -15,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -23,10 +23,8 @@ MainWindow::MainWindow() : QMainWindow(), - m_replayProcess(0), m_selectedEvent(0), m_stateEvent(0), - m_findingState(false), m_jsonParser(new QJson::Parser()) { m_ui.setupUi(this); @@ -38,6 +36,12 @@ MainWindow::MainWindow() connect(m_trace, SIGNAL(finishedLoadingTrace()), this, SLOT(finishedLoadingTrace())); + m_retracer = new Retracer(this); + connect(m_retracer, SIGNAL(finished(const QByteArray&)), + this, SLOT(replayFinished(const QByteArray&))); + connect(m_retracer, SIGNAL(error(const QString&)), + this, SLOT(replayError(const QString&))); + m_model = new ApiTraceModel(); m_model->setApiTrace(m_trace); m_proxyModel = new ApiTraceFilter(); @@ -142,13 +146,10 @@ void MainWindow::replayStart() void MainWindow::replayStop() { - if (m_replayProcess) { - m_replayProcess->kill(); - - m_ui.actionStop->setEnabled(false); - m_ui.actionReplay->setEnabled(true); - m_ui.actionLookupState->setEnabled(true); - } + m_retracer->terminate(); + m_ui.actionStop->setEnabled(false); + m_ui.actionReplay->setEnabled(true); + m_ui.actionLookupState->setEnabled(true); } void MainWindow::newTraceFile(const QString &fileName) @@ -165,21 +166,13 @@ void MainWindow::newTraceFile(const QString &fileName) } } -void MainWindow::replayFinished() +void MainWindow::replayFinished(const QByteArray &output) { m_ui.actionStop->setEnabled(false); m_ui.actionReplay->setEnabled(true); m_ui.actionLookupState->setEnabled(true); - QByteArray output = m_replayProcess->readAllStandardOutput(); - -#if 0 - qDebug()<<"Process finished = "; - qDebug()<<"\terr = "<readAllStandardError(); - qDebug()<<"\tout = "<captureState()) { bool ok = false; QVariantMap parsedJson = m_jsonParser->parse(output, &ok).toMap(); parseState(parsedJson[QLatin1String("parameters")].toMap()); @@ -187,23 +180,17 @@ void MainWindow::replayFinished() statusBar()->showMessage(output); } m_stateEvent = 0; - m_findingState = false; } -void MainWindow::replayError(QProcess::ProcessError err) +void MainWindow::replayError(const QString &message) { m_ui.actionStop->setEnabled(false); m_ui.actionReplay->setEnabled(true); m_ui.actionLookupState->setEnabled(true); - m_findingState = false; m_stateEvent = 0; - qDebug()<<"Process error = "<setProcessEnvironment(env); - - connect(m_replayProcess, SIGNAL(finished(int, QProcess::ExitStatus)), - this, SLOT(replayFinished())); - connect(m_replayProcess, SIGNAL(error(QProcess::ProcessError)), - this, SLOT(replayError(QProcess::ProcessError))); - } - if (m_traceFileName.isEmpty()) return; - QStringList arguments; - if (dumpState && - m_selectedEvent) { + m_retracer->setFileName(m_traceFileName); + m_retracer->setCaptureState(dumpState); + if (m_retracer->captureState() && m_selectedEvent) { int index = 0; if (m_selectedEvent->type() == ApiTraceEvent::Call) { index = static_cast(m_selectedEvent)->index; @@ -270,13 +236,9 @@ void MainWindow::replayTrace(bool dumpState) qDebug()<<"Unknown event type"; return; } - arguments << QLatin1String("-D"); - arguments << QString::number(index); + m_retracer->setCaptureAtCallNumber(index); } - arguments << m_traceFileName; - - m_replayProcess->start(QLatin1String("glretrace"), - arguments); + m_retracer->start(); m_ui.actionStop->setEnabled(true); } @@ -290,7 +252,6 @@ void MainWindow::lookupState() return; } m_stateEvent = m_selectedEvent; - m_findingState = true; replayTrace(true); } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index e66bd93..9d0c15e 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -13,8 +13,8 @@ class ApiTraceFrame; class ApiTraceModel; class QLineEdit; class QModelIndex; -class QProcess; class QProgressBar; +class Retracer; namespace QJson { class Parser; @@ -36,8 +36,8 @@ private slots: void filterTrace(); void replayStart(); void replayStop(); - void replayFinished(); - void replayError(QProcess::ProcessError err); + void replayFinished(const QByteArray &output); + void replayError(const QString &msg); void startedLoadingTrace(); void finishedLoadingTrace(); void lookupState(); @@ -56,8 +56,6 @@ private: ApiTraceFilter *m_proxyModel; QLineEdit *m_filterEdit; - QProcess *m_replayProcess; - QProgressBar *m_progressBar; QString m_traceFileName; @@ -65,9 +63,10 @@ private: ApiTraceEvent *m_selectedEvent; ApiTraceEvent *m_stateEvent; - bool m_findingState; QJson::Parser *m_jsonParser; + + Retracer *m_retracer; }; diff --git a/gui/retracer.cpp b/gui/retracer.cpp new file mode 100644 index 0000000..b9d74b6 --- /dev/null +++ b/gui/retracer.cpp @@ -0,0 +1,136 @@ +#include "retracer.h" + +#include + +Retracer::Retracer(QObject *parent) + : QObject(parent), + m_benchmarking(true), + m_doubleBuffered(true), + m_captureState(false), + m_captureCall(0), + m_process(0) +{ +} + +QString Retracer::fileName() const +{ + return m_fileName; +} + +void Retracer::setFileName(const QString &name) +{ + m_fileName = name; +} + +bool Retracer::isBenchmarking() const +{ + return m_benchmarking; +} + +void Retracer::setBenchmarking(bool bench) +{ + m_benchmarking = bench; +} + +bool Retracer::isDoubleBuffered() const +{ + return m_doubleBuffered; +} + +void Retracer::setDoubleBuffered(bool db) +{ + m_doubleBuffered = db; +} + +void Retracer::start() +{ + if (!m_process) { +#ifdef Q_OS_WIN + QString format = QLatin1String("%1;"); +#else + QString format = QLatin1String("%1:"); +#endif + QString buildPath = format.arg(BUILD_DIR); + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + env.insert("PATH", buildPath + env.value("PATH")); + + qputenv("PATH", env.value("PATH").toLatin1()); + + m_process = new QProcess(this); + m_process->setProcessEnvironment(env); + + connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), + this, SLOT(replayFinished())); + connect(m_process, SIGNAL(error(QProcess::ProcessError)), + this, SLOT(replayError(QProcess::ProcessError))); + } + + QStringList arguments; + + if (m_captureState) { + arguments << QLatin1String("-D"); + arguments << QString::number(m_captureCall); + } else { + if (m_benchmarking) { + arguments << QLatin1String("-b"); + } + if (m_doubleBuffered) { + arguments << QLatin1String("-db"); + } + } + + arguments << m_fileName; + + m_process->start(QLatin1String("glretrace"), arguments); +} + +void Retracer::terminate() +{ + if (m_process) { + m_process->terminate(); + } +} + +void Retracer::setCaptureAtCallNumber(qlonglong num) +{ + m_captureCall = num; +} + +qlonglong Retracer::captureAtCallNumber() const +{ + return m_captureCall; +} + +bool Retracer::captureState() const +{ + return m_captureState; +} + +void Retracer::setCaptureState(bool enable) +{ + m_captureState = enable; +} + +void Retracer::replayFinished() +{ + QByteArray output = m_process->readAllStandardOutput(); + +#if 0 + qDebug()<<"Process finished = "; + qDebug()<<"\terr = "<readAllStandardError(); + qDebug()<<"\tout = "< +#include + +class Retracer : public QObject +{ + Q_OBJECT +public: + Retracer(QObject *parent=0); + + QString fileName() const; + void setFileName(const QString &name); + + bool isBenchmarking() const; + void setBenchmarking(bool bench); + + bool isDoubleBuffered() const; + void setDoubleBuffered(bool db); + + void setCaptureAtCallNumber(qlonglong num); + qlonglong captureAtCallNumber() const; + + bool captureState() const; + void setCaptureState(bool enable); + +public slots: + void start(); + void terminate(); + +signals: + void finished(const QByteArray &output); + void error(const QString &msg); + +private slots: + void replayFinished(); + void replayError(QProcess::ProcessError err); +private: + QString m_fileName; + bool m_benchmarking; + bool m_doubleBuffered; + bool m_captureState; + qlonglong m_captureCall; + + QProcess *m_process; +}; + +#endif