]> git.cworth.org Git - apitrace/blobdiff - gui/retracer.cpp
Lookup call state on double-click.
[apitrace] / gui / retracer.cpp
index eaa86e33ef4844363994a2e41886dbf36c8c3097..17ac14d7d8d13a97da4f2e1a61455770e9b1104d 100644 (file)
@@ -38,6 +38,11 @@ void Retracer::setFileName(const QString &name)
     m_fileName = name;
 }
 
+void Retracer::setAPI(trace::API api)
+{
+    m_api = api;
+}
+
 bool Retracer::isBenchmarking() const
 {
     return m_benchmarking;
@@ -85,6 +90,7 @@ void Retracer::run()
     retrace->process()->setProcessEnvironment(m_processEnvironment);
 
     retrace->setFileName(m_fileName);
+    retrace->setAPI(m_api);
     retrace->setBenchmarking(m_benchmarking);
     retrace->setDoubleBuffered(m_doubleBuffered);
     retrace->setCaptureState(m_captureState);
@@ -118,8 +124,18 @@ void Retracer::run()
 
 void RetraceProcess::start()
 {
+    QString prog;
     QStringList arguments;
 
+    if (m_api == trace::API_GL) {
+        prog = QLatin1String("glretrace");
+    } else if (m_api == trace::API_EGL) {
+        prog = QLatin1String("eglretrace");
+    } else {
+        assert(0);
+        return;
+    }
+
     if (m_doubleBuffered) {
         arguments << QLatin1String("-db");
     } else {
@@ -137,11 +153,11 @@ void RetraceProcess::start()
 
     arguments << m_fileName;
 
-    m_process->start(QLatin1String("glretrace"), arguments);
+    m_process->start(prog, arguments);
 }
 
 
-void RetraceProcess::replayFinished()
+void RetraceProcess::replayFinished(int exitCode, QProcess::ExitStatus exitStatus)
 {
     QByteArray output = m_process->readAllStandardOutput();
     QString msg;
@@ -152,14 +168,21 @@ void RetraceProcess::replayFinished()
     qDebug()<<"\terr = "<<errStr;
     qDebug()<<"\tout = "<<output;
 #endif
-    if (m_captureState) {
-        bool ok = false;
-        QVariantMap parsedJson = m_jsonParser->parse(output, &ok).toMap();
-        ApiTraceState *state = new ApiTraceState(parsedJson);
-        emit foundState(state);
-        msg = tr("State fetched.");
+
+    if (exitStatus != QProcess::NormalExit) {
+        msg = QLatin1String("Process crashed");
+    } else if (exitCode != 0) {
+        msg = QLatin1String("Process exited with non zero exit code");
     } else {
-        msg = QString::fromUtf8(output);
+        if (m_captureState) {
+            bool ok = false;
+            QVariantMap parsedJson = m_jsonParser->parse(output, &ok).toMap();
+            ApiTraceState *state = new ApiTraceState(parsedJson);
+            emit foundState(state);
+            msg = tr("State fetched.");
+        } else {
+            msg = QString::fromUtf8(output);
+        }
     }
 
     QStringList errorLines = errStr.split('\n');
@@ -182,9 +205,16 @@ void RetraceProcess::replayFinished()
 
 void RetraceProcess::replayError(QProcess::ProcessError err)
 {
+    /*
+     * XXX: this function is likely unnecessary and should be eliminated given
+     * that replayFinished is always called, even on errors.
+     */
+
+#if 0
     qDebug()<<"Process error = "<<err;
     qDebug()<<"\terr = "<<m_process->readAllStandardError();
     qDebug()<<"\tout = "<<m_process->readAllStandardOutput();
+#endif
 
     emit error(
         tr("Couldn't execute the replay file '%1'").arg(m_fileName));
@@ -200,7 +230,7 @@ RetraceProcess::RetraceProcess(QObject *parent)
     qRegisterMetaType<QList<ApiTraceError> >();
 
     connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
-            this, SLOT(replayFinished()));
+            this, SLOT(replayFinished(int, QProcess::ExitStatus)));
     connect(m_process, SIGNAL(error(QProcess::ProcessError)),
             this, SLOT(replayError(QProcess::ProcessError)));
 }
@@ -220,6 +250,11 @@ void RetraceProcess::setFileName(const QString &name)
     m_fileName = name;
 }
 
+void RetraceProcess::setAPI(trace::API api)
+{
+    m_api = api;
+}
+
 bool RetraceProcess::isBenchmarking() const
 {
     return m_benchmarking;