It's now possible to select comments directly in the traceplot instead of selecting them in the CommentTreeWidget. Selections from the TreeWidget are synchronized to the plot but not vice versa. It would generally be the better to introduce a Model/View based approach instead of trying to synchronize selections and QActions.
409 lines
14 KiB
C++
409 lines
14 KiB
C++
/*
|
|
* Copyright (c) 2015, Technische Universität Kaiserslautern
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are
|
|
* met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
*
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* 3. Neither the name of the copyright holder nor the names of its
|
|
* contributors may be used to endorse or promote products derived from
|
|
* this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
* Authors:
|
|
* Janik Schlemminger
|
|
* Robert Gernhardt
|
|
* Matthias Jung
|
|
* Derek Christ
|
|
*/
|
|
|
|
#include "tracefiletab.h"
|
|
#include "ui_tracefiletab.h"
|
|
#include "queryeditor.h"
|
|
#include "QFileInfo"
|
|
#include "qmessagebox.h"
|
|
#include "businessObjects/pythoncaller.h"
|
|
#include <iostream>
|
|
#include <QStandardItemModel>
|
|
#include <QString>
|
|
#include <QItemDelegate>
|
|
#include <QFileDialog>
|
|
#include <QtConcurrent/QtConcurrent>
|
|
#include <QTextStream>
|
|
#include <QDebug>
|
|
#include "qwt_plot_histogram.h"
|
|
#include "qwt_plot_curve.h"
|
|
#include "qwt_plot_layout.h"
|
|
#include "qwt_scale_draw.h"
|
|
#include "qwt_scale_widget.h"
|
|
#include "qwt_legend.h"
|
|
#include "qwt_plot_magnifier.h"
|
|
#include "qwt_plot_panner.h"
|
|
#include "presentation/traceselector.h"
|
|
#include "businessObjects/configmodels.h"
|
|
|
|
#include <math.h>
|
|
|
|
TraceFileTab::TraceFileTab(QWidget *parent, const QString &path) :
|
|
QWidget(parent), ui(new Ui::TraceFileTab), navigator(new TraceNavigator(path, this)),
|
|
mcConfigModel(new McConfigModel(navigator->TraceFile(), this)),
|
|
memSpecModel(new MemSpecModel(navigator->TraceFile(), this)),
|
|
savingChangesToDB(false)
|
|
{
|
|
ui->setupUi(this);
|
|
this->path = path;
|
|
|
|
std::cout << "Opening new tab for \"" << path.toStdString() << "\"" <<
|
|
std::endl;
|
|
|
|
initNavigatorAndItsDependentWidgets(path);
|
|
setUpFileWatcher(path);
|
|
setUpTraceplotScrollbar();
|
|
setUpTraceSelector();
|
|
|
|
ui->fileDescriptionEdit->setPlainText(
|
|
navigator->GeneralTraceInfo().description);
|
|
|
|
ui->mcConfigView->setModel(mcConfigModel);
|
|
ui->mcConfigView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
ui->memSpecView->setModel(memSpecModel);
|
|
ui->memSpecView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
connect(ui->commentTree, &CommentTreeWidget::selectedCommentsChanged,
|
|
navigator, &TraceNavigator::updateCommentSelection);
|
|
|
|
tracefileChanged();
|
|
}
|
|
|
|
TraceFileTab::~TraceFileTab()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void TraceFileTab::commitChangesToDB()
|
|
{
|
|
savingChangesToDB = true;
|
|
navigator->commitChangesToDB();
|
|
}
|
|
|
|
void TraceFileTab::exportAsVCD()
|
|
{
|
|
QString filename = QFileDialog::getSaveFileName(this, "Export to VCD", "",
|
|
"VCD files (*.vcd)");
|
|
auto dumpVcd = [=]() {
|
|
QString dump = PythonCaller::instance().exportAsVcd(path);
|
|
|
|
QFile file(filename);
|
|
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
|
QTextStream out(&file);
|
|
out << dump;
|
|
file.close();
|
|
|
|
Q_EMIT statusChanged(QString("VCD export finished."));
|
|
};
|
|
|
|
if (filename != "") {
|
|
QtConcurrent::run(dumpVcd);
|
|
}
|
|
}
|
|
|
|
void TraceFileTab::setUpTraceplotScrollbar()
|
|
{
|
|
QObject::connect(ui->traceplotScrollbar, SIGNAL(valueChanged(int)),
|
|
ui->traceplot, SLOT(verticalScrollbarChanged(int)));
|
|
}
|
|
|
|
void TraceFileTab::initNavigatorAndItsDependentWidgets(QString path)
|
|
{
|
|
ui->traceplot->init(navigator, ui->traceplotScrollbar);
|
|
|
|
ui->traceScroller->init(navigator, ui->traceplot);
|
|
connect(this, SIGNAL(colorGroupingChanged(ColorGrouping)),
|
|
ui->traceScroller, SLOT(colorGroupingChanged(ColorGrouping)));
|
|
|
|
ui->selectedTransactionTree->init(navigator);
|
|
//ui->debugMessages->init(navigator,ui->traceplot);
|
|
ui->commentTree->init(navigator);
|
|
}
|
|
|
|
void TraceFileTab::setUpFileWatcher(QString path)
|
|
{
|
|
fileWatcher = new QFileSystemWatcher(QStringList(path), this);
|
|
QObject::connect(fileWatcher, SIGNAL(fileChanged(QString)), this,
|
|
SLOT(tracefileChanged()));
|
|
}
|
|
|
|
void TraceFileTab::setUpTraceSelector()
|
|
{
|
|
TraceSelector *selector = ui->tabCustomizePlot;
|
|
connect(selector, &TraceSelector::selectedTreeChanged,
|
|
ui->traceplot, &TracePlot::updateTracePlotLines);
|
|
selector->init(ui->traceplot);
|
|
}
|
|
|
|
void TraceFileTab::tracefileChanged()
|
|
{
|
|
if (savingChangesToDB == true) {
|
|
// Database has changed due to user action (e.g., saving comments).
|
|
// No need to disable the "Save changes to DB" menu.
|
|
savingChangesToDB = false;
|
|
Q_EMIT statusChanged(QString("Changes saved "), true);
|
|
} else {
|
|
// External event changed the database file (e.g., the database file
|
|
// was overwritten when running a new test).
|
|
// The "Save changes to DB" menu must be disabled to avoid saving
|
|
// changes to a corrupted or inconsistent file.
|
|
Q_EMIT statusChanged(QString("At least one database has changed on disk "),
|
|
false);
|
|
}
|
|
navigator->refreshData();
|
|
}
|
|
|
|
class ItemDelegate: public QItemDelegate
|
|
{
|
|
public:
|
|
ItemDelegate(QObject* parent = nullptr): QItemDelegate(parent)
|
|
{
|
|
}
|
|
|
|
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
{
|
|
if (index.column() == 1) {
|
|
double progress = index.data().toDouble();
|
|
QStyleOptionProgressBar opt;
|
|
opt.rect = option.rect;
|
|
opt.minimum = 0;
|
|
opt.maximum = 100;
|
|
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);
|
|
} else {
|
|
QItemDelegate::paint(painter, option, index);
|
|
}
|
|
}
|
|
};
|
|
|
|
void TraceFileTab::on_tabWidget_currentChanged(int index)
|
|
{
|
|
}
|
|
|
|
void TraceFileTab::on_latencyTreeView_doubleClicked(const QModelIndex &index)
|
|
{
|
|
// Get onlye the leaf:
|
|
if(index.column() == 0 && index.model()->hasChildren(index) == false) {
|
|
unsigned int id = index.data().toUInt();
|
|
if(id!=0) {
|
|
navigator->selectTransaction(id);
|
|
}
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
void TraceFileTab::on_startPowerAnalysis_clicked()
|
|
{
|
|
qDebug() << "Power Analysis";
|
|
QSqlDatabase db = navigator->TraceFile().getDatabase();
|
|
QSqlQuery query(db);
|
|
|
|
QString sql = "SELECT time, AveragePower FROM Power;";
|
|
|
|
query.exec(sql);
|
|
|
|
QwtPointSeriesData * data = new QwtPointSeriesData;
|
|
QwtPlotCurve * cur = new QwtPlotCurve("Speed");
|
|
QVector<QPointF>* samples=new QVector<QPointF>;
|
|
|
|
while (query.next()) {
|
|
double time = query.value(0).toDouble();
|
|
double power = query.value(1).toDouble();
|
|
samples->push_back(QPointF(time,power));
|
|
}
|
|
|
|
//ui->powerPlot->setAxisTitle(QwtPlot::xBottom,"Time");
|
|
//ui->powerPlot->setAxisLabelRotation(QwtPlot::xBottom,-50.0);
|
|
//ui->powerPlot->setAxisLabelAlignment(QwtPlot::xBottom,Qt::AlignLeft|Qt::AlignBottom);
|
|
//ui->powerPlot->setAxisTitle(QwtPlot::yLeft,"Power");
|
|
|
|
data->setSamples(*samples);
|
|
cur->setData(data);
|
|
cur->attach(ui->powerPlot);
|
|
|
|
QwtPlotMagnifier *mag1 = new QwtPlotMagnifier(ui->powerPlot->canvas());
|
|
mag1->setAxisEnabled(QwtPlot::xBottom, true);
|
|
mag1->setAxisEnabled(QwtPlot::yLeft, false);
|
|
mag1->setWheelFactor(5);
|
|
QwtPlotPanner *pan1 = new QwtPlotPanner(ui->powerPlot->canvas());
|
|
pan1->setAxisEnabled(QwtPlot::xBottom, true);
|
|
pan1->setAxisEnabled(QwtPlot::yLeft, false);
|
|
|
|
ui->powerPlot->replot();
|
|
|
|
// Bandwidth analysis:
|
|
sql = "SELECT time, AverageBandwidth FROM Bandwidth;";
|
|
query.exec(sql);
|
|
|
|
QwtPointSeriesData * data2 = new QwtPointSeriesData;
|
|
QwtPlotCurve * cur2 = new QwtPlotCurve("Speed");
|
|
QVector<QPointF>* samples2=new QVector<QPointF>;
|
|
|
|
while (query.next()) {
|
|
double time = query.value(0).toDouble();
|
|
double percentage = query.value(1).toDouble() * 100.0;
|
|
samples2->push_back(QPointF(time, percentage));
|
|
}
|
|
|
|
data2->setSamples(*samples2);
|
|
cur2->setData(data2);
|
|
cur2->attach(ui->bandwidthPlot);
|
|
|
|
ui->bandwidthPlot->setAxisTitle(0,"Bandwidth [%]");
|
|
ui->bandwidthPlot->setAxisScale(0,0.0,100.0);
|
|
QwtText axisTitle2( "Time [s]" );
|
|
axisTitle2.setFont( ui->bandwidthPlot->axisTitle( QwtPlot::xBottom ).font() );
|
|
ui->bandwidthPlot->setAxisTitle( QwtPlot::xBottom, axisTitle2 );
|
|
|
|
QwtPlotMagnifier *mag2 = new QwtPlotMagnifier(ui->bandwidthPlot->canvas());
|
|
mag2->setAxisEnabled(QwtPlot::xBottom, true);
|
|
mag2->setAxisEnabled(QwtPlot::yLeft, false);
|
|
mag2->setWheelFactor(5);
|
|
QwtPlotPanner *pan2 = new QwtPlotPanner(ui->bandwidthPlot->canvas());
|
|
pan2->setAxisEnabled(QwtPlot::xBottom, true);
|
|
pan2->setAxisEnabled(QwtPlot::yLeft, false);
|
|
|
|
ui->bandwidthPlot->replot();
|
|
|
|
// Buffer analysis:
|
|
sql = "select max(BufferNumber) from BufferDepth;";
|
|
query.exec(sql);
|
|
query.next();
|
|
unsigned int numberOfBuffers = query.value(0).toUInt();
|
|
|
|
sql = "select MaxBufferDepth from GeneralInfo;";
|
|
query.exec(sql);
|
|
query.next();
|
|
unsigned int maxBufferDepth = query.value(0).toUInt();
|
|
|
|
sql = "select Time, AverageBufferDepth from BufferDepth where BufferNumber = 0"; // TODO
|
|
query.exec(sql);
|
|
|
|
QwtPointSeriesData * data3 = new QwtPointSeriesData;
|
|
QwtPlotCurve * cur3 = new QwtPlotCurve("Speed");
|
|
QVector<QPointF>* samples3 = new QVector<QPointF>;
|
|
|
|
while (query.next()) {
|
|
double time = query.value(0).toDouble();
|
|
double queue = query.value(1).toDouble();
|
|
samples3->push_back(QPointF(time, queue));
|
|
}
|
|
|
|
data3->setSamples(*samples3);
|
|
cur3->setData(data3);
|
|
cur3->attach(ui->bufferPlot);
|
|
|
|
ui->bufferPlot->setAxisTitle(0,"Buffer Utilization");
|
|
ui->bufferPlot->setAxisScale(0,0.0, maxBufferDepth);
|
|
QwtText axisTitle3( "Time [s]" );
|
|
axisTitle3.setFont( ui->bufferPlot->axisTitle( QwtPlot::xBottom ).font() );
|
|
ui->bufferPlot->setAxisTitle( QwtPlot::xBottom, axisTitle3 );
|
|
|
|
QwtPlotMagnifier *mag3 = new QwtPlotMagnifier(ui->bufferPlot->canvas());
|
|
mag3->setAxisEnabled(QwtPlot::xBottom, true);
|
|
mag3->setAxisEnabled(QwtPlot::yLeft, false);
|
|
mag3->setWheelFactor(5);
|
|
QwtPlotPanner *pan3 = new QwtPlotPanner(ui->bufferPlot->canvas());
|
|
pan3->setAxisEnabled(QwtPlot::xBottom, true);
|
|
pan3->setAxisEnabled(QwtPlot::yLeft, false);
|
|
|
|
ui->bufferPlot->replot();
|
|
}
|