]> git.cworth.org Git - apitrace/commitdiff
Auto detect the API from the trace.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 27 Mar 2012 22:54:30 +0000 (23:54 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 27 Mar 2012 22:54:30 +0000 (23:54 +0100)
Saves key-presses on the gui for EGL traces.

Might be handy to implement a top level "apitrace retrace" command too.

common/trace_api.hpp
common/trace_parser.cpp
common/trace_parser.hpp
gui/apitrace.cpp
gui/apitrace.h
gui/mainwindow.cpp
gui/retracer.cpp
gui/traceloader.cpp
gui/traceloader.h
gui/ui/settings.ui

index ed4823f5cab2492a3bdeb2abce2872298d2bc2aa..7619f71d1d5d853c98962fda56ba047bb34809fc 100644 (file)
 namespace trace {
 
 
+/**
+ * Enum to distuinguish the API for tools.
+ *
+ * It should never be embedded in the trace file.
+ */
 enum API {
+    API_UNKNOWN = 0,
     API_GL, // GL + GLX/WGL/CGL
     API_EGL, // GL/GLES1/GLES2/VG + EGL
     API_D3D7,
index dc9634f0d36f823b635d26c7efd7bc1a1082625f..12cedac5b7b4ef054b00d952a479f1539104504b 100644 (file)
@@ -43,6 +43,7 @@ Parser::Parser() {
     file = NULL;
     next_call_no = 0;
     version = 0;
+    api = API_UNKNOWN;
 
     glGetErrorSig = NULL;
 }
@@ -65,6 +66,7 @@ bool Parser::open(const char *filename) {
         std::cerr << "error: unsupported trace format version " << version << "\n";
         return false;
     }
+    api = API_UNKNOWN;
 
     return true;
 }
@@ -232,6 +234,25 @@ Parser::parse_function_sig(void) {
         sig->offset = file->currentOffset();
         functions[id] = sig;
 
+        /**
+         * Try to autodetect the API.
+         *
+         * XXX: Ideally we would allow to mix multiple APIs in a single trace,
+         * but as it stands today, retrace is done separately for each API.
+         */
+        if (api == API_UNKNOWN) {
+            const char *n = sig->name;
+            if ((n[0] == 'g' && n[1] == 'l' && n[2] == 'X') || // glX
+                (n[0] == 'w' && n[1] == 'g' && n[2] == 'g' && n[3] >= 'A' && n[3] <= 'Z') || // wgl[A-Z]
+                (n[0] == 'C' && n[1] == 'G' && n[2] == 'L')) { // CGL
+                api = trace::API_GL;
+            } else if (n[0] == 'e' && n[1] == 'g' && n[2] == 'l' && n[3] >= 'A' && n[3] <= 'Z') { // egl
+                api = trace::API_EGL;
+            } else {
+                /* TODO */
+            }
+        }
+
         /**
          * Note down the signature of special functions for future reference.
          *
index d8c5915ea3d8e3976c1b2d38e33d8e8f57a21d53..43c13563a639cb59e535dff580be1e39d22ff28f 100644 (file)
@@ -33,6 +33,7 @@
 #include "trace_file.hpp"
 #include "trace_format.hpp"
 #include "trace_model.hpp"
+#include "trace_api.hpp"
 
 
 namespace trace {
@@ -94,6 +95,7 @@ protected:
 
 public:
     unsigned long long version;
+    API api;
 
     Parser();
 
index ec13ce5ae2f5c9d0e3cbda8e770ba3aec656b47c..b11c17c6740e33520dd366b50fed219ce3283cd4 100644 (file)
@@ -22,6 +22,8 @@ ApiTrace::ApiTrace()
             SIGNAL(frameContentsLoaded(ApiTraceFrame*,QVector<ApiTraceCall*>,quint64)),
             this,
             SLOT(loaderFrameLoaded(ApiTraceFrame*,QVector<ApiTraceCall*>,quint64)));
+    connect(m_loader, SIGNAL(guessedApi(int)),
+            this, SLOT(guessedApi(int)));
     connect(m_loader, SIGNAL(finishedParsing()),
             this, SLOT(finishedParsing()));
     connect(this, SIGNAL(loaderSearch(ApiTrace::SearchRequest)),
@@ -240,6 +242,16 @@ void ApiTrace::loadFrame(ApiTraceFrame *frame)
     }
 }
 
+void ApiTrace::guessedApi(int api)
+{
+    m_api = static_cast<trace::API>(api);
+}
+
+trace::API ApiTrace::api() const
+{
+    return m_api;
+}
+
 void ApiTrace::finishedParsing()
 {
     if (!m_frames.isEmpty()) {
index f3505258138f62fafc4f733aec72a052197e6f8f..04e295cd7e39470476990d834b5085be7bf77997 100644 (file)
@@ -3,6 +3,8 @@
 
 #include "apitracecall.h"
 
+#include "trace_api.hpp"
+
 #include <QObject>
 #include <QSet>
 
@@ -73,6 +75,8 @@ public:
 
     bool hasErrors() const;
 
+    trace::API api() const;
+
 public slots:
     void setFileName(const QString &name);
     void save();
@@ -124,6 +128,7 @@ signals:
 private slots:
     void addFrames(const QList<ApiTraceFrame*> &frames);
     void slotSaved();
+    void guessedApi(int api);
     void finishedParsing();
     void loaderFrameLoaded(ApiTraceFrame *frame,
                            const QVector<ApiTraceCall*> &calls,
@@ -140,6 +145,7 @@ private:
     QString m_tempFileName;
 
     QList<ApiTraceFrame*> m_frames;
+    trace::API m_api;
 
     TraceLoader *m_loader;
     QThread     *m_loaderThread;
index bf56115ddc06d44b4023c4598fb8657ca2b809a2..eeab447137c5c58eec6581b505dafe2e7fe235e4 100644 (file)
@@ -265,6 +265,7 @@ void MainWindow::finishedLoadingTrace()
     if (!m_trace) {
         return;
     }
+    m_api = m_trace->api();
     QFileInfo info(m_trace->fileName());
     statusBar()->showMessage(
         tr("Loaded %1").arg(info.fileName()), 3000);
index aeac9ba0f2fd61ebd1497e7890d5c014f43623d7..d0e07ef9f4d54066e56042ed8df7ae16fd036427 100644 (file)
@@ -234,7 +234,7 @@ void Retracer::run()
     } else if (m_api == trace::API_EGL) {
         prog = QLatin1String("eglretrace");
     } else {
-        Q_ASSERT(0);
+        emit finished(QLatin1String("Unsupported API"));
         return;
     }
 
index 6cd8cff744b4aedfd35857059f9b69d388fa3653..2ad32b1fb4d73523dc4219650ee5ac6cd93a85d6 100644 (file)
@@ -60,6 +60,7 @@ void TraceLoader::loadTrace(const QString &filename)
         //Load the entire file into memory
         parseTrace();
     }
+    emit guessedApi(static_cast<int>(m_parser.api));
     emit finishedParsing();
 }
 
index cdd97c7f4797f7d3fa772918339a44b4fc756351..0954078219fba68bd3e188b72d56027cd3b01d7b 100644 (file)
@@ -35,6 +35,7 @@ public slots:
 signals:
     void startedParsing();
     void parsed(int percent);
+    void guessedApi(int api);
     void finishedParsing();
 
     void framesLoaded(const QList<ApiTraceFrame*> &frames);
@@ -65,6 +66,7 @@ private:
     int numberOfCallsInFrame(int frameIdx) const;
 
     void loadHelpFile();
+    void guessApi(const trace::Call *call);
     void scanTrace();
     void parseTrace();
 
index 683557d62e826e6305ecb59d7b4d1105d71d48ef..dac4bc25f9cdeab746db2ea2a8e6b13f7efb214b 100644 (file)
      <layout class="QVBoxLayout" name="verticalLayout_4">
       <item>
        <widget class="QComboBox" name="apiComboBox">
+        <item>
+         <property name="text">
+          <string>Unknown</string>
+         </property>
+        </item>
         <item>
          <property name="text">
           <string>GL</string>