]> git.cworth.org Git - apitrace/commitdiff
Let retrace dump state.
authorZack Rusin <zack@kde.org>
Wed, 30 Mar 2011 22:30:20 +0000 (18:30 -0400)
committerZack Rusin <zack@kde.org>
Thu, 31 Mar 2011 02:48:42 +0000 (22:48 -0400)
without parsing it right now

gui/apitrace.cpp
gui/apitracecall.h
gui/loaderthread.cpp
gui/mainwindow.cpp
gui/mainwindow.h
gui/ui/mainwindow.ui

index 4d7a17c427d2df8ad268c628f2afe4d6884260a4..45fbfda9004f4ee2944607dc879b29148bd7a72d 100644 (file)
@@ -152,7 +152,6 @@ void ApiTrace::detectFrames()
             currentFrame->number = m_frames.count();
         }
         apiCall->parentFrame = currentFrame;
-        apiCall->index = currentFrame->calls.count();
         currentFrame->calls.append(apiCall);
         if (ApiTrace::isCallAFrameMarker(apiCall,
                                          m_frameMarker)) {
index 8f38bdaffa2c88490cda7e9ff767733ddf9c1e8e..fcafd5818e210e795fe0955b15b32f90c7486be2 100644 (file)
@@ -153,6 +153,7 @@ public:
     int number;
     QList<ApiTraceCall*> calls;
 
+    QMap<QString, QVariant> state;
 
     int numChildren() const;
     QStaticText staticText() const;
index 2ec06ec749f649405c14317b95c839eee516d6c9..207c2a5def9f2eecd0f4e071fece2e7baab3d9e2 100644 (file)
@@ -9,6 +9,7 @@ apiCallFromTraceCall(const Trace::Call *call)
 {
     ApiTraceCall *apiCall = new ApiTraceCall();
     apiCall->name = QString::fromStdString(call->sig->name);
+    apiCall->index = call->no;
 
     QString argumentsText;
     for (int i = 0; i < call->sig->arg_names.size(); ++i) {
@@ -54,7 +55,6 @@ void LoaderThread::run()
             ApiTraceCall *apiCall =
                 apiCallFromTraceCall(call);
             apiCall->parentFrame = currentFrame;
-            apiCall->index = currentFrame->calls.count();
             currentFrame->calls.append(apiCall);
             if (ApiTrace::isCallAFrameMarker(apiCall,
                                              m_frameMarker)) {
index 63864bfa1787b01fdee05b9c78657de986e6bc45..472ff27a4cac4a8fe78c2aef8472026df776fc65 100644 (file)
@@ -20,7 +20,8 @@
 
 MainWindow::MainWindow()
     : QMainWindow(),
-      m_replayProcess(0)
+      m_replayProcess(0),
+      m_findingState(false)
 {
     m_ui.setupUi(this);
 
@@ -59,6 +60,8 @@ MainWindow::MainWindow()
             this, SLOT(replayStart()));
     connect(m_ui.actionStop, SIGNAL(triggered()),
             this, SLOT(replayStop()));
+    connect(m_ui.actionLookupState, SIGNAL(triggered()),
+            this, SLOT(lookupState()));
 
     connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
             this, SLOT(callItemSelected(const QModelIndex &)));
@@ -99,7 +102,9 @@ void MainWindow::callItemSelected(const QModelIndex &index)
     if (call) {
         m_ui.detailsWebView->setHtml(call->toHtml());
         m_ui.detailsDock->show();
+        m_currentFrame = call->parentFrame;
     } else {
+        m_currentFrame = index.data().value<ApiTraceFrame*>();
         m_ui.detailsDock->hide();
     }
 }
@@ -111,38 +116,7 @@ void MainWindow::filterTrace()
 
 void MainWindow::replayStart()
 {
-    if (!m_replayProcess) {
-#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_replayProcess = new QProcess(this);
-        m_replayProcess->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;
-    arguments << m_traceFileName;
-
-    m_replayProcess->start(QLatin1String("glretrace"),
-                           arguments);
-
-    m_ui.actionStop->setEnabled(true);
-    m_ui.actionReplay->setEnabled(false);
+    replayTrace(false);
 }
 
 void MainWindow::replayStop()
@@ -152,6 +126,7 @@ void MainWindow::replayStop()
 
         m_ui.actionStop->setEnabled(false);
         m_ui.actionReplay->setEnabled(true);
+        m_ui.actionLookupState->setEnabled(true);
     }
 }
 
@@ -162,8 +137,10 @@ void MainWindow::newTraceFile(const QString &fileName)
 
     if (m_traceFileName.isEmpty()) {
         m_ui.actionReplay->setEnabled(false);
+        m_ui.actionLookupState->setEnabled(false);
     } else {
         m_ui.actionReplay->setEnabled(true);
+        m_ui.actionLookupState->setEnabled(true);
     }
 }
 
