]> git.cworth.org Git - apitrace/blob - gui/traceprocess.cpp
Merge branch 'master' into d2d
[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 #ifdef Q_OS_WIN
20     qWarning()<<"Windows tracing isn't supported right now!";
21     m_canTrace = false;
22 #else
23 #ifdef Q_OS_WIN
24     QString format = QLatin1String("%1;");
25 #else
26     QString format = QLatin1String("%1:");
27 #endif
28     QString buildPath = format.arg(APITRACE_BINARY_DIR);
29     QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
30     env.insert("PATH", buildPath + env.value("PATH"));
31     qputenv("PATH", env.value("PATH").toLatin1());
32 #endif
33 }
34
35 TraceProcess::~TraceProcess()
36 {
37 }
38
39 void TraceProcess::setExecutablePath(const QString &str)
40 {
41     m_execPath = str;
42
43     QFileInfo fi(m_execPath);
44     QString baseName = fi.baseName();
45
46     QString format = QString::fromLatin1("%1.trace");
47
48     m_tracePath = format
49                   .arg(baseName);
50
51     int i = 1;
52     while (QFile::exists(m_tracePath)) {
53         format = QString::fromLatin1("%1.%2.trace");
54         m_tracePath = format
55                       .arg(baseName)
56                       .arg(i++);
57     }
58 }
59
60 QString TraceProcess::executablePath() const
61 {
62     return m_execPath;
63 }
64
65 void TraceProcess::setArguments(const QStringList &args)
66 {
67     m_args = args;
68 }
69
70 QStringList TraceProcess::arguments() const
71 {
72     return m_args;
73 }
74
75 void TraceProcess::traceFinished()
76 {
77 #if 0
78     qDebug()<<"trace finished on " << m_tracePath;
79     qDebug()<<"\terr = "<<m_process->readAllStandardError();
80     qDebug()<<"\tout = "<<m_process->readAllStandardOutput();
81 #endif
82     emit tracedFile(m_tracePath);
83 }
84
85 void TraceProcess::traceError(QProcess::ProcessError err)
86 {
87 #if 1
88     qDebug()<<"trace error = "<<m_tracePath;
89     qDebug()<<"\terr = "<<m_process->readAllStandardError();
90     qDebug()<<"\tout = "<<m_process->readAllStandardOutput();
91 #endif
92     emit error(m_process->readAllStandardError());
93 }
94
95
96 void TraceProcess::start()
97 {
98     QStringList arguments;
99
100     arguments << QLatin1String("trace");
101     arguments << QLatin1String("--output");
102     arguments << m_tracePath;
103     arguments << QLatin1String("--");
104     arguments << m_execPath;
105     arguments << m_args;
106
107     m_process->start(QLatin1String("apitrace"), arguments);
108 }
109
110 bool TraceProcess::canTrace() const
111 {
112     return m_canTrace;
113 }
114
115 #include "traceprocess.moc"