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