3 #include "apitracecall.h"
8 #include <qjson/parser.h>
10 Retracer::Retracer(QObject *parent)
13 m_doubleBuffered(true),
14 m_captureState(false),
18 QString format = QLatin1String("%1;");
20 QString format = QLatin1String("%1:");
22 QString buildPath = format.arg(BUILD_DIR);
23 m_processEnvironment = QProcessEnvironment::systemEnvironment();
24 m_processEnvironment.insert("PATH", buildPath +
25 m_processEnvironment.value("PATH"));
28 m_processEnvironment.value("PATH").toLatin1());
31 QString Retracer::fileName() const
36 void Retracer::setFileName(const QString &name)
41 bool Retracer::isBenchmarking() const
43 return m_benchmarking;
46 void Retracer::setBenchmarking(bool bench)
48 m_benchmarking = bench;
51 bool Retracer::isDoubleBuffered() const
53 return m_doubleBuffered;
56 void Retracer::setDoubleBuffered(bool db)
58 m_doubleBuffered = db;
61 void Retracer::setCaptureAtCallNumber(qlonglong num)
66 qlonglong Retracer::captureAtCallNumber() const
71 bool Retracer::captureState() const
73 return m_captureState;
76 void Retracer::setCaptureState(bool enable)
78 m_captureState = enable;
84 RetraceProcess *retrace = new RetraceProcess();
85 retrace->process()->setProcessEnvironment(m_processEnvironment);
87 retrace->setFileName(m_fileName);
88 retrace->setBenchmarking(m_benchmarking);
89 retrace->setDoubleBuffered(m_doubleBuffered);
90 retrace->setCaptureState(m_captureState);
91 retrace->setCaptureAtCallNumber(m_captureCall);
93 connect(retrace, SIGNAL(finished(const QString&)),
94 this, SLOT(cleanup()));
95 connect(retrace, SIGNAL(error(const QString&)),
96 this, SLOT(cleanup()));
97 connect(retrace, SIGNAL(finished(const QString&)),
98 this, SIGNAL(finished(const QString&)));
99 connect(retrace, SIGNAL(error(const QString&)),
100 this, SIGNAL(error(const QString&)));
101 connect(retrace, SIGNAL(foundState(const ApiTraceState&)),
102 this, SIGNAL(foundState(const ApiTraceState&)));
108 /* means we need to kill the process */
109 if (retrace->process()->state() != QProcess::NotRunning) {
110 retrace->terminate();
117 void RetraceProcess::start()
119 QStringList arguments;
121 if (m_doubleBuffered) {
122 arguments << QLatin1String("-db");
125 if (m_captureState) {
126 arguments << QLatin1String("-D");
127 arguments << QString::number(m_captureCall);
129 if (m_benchmarking) {
130 arguments << QLatin1String("-b");
134 arguments << m_fileName;
136 m_process->start(QLatin1String("glretrace"), arguments);
140 void RetraceProcess::replayFinished()
142 QByteArray output = m_process->readAllStandardOutput();
146 qDebug()<<"Process finished = ";
147 qDebug()<<"\terr = "<<m_process->readAllStandardError();
148 qDebug()<<"\tout = "<<output;
150 if (m_captureState) {
152 QVariantMap parsedJson = m_jsonParser->parse(output, &ok).toMap();
153 ApiTraceState state(parsedJson);
154 emit foundState(state);
155 msg = tr("State fetched.");
157 msg = QString::fromUtf8(output);
163 void RetraceProcess::replayError(QProcess::ProcessError err)
165 qDebug()<<"Process error = "<<err;
166 qDebug()<<"\terr = "<<m_process->readAllStandardError();
167 qDebug()<<"\tout = "<<m_process->readAllStandardOutput();
170 tr("Couldn't execute the replay file '%1'").arg(m_fileName));
174 RetraceProcess::RetraceProcess(QObject *parent)
177 m_process = new QProcess(this);
178 m_jsonParser = new QJson::Parser();
180 connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
181 this, SLOT(replayFinished()));
182 connect(m_process, SIGNAL(error(QProcess::ProcessError)),
183 this, SLOT(replayError(QProcess::ProcessError)));
186 QProcess * RetraceProcess::process() const
191 QString RetraceProcess::fileName() const
196 void RetraceProcess::setFileName(const QString &name)
201 bool RetraceProcess::isBenchmarking() const
203 return m_benchmarking;
206 void RetraceProcess::setBenchmarking(bool bench)
208 m_benchmarking = bench;
211 bool RetraceProcess::isDoubleBuffered() const
213 return m_doubleBuffered;
216 void RetraceProcess::setDoubleBuffered(bool db)
218 m_doubleBuffered = db;
221 void RetraceProcess::setCaptureAtCallNumber(qlonglong num)
226 qlonglong RetraceProcess::captureAtCallNumber() const
228 return m_captureCall;
231 bool RetraceProcess::captureState() const
233 return m_captureState;
236 void RetraceProcess::setCaptureState(bool enable)
238 m_captureState = enable;
241 void RetraceProcess::terminate()
244 m_process->terminate();
245 emit finished(tr("Process terminated."));
249 void Retracer::cleanup()
254 RetraceProcess::~RetraceProcess()
259 #include "retracer.moc"