Zack Rusin | 3acde36 | 2011-04-06 01:11:55 -0400 | [diff] [blame] | 1 | #include "retracer.h" |
| 2 | |
| 3 | #include <QDebug> |
| 4 | |
| 5 | Retracer::Retracer(QObject *parent) |
| 6 | : QObject(parent), |
| 7 | m_benchmarking(true), |
| 8 | m_doubleBuffered(true), |
| 9 | m_captureState(false), |
| 10 | m_captureCall(0), |
| 11 | m_process(0) |
| 12 | { |
| 13 | } |
| 14 | |
| 15 | QString Retracer::fileName() const |
| 16 | { |
| 17 | return m_fileName; |
| 18 | } |
| 19 | |
| 20 | void Retracer::setFileName(const QString &name) |
| 21 | { |
| 22 | m_fileName = name; |
| 23 | } |
| 24 | |
| 25 | bool Retracer::isBenchmarking() const |
| 26 | { |
| 27 | return m_benchmarking; |
| 28 | } |
| 29 | |
| 30 | void Retracer::setBenchmarking(bool bench) |
| 31 | { |
| 32 | m_benchmarking = bench; |
| 33 | } |
| 34 | |
| 35 | bool Retracer::isDoubleBuffered() const |
| 36 | { |
| 37 | return m_doubleBuffered; |
| 38 | } |
| 39 | |
| 40 | void Retracer::setDoubleBuffered(bool db) |
| 41 | { |
| 42 | m_doubleBuffered = db; |
| 43 | } |
| 44 | |
| 45 | void Retracer::start() |
| 46 | { |
| 47 | if (!m_process) { |
| 48 | #ifdef Q_OS_WIN |
| 49 | QString format = QLatin1String("%1;"); |
| 50 | #else |
| 51 | QString format = QLatin1String("%1:"); |
| 52 | #endif |
| 53 | QString buildPath = format.arg(BUILD_DIR); |
| 54 | QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); |
| 55 | env.insert("PATH", buildPath + env.value("PATH")); |
| 56 | |
| 57 | qputenv("PATH", env.value("PATH").toLatin1()); |
| 58 | |
| 59 | m_process = new QProcess(this); |
| 60 | m_process->setProcessEnvironment(env); |
| 61 | |
| 62 | connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), |
| 63 | this, SLOT(replayFinished())); |
| 64 | connect(m_process, SIGNAL(error(QProcess::ProcessError)), |
| 65 | this, SLOT(replayError(QProcess::ProcessError))); |
| 66 | } |
| 67 | |
| 68 | QStringList arguments; |
| 69 | |
| 70 | if (m_captureState) { |
| 71 | arguments << QLatin1String("-D"); |
| 72 | arguments << QString::number(m_captureCall); |
| 73 | } else { |
| 74 | if (m_benchmarking) { |
| 75 | arguments << QLatin1String("-b"); |
| 76 | } |
| 77 | if (m_doubleBuffered) { |
| 78 | arguments << QLatin1String("-db"); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | arguments << m_fileName; |
| 83 | |
| 84 | m_process->start(QLatin1String("glretrace"), arguments); |
| 85 | } |
| 86 | |
| 87 | void Retracer::terminate() |
| 88 | { |
| 89 | if (m_process) { |
| 90 | m_process->terminate(); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | void Retracer::setCaptureAtCallNumber(qlonglong num) |
| 95 | { |
| 96 | m_captureCall = num; |
| 97 | } |
| 98 | |
| 99 | qlonglong Retracer::captureAtCallNumber() const |
| 100 | { |
| 101 | return m_captureCall; |
| 102 | } |
| 103 | |
| 104 | bool Retracer::captureState() const |
| 105 | { |
| 106 | return m_captureState; |
| 107 | } |
| 108 | |
| 109 | void Retracer::setCaptureState(bool enable) |
| 110 | { |
| 111 | m_captureState = enable; |
| 112 | } |
| 113 | |
| 114 | void Retracer::replayFinished() |
| 115 | { |
| 116 | QByteArray output = m_process->readAllStandardOutput(); |
| 117 | |
| 118 | #if 0 |
| 119 | qDebug()<<"Process finished = "; |
| 120 | qDebug()<<"\terr = "<<m_process->readAllStandardError(); |
| 121 | qDebug()<<"\tout = "<<output; |
| 122 | #endif |
| 123 | emit finished(output); |
| 124 | } |
| 125 | |
| 126 | void Retracer::replayError(QProcess::ProcessError err) |
| 127 | { |
| 128 | qDebug()<<"Process error = "<<err; |
| 129 | qDebug()<<"\terr = "<<m_process->readAllStandardError(); |
| 130 | qDebug()<<"\tout = "<<m_process->readAllStandardOutput(); |
| 131 | |
| 132 | emit error( |
| 133 | tr("Couldn't execute the replay file '%1'").arg(m_fileName)); |
| 134 | } |
| 135 | |
| 136 | #include "retracer.moc" |