Jose Fonseca | a20a795 | 2016-01-19 14:16:24 +0000 | [diff] [blame^] | 1 | #include "leaktracethread.h" |
| 2 | |
| 3 | #include "apitracecall.h" |
| 4 | |
| 5 | #include <QDebug> |
| 6 | #include <QProcess> |
| 7 | |
| 8 | void LeakTraceThread::run() |
| 9 | { |
| 10 | QString msg = QLatin1String("Replay finished!"); |
| 11 | |
| 12 | /* |
| 13 | * Construct command line |
| 14 | */ |
| 15 | |
| 16 | QString prog = "apitrace"; |
| 17 | QStringList arguments; |
| 18 | arguments << "leaks"; |
| 19 | arguments << filename; |
| 20 | |
| 21 | /* |
| 22 | * Start the process. |
| 23 | */ |
| 24 | |
| 25 | { |
| 26 | QDebug debug(QtDebugMsg); |
| 27 | debug << "Running:"; |
| 28 | debug << prog; |
| 29 | foreach (const QString &argument, arguments) { |
| 30 | debug << argument; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | QProcess process; |
| 35 | |
| 36 | process.start(prog, arguments, QIODevice::ReadOnly); |
| 37 | if (!process.waitForStarted(-1)) { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | /* |
| 42 | * Wait for process termination |
| 43 | */ |
| 44 | |
| 45 | process.waitForFinished(-1); |
| 46 | |
| 47 | if (process.exitStatus() != QProcess::NormalExit) { |
| 48 | msg = QLatin1String("Process crashed"); |
| 49 | } else if (process.exitCode() != 0) { |
| 50 | msg = QLatin1String("Process exited with non zero exit code"); |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * Parse errors. |
| 55 | */ |
| 56 | |
| 57 | QList<ApiTraceError> errors; |
| 58 | process.setReadChannel(QProcess::StandardError); |
| 59 | QRegExp regexp("(^\\d+): +(\\b\\w+\\b): ([^\\r\\n]+)[\\r\\n]*$"); |
| 60 | while (!process.atEnd()) { |
| 61 | QString line = process.readLine(); |
| 62 | qDebug() << line; |
| 63 | if (regexp.indexIn(line) != -1) { |
| 64 | qDebug() << "error"; |
| 65 | ApiTraceError error; |
| 66 | error.callIndex = regexp.cap(1).toInt(); |
| 67 | error.type = regexp.cap(2); |
| 68 | error.message = regexp.cap(3); |
| 69 | errors.append(error); |
| 70 | } else { |
| 71 | qDebug() << line; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /* |
| 76 | * Emit signals |
| 77 | */ |
| 78 | |
| 79 | error = !errors.empty(); |
| 80 | emit leakTraceErrors(errors); |
| 81 | } |
| 82 | |