File: leaktracethread.cpp

package info (click to toggle)
apitrace 13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,752 kB
  • sloc: cpp: 183,974; python: 33,969; ansic: 25,566; sh: 169; makefile: 88; sed: 3
file content (84 lines) | stat: -rw-r--r-- 1,867 bytes parent folder | download
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
#include "leaktracethread.h"

#include "apitracecall.h"

#include <QDebug>
#include <QProcess>
#include <QRegularExpression>

void LeakTraceThread::run()
{
    QString msg = QLatin1String("Replay finished!");

    /*
     * Construct command line
     */

    QString prog = "apitrace";
    QStringList arguments;
    arguments << "leaks";
    arguments << filename;

    /*
     * Start the process.
     */

    {
        QDebug debug(QtDebugMsg);
        debug << "Running:";
        debug << prog;
        foreach (const QString &argument, arguments) {
            debug << argument;
        }
    }

    QProcess process;

    process.start(prog, arguments, QIODevice::ReadOnly);
    if (!process.waitForStarted(-1)) {
        return;
    }

    /*
     * Wait for process termination
     */

    process.waitForFinished(-1);

    if (process.exitStatus() != QProcess::NormalExit) {
        msg = QLatin1String("Process crashed");
    } else if (process.exitCode() != 0) {
        msg = QLatin1String("Process exited with non zero exit code");
    }

    /*
     * Parse errors.
     */

    QList<ApiTraceError> errors;
    process.setReadChannel(QProcess::StandardError);
    QRegularExpression regexp("^(\\d+): +(\\b\\w+\\b): ([^\\r\\n]+)[\\r\\n]*$");
    while (!process.atEnd()) {
        QString line = process.readLine();
        qDebug() << line;
        QRegularExpressionMatch match = regexp.match(line);
        if (match.hasMatch()) {
            qDebug() << "error";
            ApiTraceError error;
            error.callIndex = match.captured(1).toInt();
            error.type = match.captured(2);
            error.message = match.captured(3);
            errors.append(error);
        } else {
            qDebug() << line;
        }
    }

    /*
     * Emit signals
     */

    error = !errors.empty();
    emit leakTraceErrors(errors);
}