From 11bfed8b6a5dea7ce5fb7896da8ef8713e40cd58 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Mon, 2 Nov 2020 19:53:53 +0100 Subject: [PATCH] Finished Latency Analysis Tool in TA --- DRAMSys/traceAnalyzer/tracefiletab.cpp | 119 +++++++++++++-------- DRAMSys/traceAnalyzer/tracefiletab.h | 1 + DRAMSys/traceAnalyzer/tracefiletab.ui | 141 +++++++++++++++---------- 3 files changed, 159 insertions(+), 102 deletions(-) diff --git a/DRAMSys/traceAnalyzer/tracefiletab.cpp b/DRAMSys/traceAnalyzer/tracefiletab.cpp index 3acbf409..b67004b7 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.cpp +++ b/DRAMSys/traceAnalyzer/tracefiletab.cpp @@ -44,6 +44,8 @@ #include #include #include +#include "qwt_plot_histogram.h" +#include TraceFileTab::TraceFileTab(QWidget *parent, const QString &path) : QWidget(parent), ui(new Ui::TraceFileTab), savingChangesToDB(false) @@ -127,7 +129,7 @@ public: opt.rect = option.rect; opt.minimum = 0; opt.maximum = 100; - opt.progress = static_cast(progress); + opt.progress = static_cast(floor(progress)); opt.text = QString::number(progress, 'f', 2)+" %"; opt.textVisible = true; QApplication::style()->drawControl(QStyle::CE_ProgressBar, &opt, painter, nullptr); @@ -139,51 +141,6 @@ public: void TraceFileTab::on_tabWidget_currentChanged(int index) { - if(index == 1) // Changed to latency tab: - { - // Create Database Setup and Query: - QString sql = "SELECT ((p2.PhaseEnd - p1.PhaseBegin)/1000) as latency, t.id " - "FROM Transactions t, Phases p1, Phases p2 " - "WHERE t.id = p1.Transact " - "AND t.id = p2.Transact " - "AND p1.PhaseName = \"REQ\" " - "AND p2.PhaseName = \"RESP\" ORDER BY latency;"; - - QSqlDatabase db = navigator->TraceFile().getDatabase(); - QSqlQuery query(db); - query.exec(sql); - - // Creatoe model and fill it from Database: - QStandardItemModel* model = new QStandardItemModel(); - - int currentLatency = 0; - QStandardItem* currentLatencyItem = nullptr; - int counter = 0; - while (query.next()) { - if(query.value(0) != currentLatency) { - currentLatencyItem = new QStandardItem(QString::number(query.value(0).toInt())+" ns"); - currentLatency = query.value(0).toInt(); - QList row; - row.append(currentLatencyItem); - row.append(new QStandardItem()); - model->appendRow(row); - } - QStandardItem * id = new QStandardItem(query.value(1).toString()); - currentLatencyItem->appendRow(id); - counter++; - } - QStringList header = {"Latency","Occurences"}; - model->setHorizontalHeaderLabels(header); - - // Generate Histrogram: - for(int i = 0; i < model->rowCount(); i++) { - int numberOfChilds = model->item(i)->rowCount(); - double percentage = 100*((double(numberOfChilds))/(double(counter))); - model->item(i,1)->setText(QString::number(percentage)); - } - ui->latencyTreeView->setItemDelegate(new ItemDelegate(ui->latencyTreeView)); - ui->latencyTreeView->setModel(model); - } } void TraceFileTab::on_latencyTreeView_doubleClicked(const QModelIndex &index) @@ -196,3 +153,73 @@ void TraceFileTab::on_latencyTreeView_doubleClicked(const QModelIndex &index) } } } + +void TraceFileTab::on_startLatencyAnalysis_clicked() +{ + // Setup Database: + QSqlDatabase db = navigator->TraceFile().getDatabase(); + QSqlQuery query(db); + + // Check the count of transactions: + QString sql = "SELECT COUNT(*) FROM Transactions;"; + query.exec(sql); + query.next(); + int maxTransactions = query.value(0).toInt(); + + // Create Database Setup and Query: + sql = "SELECT ((p2.PhaseEnd - p1.PhaseBegin)/1000) as latency, t.id " + "FROM Transactions t, Phases p1, Phases p2 " + "WHERE t.id = p1.Transact " + "AND t.id = p2.Transact " + "AND p1.PhaseName = \"REQ\" " + "AND p2.PhaseName = \"RESP\" ORDER BY latency;"; + + query.exec(sql); + + // Creatoe model and fill it from Database: + QStandardItemModel* model = new QStandardItemModel(); + + int currentLatency = 0; + QStandardItem* currentLatencyItem = nullptr; + int counter = 0; + while (query.next()) { + if(query.value(0) != currentLatency) { + currentLatencyItem = new QStandardItem(QString::number(query.value(0).toInt())+" ns"); + currentLatency = query.value(0).toInt(); + QList row; + row.append(currentLatencyItem); + row.append(new QStandardItem()); + model->appendRow(row); + } + QStandardItem * id = new QStandardItem(query.value(1).toString()); + currentLatencyItem->appendRow(id); + counter++; + + int percentage = int(ceil((double(counter))/(double(maxTransactions))*100.0)); + ui->latencyAnalysisProgressBar->setValue(percentage); + } + QStringList header = {"Latency","Occurences"}; + model->setHorizontalHeaderLabels(header); + + // Generate Histrogram and Tree: + QwtPlotHistogram *hist = new QwtPlotHistogram; + QVector *intervals = new QVector; + for(int i = 0; i < model->rowCount(); i++) { + double latency = model->item(i,0)->text().replace(" ns","").toDouble(); + int numberOfChilds = model->item(i)->rowCount(); + double percentage = 100*((double(numberOfChilds))/(double(counter))); + model->item(i,1)->setText(QString::number(percentage)); + intervals->append(QwtIntervalSample(percentage, latency, latency+1)); + } + ui->latencyTreeView->setItemDelegate(new ItemDelegate(ui->latencyTreeView)); + ui->latencyTreeView->setModel(model); + hist->setSamples(*intervals); + hist->attach(ui->latencyPlot); + hist->setPen(QPen(QColor(255,0,0,100))); + hist->setBrush(QBrush(QColor(255,0,0,255))); + ui->latencyPlot->setAxisTitle(0,"Occurences [%]"); + QwtText axisTitle( "Latency [ns]" ); + axisTitle.setFont( ui->latencyPlot->axisTitle( QwtPlot::xBottom ).font() ); + ui->latencyPlot->setAxisTitle( QwtPlot::xBottom, axisTitle ); + ui->latencyPlot->replot(); +} diff --git a/DRAMSys/traceAnalyzer/tracefiletab.h b/DRAMSys/traceAnalyzer/tracefiletab.h index a802e5b8..6ec1cec5 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.h +++ b/DRAMSys/traceAnalyzer/tracefiletab.h @@ -82,6 +82,7 @@ Q_SIGNALS: private Q_SLOTS: void on_tabWidget_currentChanged(int index); void on_latencyTreeView_doubleClicked(const QModelIndex &index); + void on_startLatencyAnalysis_clicked(); }; #endif // TRACEFILETAB_H diff --git a/DRAMSys/traceAnalyzer/tracefiletab.ui b/DRAMSys/traceAnalyzer/tracefiletab.ui index 77e62437..726f36c8 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.ui +++ b/DRAMSys/traceAnalyzer/tracefiletab.ui @@ -56,7 +56,7 @@ - + @@ -112,6 +112,61 @@ + + + + + 2 + 1 + + + + + 300 + 200 + + + + + 16777215 + 16777215 + + + + + 1 + + + + + + + + true + + + + 2 + 1 + + + + + 300 + 0 + + + + + 16777215 + 16777215 + + + + true + + + @@ -123,6 +178,30 @@ + + + + Start Analysis + + + + + + + 0 + + + + + + + + 16777215 + 200 + + + + @@ -136,61 +215,6 @@ - - - - - 2 - 1 - - - - - 300 - 200 - - - - - 16777215 - 16777215 - - - - - 1 - - - - - - - - true - - - - 2 - 1 - - - - - 300 - 0 - - - - - 16777215 - 16777215 - - - - true - - - @@ -198,6 +222,11 @@ + + QwtPlot + QFrame +
qwt_plot.h
+
TracePlot QListView