-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.cpp
executable file
·345 lines (289 loc) · 14 KB
/
MainWindow.cpp
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QDir>
#include <QTextStream>
#include "DataReport.h"
#include "TrafficAnalysis.h"
#include "PerformanceAnalysis.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->listData = NULL;
QStringList header;
header << tr("Fclk\n(MHz)")
<< tr("Analyzed\nPackets")
<< tr("Offered\nTraffic\n(norm)")
<< tr("Accepted\nTraffic\n(norm)")
<< tr("Ideal\nAvg\nLatency\n(cycles)")
<< tr("Avg\nLatency\n(cycles)")
<< tr("Min\nLatency\n(cycles)")
<< tr("Max\nLatency\n(cycles)")
<< tr("Std Dev\nLatency")
<< tr("RT0 Met\nDeadlines\n(%)")
<< tr("RT1 Met\nDeadlines\n(%)")
<< tr("nRT0 Met\nDeadlines\n(%)")
<< tr("nRT1 Met\nDeadlines\n(%)")
<< tr("Offered\nTraffic\n(Mbps/n)")
<< tr("Accepted\nTraffic\n(Mbps/n)")
<< tr("Ideal\nAvg\nLatency\n(ns)")
<< tr("Avg\nLatency\n(ns)")
<< tr("Min\nLatency\n(ns)")
<< tr("Max\nLatency\n(ns)");;
this->ui->treeView->setHeaderLabels(header);
for(int i = 0; i < header.size(); i++) {
this->ui->treeView->headerItem()->setTextAlignment(i,Qt::AlignCenter);
this->ui->treeView->resizeColumnToContents(i);
}
connect(ui->actionExit,SIGNAL(triggered(bool)),this,SLOT(close()));
connect(ui->actionOpen,SIGNAL(triggered(bool)),this,SLOT(loadDirectory()));
connect(ui->actionGenerate_Report,SIGNAL(triggered(bool)),this,SLOT(generateCSVReport()));
}
void MainWindow::loadDirectory() {
workDir = QFileDialog::getExistingDirectory(this,tr("Select the results directory"));
if( workDir.isNull() || workDir.isEmpty() ) {
return;
}
loadData();
}
void MainWindow::loadData() {
QString fClkString = workDir.mid( workDir.lastIndexOf("/")+1 );
fClkString.remove("MHz");
float fClk = fClkString.toFloat();
float tClk = (1.0 / fClk) * 1000.0;
unsigned int xSize = 4;
unsigned int ySize = 4;
unsigned int dataWidth = 32;
float lower = 0; // From 0%
float upper = 1; // To 100%
unsigned long channelBW = dataWidth * fClk;
unsigned int fifoOut = 0;
unsigned int flowControl = 1; // 0: Handshake | 1: Credit-based
QString resultDir = workDir + "/Results";
QDir dir(resultDir);
if( !dir.exists() ) {
dir.mkpath(".");
} else {
dir.removeRecursively();
dir.mkpath(".");
}
QByteArray dirAnalysis = workDir.toUtf8();
QByteArray dirResults = resultDir.toUtf8();
const char* analysis = dirAnalysis.constData();
const char* results = dirResults.constData();
TrafficAnalysis* analyzer = new PerformanceAnalysis(xSize,ySize,dataWidth,lower,
upper,fClk,tClk,channelBW,fifoOut,
flowControl,analysis,results);
TrafficAnalysis::StatusAnalysis resultAnalysis = analyzer->makeAnalysis();
QString dirAnalyzed = fClkString + "MHz";
switch (resultAnalysis) {
case TrafficAnalysis::NoInputFile:
QMessageBox::critical(this,tr("Problem"),tr("There is no input file for analysis (maybe "
"simulation was not run or directory is invalid) in %1").arg(dirAnalyzed));
return;
case TrafficAnalysis::NoPacketsDelivered:
QMessageBox::critical(this,tr("Problem"),tr("Simulation time too short. None packet was "
"delivered in %1").arg(dirAnalyzed));
return;
case TrafficAnalysis::NoOutputFile:
QMessageBox::critical(this,tr("Problem"),tr("Impossible create result file in %1")
.arg(dirAnalyzed));
return;
default: break;
}
delete analyzer;
// Read the summary of simulation only
if( this->readReport(resultDir+"/summary") ) {
QMessageBox::information(this,tr("Information"),tr("Successfully analyzed - %1")
.arg(dirAnalyzed));
this->showData();
} else {
QMessageBox::critical(this,tr("Error"),tr("It isn't possible open file from simulation's result"));
}
}
bool MainWindow::readReport(QString file) {
QFile* arquivo = new QFile(QString(file));
if( !arquivo->open(QIODevice::ReadOnly | QIODevice::Text) ) {
delete arquivo;
return false;
} else {
QTextStream str(&*arquivo);
QString linha;
this->clearData();
QList<DataReport*>* listaDados = new QList<DataReport*>();
do {
linha = str.readLine();
if( linha.isNull() ) {
break;
}
QStringList params = linha.split("\t");
if(params.size() == 19) {
DataReport* data = new DataReport;
data->fClk = params.at(0).toFloat();
data->accNbOfPck = params.at(1).toULong();
data->avgRequiredBwNorm = params.at(2).toFloat();
data->acceptedTrafficFlits = params.at(3).toFloat();
data->idealAvgLatency = params.at(4).toFloat();
data->avgLatencyCycles = params.at(5).toFloat();
data->stdevLatency = params.at(6).toFloat();
data->minLatency = params.at(7).toFloat();
data->maxLatency = params.at(8).toFloat();
data->avgRequiredBwBps = params.at(9).toFloat();
data->acceptedTrafficBps = params.at(10).toFloat();
data->idealAvgLatencyNs = params.at(11).toFloat();
data->avgLatencyNs = params.at(12).toFloat();
data->minLatencyNs = params.at(13).toFloat();
data->maxLatencyNs = params.at(14).toFloat();
data->metDeadlinesPer0 = params.at(15).toFloat();
data->metDeadlinesPer1 = params.at(16).toFloat();
data->metDeadlinesPer2 = params.at(17).toFloat();
data->metDeadlinesPer3 = params.at(18).toFloat();
listaDados->append(data);
}
} while(!linha.isNull());
arquivo->close();
delete arquivo;
this->listData = listaDados;
return true;
}
}
void MainWindow::generateCSVReport() {
QString filename = QFileDialog::getSaveFileName(this,tr("Save CSV Report"),QString(),tr("CSV Report(*.csv)"));
if( filename.isNull() || filename.isEmpty() ) {
return;
}
if( listData == NULL ) {
QMessageBox::information(this,tr("Information"),tr("There is no data loaded!"));
return;
}
QFile file(filename);
if( !file.open(QIODevice::WriteOnly | QIODevice::Text) ) {
QMessageBox::critical(this,tr("Error"),tr("It is not possible generate CSV."
"<br />Please verify write permissions in selected folder."));
return;
} else {
QString csvText;
QTextStream ts(&csvText);
QLocale local = QLocale::system();
// QChar decPoint = local.decimalPoint();
QString decPoint = local.decimalPoint();
char separator = ',';
if( decPoint == ',' ) {
separator = ';';
}
ts << tr("Analyzer CSV Report") << separator
<< separator << separator << separator << separator << separator << separator
<< separator << separator << separator << separator << separator << separator
<< separator << separator << separator << separator << separator << separator
<< separator << separator << "\n";
// Varrer e escrever CSV
if( listData != NULL ) {
// Legenda
ts << tr("Clock Frequency(MHz)") << separator
<< tr("Analyzed Packets") << separator
<< tr("Offered Traffic(norm)") << separator
<< tr("Accepted Traffic(norm)") << separator
<< tr("Ideal Average Latency(cycles)") << separator
<< tr("Average Latency(cycles)") << separator
<< tr("Standard Deviation Latency") << separator
<< tr("Minimum Latency(cycles)") << separator
<< tr("Maximum Latency(cycles)") << separator
<< tr("Offered Traffic(Mbps/n)") << separator
<< tr("Accepted Traffic(Mbps/n)") << separator
<< tr("Ideal Average Latency(ns)") << separator
<< tr("Average Latency(ns)") << separator
<< tr("Minimun Latency(ns)") << separator
<< tr("Maximum Latency(ns)") << separator
<< tr("RT0 Met Deadlines(%)") << separator
<< tr("RT1 Met Deadlines(%)") << separator
<< tr("nRT0 Met Deadlines(%)") << separator
<< tr("nRT1 Met Deadlines(%)") << "\n";
for( int z = 0; z < listData->size(); z++ ) {
// Linha de dado
DataReport* d = listData->at(z);
ts << QString::number(d->fClk,'f',0) << separator
<< QString::number(d->accNbOfPck,'f',0) << separator
<< QString::number(d->avgRequiredBwNorm,'f',4) << separator
<< QString::number(d->acceptedTrafficFlits,'f',4) << separator
<< QString::number(d->idealAvgLatency,'f',0) << separator
<< QString::number(d->avgLatencyCycles,'f',1) << separator
<< QString::number(d->stdevLatency,'f',1) << separator
<< QString::number(d->minLatency,'f',0) << separator
<< QString::number(d->maxLatency,'f',0) << separator
<< QString::number(d->avgRequiredBwBps,'f',0) << separator
<< QString::number(d->acceptedTrafficBps,'f',0) << separator
<< QString::number(d->idealAvgLatencyNs,'f',1) << separator
<< QString::number(d->avgLatencyNs,'f',1) << separator
<< QString::number(d->minLatencyNs,'f',1) << separator
<< QString::number(d->maxLatencyNs,'f',1) << separator
<< (d->metDeadlinesPer0 == -1 ? QString():QString::number(d->metDeadlinesPer0)) << separator
<< (d->metDeadlinesPer1 == -1 ? QString():QString::number(d->metDeadlinesPer1)) << separator
<< (d->metDeadlinesPer2 == -1 ? QString():QString::number(d->metDeadlinesPer2)) << separator
<< (d->metDeadlinesPer3 == -1 ? QString():QString::number(d->metDeadlinesPer3)) << "\n";
}
}
if( decPoint == ',' ) {
csvText.replace(".",","); // Change decimal separator to ','
}
QTextStream csvTs(&file);
csvTs << csvText;
file.close();
}
}
void MainWindow::showData() {
QTreeWidgetItemIterator it(ui->treeView);
for( ; (*it) ; ) {
QTreeWidgetItem* item = (*it);
delete item;
it++;
}
ui->treeView->clear();
int size = listData->size();
for( int i = 0; i < size; i++ ) {
DataReport* dado = listData->at(i);
QTreeWidgetItem* item = new QTreeWidgetItem(this->ui->treeView);
item->setData(0,Qt::DisplayRole, QString::number(dado->fClk,'f',0) );
item->setData(1,Qt::DisplayRole, QString::number(dado->accNbOfPck,'f',0) );
item->setData(2,Qt::DisplayRole, QString::number(dado->avgRequiredBwNorm,'f',4) );
item->setData(3,Qt::DisplayRole, QString::number(dado->acceptedTrafficFlits,'f',4) );
item->setData(4,Qt::DisplayRole, QString::number(dado->idealAvgLatency,'f',0) );
item->setData(5,Qt::DisplayRole, QString::number(dado->avgLatencyCycles,'f',1) );
item->setData(6,Qt::DisplayRole, QString::number(dado->minLatency,'f',0) );
item->setData(7,Qt::DisplayRole, QString::number(dado->maxLatency,'f',0) );
item->setData(8,Qt::DisplayRole, QString::number(dado->stdevLatency,'f',1) );
item->setData(9,Qt::DisplayRole, (dado->metDeadlinesPer0 == -1 ? QString():QString::number(dado->metDeadlinesPer0,'g',4)) );
item->setData(10,Qt::DisplayRole, (dado->metDeadlinesPer1 == -1 ? QString():QString::number(dado->metDeadlinesPer1,'g',4)) );
item->setData(11,Qt::DisplayRole, (dado->metDeadlinesPer2 == -1 ? QString():QString::number(dado->metDeadlinesPer2,'g',4)) );
item->setData(12,Qt::DisplayRole, (dado->metDeadlinesPer3 == -1 ? QString():QString::number(dado->metDeadlinesPer3,'g',4)) );
item->setData(13,Qt::DisplayRole, QString::number(dado->avgRequiredBwBps,'f',1) );
item->setData(14,Qt::DisplayRole, QString::number(dado->acceptedTrafficBps,'f',1) );
item->setData(15,Qt::DisplayRole, QString::number(dado->idealAvgLatencyNs,'f',1) );
item->setData(16,Qt::DisplayRole, QString::number(dado->avgLatencyNs,'f',1) );
item->setData(17,Qt::DisplayRole, QString::number(dado->minLatencyNs,'f',1) );
item->setData(18,Qt::DisplayRole, QString::number(dado->maxLatencyNs,'f',1) );
for( int x = 0; x < ui->treeView->columnCount(); x++ ) {
item->setTextAlignment(x,Qt::AlignCenter);
}
}
for(int i = 0; i < ui->treeView->columnCount(); i++) {
this->ui->treeView->resizeColumnToContents(i);
}
}
void MainWindow::clearData() {
if(listData != NULL) {
for( int z = 0; z < listData->size(); z++ ) {
DataReport* d = listData->at(z);
delete d;
}
listData->clear();
delete listData;
listData = NULL;
}
}
MainWindow::~MainWindow()
{
delete ui;
}