From f72e593d5dd779efc3b9f3d2578917daf31d7968 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 25 Nov 2011 13:16:35 +0000 Subject: [PATCH] Trace via "apitrace trace" command. It could be done via the library directly, but this allows to use QProcess as before, and therefore run asynchronously without extra effort. --- gui/traceprocess.cpp | 68 ++++++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/gui/traceprocess.cpp b/gui/traceprocess.cpp index ae27e81..67cc64a 100644 --- a/gui/traceprocess.cpp +++ b/gui/traceprocess.cpp @@ -5,29 +5,6 @@ #include #include -static QString -findPreloader() -{ - QString libPath; - QFileInfo fi; - -#ifdef APITRACE_BINARY_DIR - libPath = QString::fromLatin1(APITRACE_BINARY_DIR "/wrappers/glxtrace.so"); - fi = QFileInfo(libPath); - if (fi.exists()) - return libPath; -#endif - -#ifdef APITRACE_WRAPPER_INSTALL_DIR - libPath = QString::fromLatin1(APITRACE_WRAPPER_INSTALL_DIR "/glxtrace.so"); - fi = QFileInfo(libPath); - if (fi.exists()) - return libPath; -#endif - - return QString(); -} - TraceProcess::TraceProcess(QObject *parent) : QObject(parent), m_canTrace(true) @@ -43,18 +20,15 @@ TraceProcess::TraceProcess(QObject *parent) qWarning()<<"Windows tracing isn't supported right now!"; m_canTrace = false; #else - QString var = QLatin1String("LD_PRELOAD"); - QString libPath = findPreloader(); +#ifdef Q_OS_WIN + QString format = QLatin1String("%1;"); +#else + QString format = QLatin1String("%1:"); +#endif + QString buildPath = format.arg(APITRACE_BINARY_DIR); QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); - - if (libPath.isEmpty()) { - m_canTrace = false; - } - - env.insert("LD_PRELOAD", libPath); - qputenv("LD_PRELOAD", env.value("LD_PRELOAD").toLatin1()); - - m_process->setProcessEnvironment(env); + env.insert("PATH", buildPath + env.value("PATH")); + qputenv("PATH", env.value("PATH").toLatin1()); #endif } @@ -67,23 +41,18 @@ void TraceProcess::setExecutablePath(const QString &str) m_execPath = str; QFileInfo fi(m_execPath); + QString baseName = fi.baseName(); - m_process->setWorkingDirectory(fi.absolutePath()); - - QString format = QString::fromLatin1("%1%2%3.trace"); + QString format = QString::fromLatin1("%1.trace"); m_tracePath = format - .arg(fi.absolutePath()) - .arg(QDir::separator()) - .arg(fi.baseName()); + .arg(baseName); int i = 1; while (QFile::exists(m_tracePath)) { - QString format = QString::fromLatin1("%1%2%3.%4.trace"); + format = QString::fromLatin1("%1.%2.trace"); m_tracePath = format - .arg(fi.absolutePath()) - .arg(QDir::separator()) - .arg(fi.baseName()) + .arg(baseName) .arg(i++); } } @@ -126,7 +95,16 @@ void TraceProcess::traceError(QProcess::ProcessError err) void TraceProcess::start() { - m_process->start(m_execPath, m_args); + QStringList arguments; + + arguments << QLatin1String("trace"); + arguments << QLatin1String("--output"); + arguments << m_tracePath; + arguments << QLatin1String("--"); + arguments << m_execPath; + arguments << m_args; + + m_process->start(QLatin1String("apitrace"), arguments); } bool TraceProcess::canTrace() const -- 2.7.4