From: José Fonseca Date: Tue, 27 Mar 2012 22:54:30 +0000 (+0100) Subject: Auto detect the API from the trace. X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=67964385bd2abb065787c52625ed19dbe08f2bf8 Auto detect the API from the trace. Saves key-presses on the gui for EGL traces. Might be handy to implement a top level "apitrace retrace" command too. --- diff --git a/common/trace_api.hpp b/common/trace_api.hpp index ed4823f..7619f71 100644 --- a/common/trace_api.hpp +++ b/common/trace_api.hpp @@ -35,7 +35,13 @@ 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, diff --git a/common/trace_parser.cpp b/common/trace_parser.cpp index dc9634f..12cedac 100644 --- a/common/trace_parser.cpp +++ b/common/trace_parser.cpp @@ -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. * diff --git a/common/trace_parser.hpp b/common/trace_parser.hpp index d8c5915..43c1356 100644 --- a/common/trace_parser.hpp +++ b/common/trace_parser.hpp @@ -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(); diff --git a/gui/apitrace.cpp b/gui/apitrace.cpp index ec13ce5..b11c17c 100644 --- a/gui/apitrace.cpp +++ b/gui/apitrace.cpp @@ -22,6 +22,8 @@ ApiTrace::ApiTrace() SIGNAL(frameContentsLoaded(ApiTraceFrame*,QVector,quint64)), this, SLOT(loaderFrameLoaded(ApiTraceFrame*,QVector,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(api); +} + +trace::API ApiTrace::api() const +{ + return m_api; +} + void ApiTrace::finishedParsing() { if (!m_frames.isEmpty()) { diff --git a/gui/apitrace.h b/gui/apitrace.h index f350525..04e295c 100644 --- a/gui/apitrace.h +++ b/gui/apitrace.h @@ -3,6 +3,8 @@ #include "apitracecall.h" +#include "trace_api.hpp" + #include #include @@ -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 &frames); void slotSaved(); + void guessedApi(int api); void finishedParsing(); void loaderFrameLoaded(ApiTraceFrame *frame, const QVector &calls, @@ -140,6 +145,7 @@ private: QString m_tempFileName; QList m_frames; + trace::API m_api; TraceLoader *m_loader; QThread *m_loaderThread; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index bf56115..eeab447 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -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); diff --git a/gui/retracer.cpp b/gui/retracer.cpp index aeac9ba..d0e07ef 100644 --- a/gui/retracer.cpp +++ b/gui/retracer.cpp @@ -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; } diff --git a/gui/traceloader.cpp b/gui/traceloader.cpp index 6cd8cff..2ad32b1 100644 --- a/gui/traceloader.cpp +++ b/gui/traceloader.cpp @@ -60,6 +60,7 @@ void TraceLoader::loadTrace(const QString &filename) //Load the entire file into memory parseTrace(); } + emit guessedApi(static_cast(m_parser.api)); emit finishedParsing(); } diff --git a/gui/traceloader.h b/gui/traceloader.h index cdd97c7..0954078 100644 --- a/gui/traceloader.h +++ b/gui/traceloader.h @@ -35,6 +35,7 @@ public slots: signals: void startedParsing(); void parsed(int percent); + void guessedApi(int api); void finishedParsing(); void framesLoaded(const QList &frames); @@ -65,6 +66,7 @@ private: int numberOfCallsInFrame(int frameIdx) const; void loadHelpFile(); + void guessApi(const trace::Call *call); void scanTrace(); void parseTrace(); diff --git a/gui/ui/settings.ui b/gui/ui/settings.ui index 683557d..dac4bc2 100644 --- a/gui/ui/settings.ui +++ b/gui/ui/settings.ui @@ -25,6 +25,11 @@ + + + Unknown + + GL