X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=gui%2Fretracer.cpp;h=2de9d23ee849de85f12c6cbf51461750ba7edf68;hb=7257dfcc57b3a1af576a8a2ca69992ae8d77dea4;hp=983cd1a99f21f4f8f70c2c18ac49233afb737d53;hpb=1da480dd320a9d3d631a94025ca40609099f6d34;p=apitrace diff --git a/gui/retracer.cpp b/gui/retracer.cpp index 983cd1a..2de9d23 100644 --- a/gui/retracer.cpp +++ b/gui/retracer.cpp @@ -3,7 +3,9 @@ #include "apitracecall.h" #include "thumbnail.h" -#include "image.hpp" +#include "image/image.hpp" + +#include "trace_profiler.hpp" #include #include @@ -129,22 +131,12 @@ Retracer::Retracer(QObject *parent) m_benchmarking(false), m_doubleBuffered(true), m_captureState(false), - m_captureCall(0) + m_captureCall(0), + m_profileGpu(false), + m_profileCpu(false), + m_profilePixels(false) { qRegisterMetaType >(); - -#ifdef Q_OS_WIN - QString format = QLatin1String("%1;"); -#else - QString format = QLatin1String("%1:"); -#endif - QString buildPath = format.arg(APITRACE_BINARY_DIR); - m_processEnvironment = QProcessEnvironment::systemEnvironment(); - m_processEnvironment.insert("PATH", buildPath + - m_processEnvironment.value("PATH")); - - qputenv("PATH", - m_processEnvironment.value("PATH").toLatin1()); } QString Retracer::fileName() const @@ -157,6 +149,16 @@ void Retracer::setFileName(const QString &name) m_fileName = name; } +QString Retracer::remoteTarget() const +{ + return m_remoteTarget; +} + +void Retracer::setRemoteTarget(const QString &host) +{ + m_remoteTarget = host; +} + void Retracer::setAPI(trace::API api) { m_api = api; @@ -182,6 +184,33 @@ void Retracer::setDoubleBuffered(bool db) m_doubleBuffered = db; } +bool Retracer::isProfilingGpu() const +{ + return m_profileGpu; +} + +bool Retracer::isProfilingCpu() const +{ + return m_profileCpu; +} + +bool Retracer::isProfilingPixels() const +{ + return m_profilePixels; +} + +bool Retracer::isProfiling() const +{ + return m_profileGpu || m_profileCpu || m_profilePixels; +} + +void Retracer::setProfiling(bool gpu, bool cpu, bool pixels) +{ + m_profileGpu = gpu; + m_profileCpu = cpu; + m_profilePixels = pixels; +} + void Retracer::setCaptureAtCallNumber(qlonglong num) { m_captureCall = num; @@ -212,7 +241,6 @@ void Retracer::setCaptureThumbnails(bool enable) m_captureThumbnails = enable; } - /** * Starting point for the retracing thread. * @@ -229,33 +257,72 @@ void Retracer::run() QString prog; QStringList arguments; - if (m_api == trace::API_GL) { + switch (m_api) { + case trace::API_GL: prog = QLatin1String("glretrace"); - } else if (m_api == trace::API_EGL) { + break; + case trace::API_EGL: prog = QLatin1String("eglretrace"); - } else { + break; + case trace::API_DX: + case trace::API_D3D7: + case trace::API_D3D8: + case trace::API_D3D9: + case trace::API_DXGI: +#ifdef Q_OS_WIN + prog = QLatin1String("d3dretrace"); +#else + prog = QLatin1String("wine"); + arguments << QLatin1String("d3dretrace.exe"); +#endif + break; + default: emit finished(QLatin1String("Unsupported API")); return; } - if (m_doubleBuffered) { - arguments << QLatin1String("-db"); - } else { - arguments << QLatin1String("-sb"); - } - if (m_captureState) { arguments << QLatin1String("-D"); arguments << QString::number(m_captureCall); } else if (m_captureThumbnails) { arguments << QLatin1String("-s"); // emit snapshots arguments << QLatin1String("-"); // emit to stdout - } else if (m_benchmarking) { - arguments << QLatin1String("-b"); + } else if (isProfiling()) { + if (m_profileGpu) { + arguments << QLatin1String("--pgpu"); + } + + if (m_profileCpu) { + arguments << QLatin1String("--pcpu"); + } + + if (m_profilePixels) { + arguments << QLatin1String("--ppd"); + } + } else { + if (m_doubleBuffered) { + arguments << QLatin1String("--db"); + } else { + arguments << QLatin1String("--sb"); + } + + if (m_benchmarking) { + arguments << QLatin1String("-b"); + } } arguments << m_fileName; + /* + * Support remote execution on a separate target. + */ + + if (m_remoteTarget.length() != 0) { + arguments.prepend(prog); + arguments.prepend(m_remoteTarget); + prog = QLatin1String("ssh"); + } + /* * Start the process. */ @@ -274,6 +341,7 @@ void Retracer::run() QList thumbnails; QVariantMap parsedJson; + trace::Profile* profile = NULL; process.setReadChannel(QProcess::StandardOutput); if (process.waitForReadyRead(-1)) { @@ -290,6 +358,9 @@ void Retracer::run() bool ok = false; QJson::Parser jsonParser; + + // Allow Nan/Infinity + jsonParser.allowSpecialNumbers(true); #if 0 parsedJson = jsonParser.parse(&io, &ok).toMap(); #else @@ -345,6 +416,7 @@ void Retracer::run() unsigned char *scanLine = snapshot.scanLine(y); qint64 readBytes = io.read((char *) scanLine, rowBytes); Q_ASSERT(readBytes == rowBytes); + (void)readBytes; } QImage thumb = thumbnail(snapshot); @@ -352,7 +424,20 @@ void Retracer::run() } Q_ASSERT(process.state() != QProcess::Running); + } else if (isProfiling()) { + profile = new trace::Profile(); + + while (!io.atEnd()) { + char line[256]; + qint64 lineLength; + lineLength = io.readLine(line, 256); + + if (lineLength == -1) + break; + + trace::Profiler::parseLine(line, profile); + } } else { QByteArray output; output = process.readAllStandardOutput(); @@ -389,6 +474,14 @@ void Retracer::run() error.type = regexp.cap(2); error.message = regexp.cap(3); errors.append(error); + } else if (!errors.isEmpty()) { + // Probably a multiligne message + ApiTraceError &previous = errors.last(); + if (line.endsWith("\n")) { + line.chop(1); + } + previous.message.append('\n'); + previous.message.append(line); } } @@ -399,13 +492,16 @@ void Retracer::run() if (m_captureState) { ApiTraceState *state = new ApiTraceState(parsedJson); emit foundState(state); - msg = QLatin1String("State fetched."); } if (m_captureThumbnails && !thumbnails.isEmpty()) { emit foundThumbnails(thumbnails); } + if (isProfiling() && profile) { + emit foundProfile(profile); + } + if (!errors.isEmpty()) { emit retraceErrors(errors); }