-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
155 lines (133 loc) · 5.16 KB
/
Copy pathmain.cpp
File metadata and controls
155 lines (133 loc) · 5.16 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <QObject>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "dataobject.h"
#include <QFile>
#include <QIODevice>
#include <QTextStream>
#include <QDebug>
#include <QHash>
// DONE make sliders dynamic width
// DONE sort out the starting view. get min/max values into QML somehow and zoom to relevant timespan
// * make a better interface for changing displayed timespan
// * group rows by parent pid somehow
// * wrap it up in a script that runs strace
// * add parsing for clone() and whatever else is needed to display every process that gets run
// * make the text show up in a nicer way. consider mouseover balloon text boxes
// * add to github :)
// * rename project :D
// * show wait() and maybe other syscalls within the bar for each process
// * do gridlines
// * display times in the gui somehow, perhaps on an user action (mouseover or clicking a process box)
// Try some layouts in pure xml
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
//TimeCollection tc;
//tc.append(new DataObject(1.0, 2.5));
//tc.times()->append(new DataObject(1.0, 2.5));
QList<QObject*> dataList;
QHash<QString, QString> unfinished;
QHash<QString, double> startTimes;
QHash<QString, QString> startNames;
QString digits("(\\d+)");
QString whitespace("\\s+");
QString decimal("(\\d+\\.\\d+)");
QString letters("(.*$)");
QRegExp rx(digits + whitespace + decimal + whitespace + letters);
QFile inputFile("/home/osboxes/log2.strace");
int execs = 0;
int exits = 0;
if (inputFile.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile);
int i = 0;
while (!in.atEnd())
{
QString line = in.readLine();
//"^(\d\d):(\d\d):(\d\d)(?:\.(\d\d\d\d\d\d))?""
int j = rx.indexIn(line);
QString pid(rx.cap(1));
QString time(rx.cap(2));
QString rest(rx.cap(3));
/*
if (i < 5) {
qInfo() << line;
qInfo() << " " << j << " " << pid;
qInfo() << " " << j << " " << time;
qInfo() << " " << j << " " << rest;
qInfo() << " " << j << " " << rx.cap(0) ;
}
i++;
*/
if (QRegExp("^(.*) <unfinished \\.\\.\\.>$").indexIn(rest) > -1) {
// qInfo() << pid << " unfinished " << rest;
unfinished.insert(pid, rest);
unfinished.insert("apa", "kalle");
continue;
}
if (QRegExp("\\.\\.\\. \\S+ resumed> ").indexIn(rest) > -1) {
if (unfinished.contains(pid)) {
QString line( unfinished.value(pid) + rest );
// qInfo() << pid << " resumed " << line;
rest = line;
unfinished.remove(pid);
} else {
qInfo() << "resumed unknown call " << unfinished.value(pid);
continue;
}
}
if (QRegExp("^\\+\\+\\+ killed by SIG(\\S+) \\+\\+\\+$").indexIn(rest) > -1) {
// for later: handle_killed(pid, time);
continue;
}
if (QRegExp("^\\+\\+\\+ exited with (\\d+) \\+\\+\\+$").indexIn(rest) > -1) {
exits++;
// qInfo() << exits << " exit " << pid;
if (startTimes.contains(pid)) {
dataList.append(new DataObject( startTimes.value(pid), time.toDouble(), startNames.value(pid) ) );
}
//qInfo() << pid << "exited with " << rest;
// No need to handle(?)
continue;
}
QRegExp execRx("execve.*= 0 <(.*)>$");
if (execRx.indexIn(rest) > -1) {
execs++;
// qInfo() << execs << " " << pid << " " << time << " " << rest << " " << execRx.cap(1);
startTimes.insert(pid, time.toDouble());
startNames.insert(pid, rest);
}
}
inputFile.close();
} else {
// printf("%s\n", inputFile.errorString().toLocal8Bit());
}
QQmlApplicationEngine engine;
QQmlContext * ctx = engine.rootContext();
QVariant kalle = QVariant::fromValue(QList<QObject*>(dataList));
qreal min = dataList.at(0)->property("s").toDouble();
qreal max = dataList.at(0)->property("e").toDouble();
foreach(QObject *o, dataList) {
if (o->property("s").toDouble() < min) {
min = o->property("s").toDouble();
}
if (o->property("s").toDouble() > max) {
max = o->property("e").toDouble();
}
// qInfo() << "min" << min;
// qInfo() << "max" << max;
}
/*
min -= (max - min) * 0.02;
max += (max - min) * 0.02;
*/
DataObject minMax(min,max,"apa");
//std::sort(dataList.begin(), dataList.end());
ctx->setContextProperty("dataList", QVariant::fromValue(QList<QObject*>(dataList)));
ctx->setContextProperty("minMax", &minMax);
//setProperty("min", QVariant::fromValue(QString("kalle")));
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}