1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#include "traceprocess.h"
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
TraceProcess::TraceProcess(QObject *parent)
: QObject(parent),
m_canTrace(true)
{
m_process = new QProcess(this);
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(traceFinished()));
connect(m_process, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(traceError(QProcess::ProcessError)));
}
TraceProcess::~TraceProcess()
{
}
void TraceProcess::setApi(const QString &str)
{
m_api = str;
}
void TraceProcess::setExecutablePath(const QString &str)
{
m_execPath = str;
QFileInfo fi(m_execPath);
QString baseName = fi.baseName();
QString format = QString::fromLatin1("%1.trace");
m_tracePath = format
.arg(baseName);
int i = 1;
while (QFile::exists(m_tracePath)) {
format = QString::fromLatin1("%1.%2.trace");
m_tracePath = format
.arg(baseName)
.arg(i++);
}
}
QString TraceProcess::executablePath() const
{
return m_execPath;
}
void TraceProcess::setArguments(const QStringList &args)
{
m_args = args;
}
QStringList TraceProcess::arguments() const
{
return m_args;
}
void TraceProcess::traceFinished()
{
#if 0
qDebug()<<"trace finished on " << m_tracePath;
qDebug()<<"\terr = "<<m_process->readAllStandardError();
qDebug()<<"\tout = "<<m_process->readAllStandardOutput();
#endif
emit tracedFile(m_tracePath);
}
void TraceProcess::traceError(QProcess::ProcessError err)
{
#if 1
qDebug()<<"trace error = "<<m_tracePath;
qDebug()<<"\terr = "<<m_process->readAllStandardError();
qDebug()<<"\tout = "<<m_process->readAllStandardOutput();
#endif
emit error(m_process->readAllStandardError());
}
void TraceProcess::start()
{
QStringList arguments;
arguments << QLatin1String("trace");
arguments << QLatin1String("--api");
arguments << m_api;
arguments << QLatin1String("--output");
arguments << m_tracePath;
arguments << QLatin1String("--");
arguments << m_execPath;
arguments << m_args;
m_process->start(QLatin1String("apitrace"), arguments);
}
bool TraceProcess::canTrace() const
{
return m_canTrace;
}
#include "traceprocess.moc"
|