Finished Latency Analysis Tool in TA

This commit is contained in:
Matthias Jung
2020-11-02 19:53:53 +01:00
parent c744c43ab2
commit 11bfed8b6a
3 changed files with 159 additions and 102 deletions

View File

@@ -44,6 +44,8 @@
#include <QStandardItemModel>
#include <QString>
#include <QItemDelegate>
#include "qwt_plot_histogram.h"
#include <math.h>
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<int>(progress);
opt.progress = static_cast<int>(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<QStandardItem *> 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<QStandardItem *> 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<QwtIntervalSample> *intervals = new QVector<QwtIntervalSample>;
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();
}

View File

@@ -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

View File

@@ -56,7 +56,7 @@
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="minimumSize">
@@ -112,6 +112,61 @@
</attribute>
</widget>
</item>
<item>
<widget class="CommentTreeWidget" name="commentTree">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>2</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>200</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="fileDescriptionEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>2</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@@ -123,6 +178,30 @@
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QPushButton" name="startLatencyAnalysis">
<property name="text">
<string>Start Analysis</string>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="latencyAnalysisProgressBar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QwtPlot" name="latencyPlot">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>200</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="latencyTreeView">
<property name="editTriggers">
@@ -136,61 +215,6 @@
</widget>
</widget>
</item>
<item>
<widget class="CommentTreeWidget" name="commentTree">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>2</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>200</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="fileDescriptionEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>2</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@@ -198,6 +222,11 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QwtPlot</class>
<extends>QFrame</extends>
<header>qwt_plot.h</header>
</customwidget>
<customwidget>
<class>TracePlot</class>
<extends>QListView</extends>