@@ -171,16 +148,19 @@ void MainWindow::replayFinished()
 {
     m_ui.actionStop->setEnabled(false);
     m_ui.actionReplay->setEnabled(true);
+    m_ui.actionLookupState->setEnabled(true);
 
-    QString output = m_replayProcess->readAllStandardOutput();
+    QByteArray output = m_replayProcess->readAllStandardOutput();
 
-#if 0
+#if 1
     qDebug()<<"Process finished = ";
     qDebug()<<"\terr = "<<m_replayProcess->readAllStandardError();
     qDebug()<<"\tout = "<<output;
 #endif
 
-    if (output.length() < 80) {
+    if (m_findingState) {
+        qDebug()<<"json parse";
+    } else if (output.length() < 80) {
         statusBar()->showMessage(output);
     }
 }
@@ -189,6 +169,8 @@ void MainWindow::replayError(QProcess::ProcessError err)
 {
     m_ui.actionStop->setEnabled(false);
     m_ui.actionReplay->setEnabled(true);
+    m_ui.actionLookupState->setEnabled(true);
+    m_findingState = false;
 
     qDebug()<<"Process error = "<<err;
     qDebug()<<"\terr = "<<m_replayProcess->readAllStandardError();
@@ -218,4 +200,56 @@ void MainWindow::finishedLoadingTrace()
         tr("Loaded %1").arg(info.fileName()), 3000);
 }
 
+void MainWindow::replayTrace(bool dumpState)
+{
+    if (!m_replayProcess) {
+#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_replayProcess = new QProcess(this);
+        m_replayProcess->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_currentFrame && !m_currentFrame->calls.isEmpty()) {
+        arguments << QLatin1String("-D");
+        arguments << QString::number(m_currentFrame->calls.first()->index);
+    }
+    arguments << m_traceFileName;
+
+    m_replayProcess->start(QLatin1String("glretrace"),
+                           arguments);
+
+    m_ui.actionStop->setEnabled(true);
+}
+
+void MainWindow::lookupState()
+{
+    if (!m_currentFrame) {
+        QMessageBox::warning(
+            this, tr("Unknown Frame"),
+            tr("To inspect the state select a frame in the trace."));
+        return;
+    }
+    m_findingState = true;
+    replayTrace(true);
+}
+
 #include "mainwindow.moc"
index a771bd9c0bb63ad67508002bcb9594cb98950969..598a61236912ea71029315383bfe6184fd13fa37 100644 (file)
@@ -7,6 +7,7 @@
 #include <QProcess>
 
 class ApiTrace;
+class ApiTraceFrame;
 class ApiTraceModel;
 class ApiTraceFilter;
 class QLineEdit;
@@ -33,9 +34,11 @@ private slots:
     void replayError(QProcess::ProcessError err);
     void startedLoadingTrace();
     void finishedLoadingTrace();
+    void lookupState();
 
 private:
     void newTraceFile(const QString &fileName);
+    void replayTrace(bool dumpState);
 
 private:
     Ui_MainWindow m_ui;
@@ -49,6 +52,9 @@ private:
     QProgressBar *m_progressBar;
 
     QString m_traceFileName;
+
+    ApiTraceFrame *m_currentFrame;
+    bool m_findingState;
 };
 
 
index f60042cdc88d8933fd34963506ff129a290a684b..229aaebb309f51baf8691fbf863cd98c41a76de0 100644 (file)
@@ -50,6 +50,7 @@
     </property>
     <addaction name="actionReplay"/>
     <addaction name="actionStop"/>
+    <addaction name="actionLookupState"/>
    </widget>
    <addaction name="menuFile"/>
    <addaction name="menu_Trace"/>
     <string>&amp;Stop</string>
    </property>
   </action>
+  <action name="actionLookupState">
+   <property name="enabled">
+    <bool>false</bool>
+   </property>
+   <property name="text">
+    <string>Lookup State</string>
+   </property>
+  </action>
  </widget>
  <customwidgets>
   <customwidget>