diff --git a/DRAMSys/traceAnalyzer/CMakeLists.txt b/DRAMSys/traceAnalyzer/CMakeLists.txt index f182b186..ae70b48c 100644 --- a/DRAMSys/traceAnalyzer/CMakeLists.txt +++ b/DRAMSys/traceAnalyzer/CMakeLists.txt @@ -96,6 +96,7 @@ add_executable(TraceAnalyzer presentation/util/traceplotlinecache.cpp presentation/util/customlabelscaledraw.cpp presentation/traceselector.cpp + businessObjects/configmodels.cpp selectmetrics.ui preferences.ui diff --git a/DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp b/DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp new file mode 100644 index 00000000..3748d438 --- /dev/null +++ b/DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021, 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: + * Derek Christ + */ + +#include "configmodels.h" + +#include +#include + +McConfigModel::McConfigModel(const TraceDB &traceFile, QObject *parent) : QAbstractTableModel(parent) +{ + QSqlDatabase db = traceFile.getDatabase(); + QString query = "SELECT MCconfig FROM GeneralInfo"; + QSqlQuery sqlQuery = db.exec(query); + + // The whole configuration is stored in a single cell. + sqlQuery.next(); + QString mcConfigJson = sqlQuery.value(0).toString(); + + parseJson(mcConfigJson); + + qDebug() << roleNames(); +} + +void McConfigModel::parseJson(const QString &jsonString) +{ + QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonString.toUtf8()); + QJsonObject mcConfigJson = jsonDocument["mcconfig"].toObject(); + + for (auto key : mcConfigJson.keys()) + { + QJsonValue currentValue = mcConfigJson.value(key); + + if (currentValue.isDouble()) + { + entries.push_back(std::make_pair(key, QString::number(currentValue.toDouble()))); + } + else if (currentValue.isString()) + { + entries.push_back(std::make_pair(key, currentValue.toString())); + } + } +} + +int McConfigModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + + return entries.size(); +} + +int McConfigModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + + return 2; +} + +QVariant McConfigModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role != Qt::DisplayRole) + return QVariant(); + + auto entry = entries.at(index.row()); + + if (index.column() == 0) + return entry.first; + else if (index.column() == 1) + return entry.second; + + return QVariant(); +} + +QVariant McConfigModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + if (orientation == Qt::Horizontal) + { + switch (section) { + case 0: + return "Field"; + case 1: + return "Value"; + default: + break; + } + } + + return QVariant(); +} diff --git a/DRAMSys/traceAnalyzer/businessObjects/configmodels.h b/DRAMSys/traceAnalyzer/businessObjects/configmodels.h new file mode 100644 index 00000000..327b20cb --- /dev/null +++ b/DRAMSys/traceAnalyzer/businessObjects/configmodels.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021, 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: + * Derek Christ + */ + +#ifndef CONFIGMODELS_H +#define CONFIGMODELS_H + +#include "../data/tracedb.h" + +#include +#include +#include + +class McConfigModel : public QAbstractTableModel +{ +public: + McConfigModel(const TraceDB &traceFile, QObject *parent = nullptr); + ~McConfigModel() {} + +protected: + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + +private: + /** + * Parses the json file and adds json entries to the entries vector. + * In case of failure, nothing is added and therefore the model + * will stay empty. + */ + void parseJson(const QString &jsonString); + + std::vector> entries; +}; + +class MemSpecsModel : public QAbstractItemModel +{ + +}; + +#endif // CONFIGMODELS_H diff --git a/DRAMSys/traceAnalyzer/tracefiletab.cpp b/DRAMSys/traceAnalyzer/tracefiletab.cpp index 842c1760..93c60ae4 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.cpp +++ b/DRAMSys/traceAnalyzer/tracefiletab.cpp @@ -59,11 +59,13 @@ #include "qwt_plot_magnifier.h" #include "qwt_plot_panner.h" #include "presentation/traceselector.h" +#include "businessObjects/configmodels.h" #include TraceFileTab::TraceFileTab(QWidget *parent, const QString &path) : - QWidget(parent), ui(new Ui::TraceFileTab), savingChangesToDB(false) + QWidget(parent), ui(new Ui::TraceFileTab), navigator(new TraceNavigator(path, this)), + mcConfigModel(new McConfigModel(navigator->TraceFile(), this)), savingChangesToDB(false) { ui->setupUi(this); this->path = path; @@ -79,6 +81,9 @@ TraceFileTab::TraceFileTab(QWidget *parent, const QString &path) : ui->fileDescriptionEdit->setPlainText( navigator->GeneralTraceInfo().description); + ui->mcConfigView->setModel(mcConfigModel); + ui->mcConfigView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + tracefileChanged(); } @@ -122,8 +127,6 @@ void TraceFileTab::setUpTraceplotScrollbar() void TraceFileTab::initNavigatorAndItsDependentWidgets(QString path) { - navigator = new TraceNavigator(path, this); - ui->traceplot->init(navigator, ui->traceplotScrollbar); ui->traceScroller->init(navigator, ui->traceplot); diff --git a/DRAMSys/traceAnalyzer/tracefiletab.h b/DRAMSys/traceAnalyzer/tracefiletab.h index 25fa915c..9fd7b3a3 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.h +++ b/DRAMSys/traceAnalyzer/tracefiletab.h @@ -45,6 +45,7 @@ #include "presentation/tracenavigator.h" #include "presentation/traceplot.h" #include "presentation/tracescroller.h" +#include "businessObjects/configmodels.h" namespace Ui { class TraceFileTab; @@ -74,6 +75,10 @@ private: Ui::TraceFileTab *ui; TraceNavigator *navigator; QFileSystemWatcher *fileWatcher; + + QAbstractItemModel *mcConfigModel; + //QAbstractItemModel *memSpecModel; + void setUpQueryEditor(QString path); bool savingChangesToDB; diff --git a/DRAMSys/traceAnalyzer/tracefiletab.ui b/DRAMSys/traceAnalyzer/tracefiletab.ui index cd45bbef..c6555e26 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.ui +++ b/DRAMSys/traceAnalyzer/tracefiletab.ui @@ -348,6 +348,35 @@ + + + Simulation Configuration + + + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + true + + + true + + + false + + + + + + + +