diff --git a/DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp b/DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp index 94fe6ddd..7a1e893c 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp @@ -282,3 +282,142 @@ QModelIndex MemSpecModel::parent(const QModelIndex &index) const return createIndex(parentNode->getRow(), 0, const_cast(parentNode)); } + +DependencyInfosModel::DependencyInfosModel(TraceDB &traceFile, QObject *parent) + : QAbstractItemModel(parent) +{ + mDepInfosDepType = traceFile.getDependencyInfos(DependencyInfos::Type::DependencyType); + mDepInfosTimeDep = traceFile.getDependencyInfos(DependencyInfos::Type::TimeDependency); + mDepInfosDelPhase = traceFile.getDependencyInfos(DependencyInfos::Type::DelayedPhase); + mDepInfosDepPhase = traceFile.getDependencyInfos(DependencyInfos::Type::DependencyPhase); + + parseInfos(); +} + +int DependencyInfosModel::Node::getRow() const +{ + if (!parent) + return 0; + + const auto &siblings = parent->children; + const auto siblingsIt = std::find_if(siblings.begin(), siblings.end(), [this](const std::unique_ptr &node){ + return node.get() == this; + }); + + Q_ASSERT(siblingsIt != siblings.end()); + + return std::distance(siblings.begin(), siblingsIt); +} + +void DependencyInfosModel::parseInfos() +{ + std::vector> infos = { + {"Dependency Granularity", mDepInfosDepType}, + {"Time Dependencies", mDepInfosTimeDep}, + {"Delayed Phases", mDepInfosDelPhase}, + {"Dependency Phases", mDepInfosDepPhase} + }; + + for (auto pair : infos) + { + std::unique_ptr node = std::unique_ptr(new Node({pair.first, ""}, rootNode.get())); + + for (auto v : pair.second.getInfos()) { + QString value = QString::number(v.value) + " %"; + node->children.push_back(std::move(std::unique_ptr(new Node({v.id, value}, node.get())))); + + } + + rootNode->children.push_back(std::move(node)); + + } +} + +int DependencyInfosModel::rowCount(const QModelIndex &parent) const +{ + if (parent.column() > 0) + return 0; + + const Node *parentNode; + + if (!parent.isValid()) + parentNode = rootNode.get(); + else + parentNode = static_cast(parent.internalPointer()); + + return parentNode->childCount(); +} + +int DependencyInfosModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + + return 2; +} + +QVariant DependencyInfosModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role != Qt::DisplayRole && role != Qt::ToolTipRole) + return QVariant(); + + auto *node = static_cast(index.internalPointer()); + + if (index.column() == 0) + return QVariant(node->data.first); + else + return QVariant(node->data.second); +} + +QVariant DependencyInfosModel::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 "Percentage"; + default: + break; + } + } + + return QVariant(); +} + +QModelIndex DependencyInfosModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + const Node *parentNode; + + if (!parent.isValid()) + parentNode = rootNode.get(); + else + parentNode = static_cast(parent.internalPointer()); + + const Node *node = parentNode->children[row].get(); + + return createIndex(row, column, const_cast(node)); +} + +QModelIndex DependencyInfosModel::parent(const QModelIndex &index) const +{ + if (!index.isValid()) + return QModelIndex(); + + const Node *childNode = static_cast(index.internalPointer()); + const Node *parentNode = childNode->parent; + + if (!parentNode) + return QModelIndex(); + + return createIndex(parentNode->getRow(), 0, const_cast(parentNode)); +} diff --git a/DRAMSys/traceAnalyzer/businessObjects/configmodels.h b/DRAMSys/traceAnalyzer/businessObjects/configmodels.h index f2a77a87..8b6c52e2 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/configmodels.h +++ b/DRAMSys/traceAnalyzer/businessObjects/configmodels.h @@ -37,6 +37,7 @@ #define CONFIGMODELS_H #include "../data/tracedb.h" +#include "phases/dependencyinfos.h" #include #include @@ -122,4 +123,50 @@ private: std::unique_ptr rootNode = std::unique_ptr(new Node); }; +class DependencyInfosModel : public QAbstractItemModel +{ + Q_OBJECT + public: + explicit DependencyInfosModel(TraceDB& traceFile, QObject* parent = nullptr); + ~DependencyInfosModel() {} + + protected: + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent) 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; + + QModelIndex index(int row, int column, const QModelIndex &parent) const override; + QModelIndex parent(const QModelIndex &index) const override; + + private: + DependencyInfos mDepInfosDepType; + DependencyInfos mDepInfosTimeDep; + DependencyInfos mDepInfosDelPhase; + DependencyInfos mDepInfosDepPhase; + + void parseInfos(); + struct Node + { + using NodeData = std::pair; + + Node() {} + Node(NodeData data, const Node *parent) : data(data), parent(parent) {} + + /** + * Gets the row relative to its parent. + */ + int getRow() const; + int childCount() const { return children.size(); } + + NodeData data; + + const Node *parent = nullptr; + std::vector> children; + }; + + std::unique_ptr rootNode = std::unique_ptr(new Node); +}; + #endif // CONFIGMODELS_H diff --git a/DRAMSys/traceAnalyzer/businessObjects/phases/dependencyinfos.h b/DRAMSys/traceAnalyzer/businessObjects/phases/dependencyinfos.h index 7c70ec52..801f4272 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phases/dependencyinfos.h +++ b/DRAMSys/traceAnalyzer/businessObjects/phases/dependencyinfos.h @@ -28,6 +28,7 @@ class DependencyInfos void addInfo(DependencyInfo); const std::vector& getInfos() const { return mInfos; } + size_t size() const { return mInfos.size(); } private: Type mType; diff --git a/DRAMSys/traceAnalyzer/data/tracedb.cpp b/DRAMSys/traceAnalyzer/data/tracedb.cpp index f7f85123..9259c07d 100644 --- a/DRAMSys/traceAnalyzer/data/tracedb.cpp +++ b/DRAMSys/traceAnalyzer/data/tracedb.cpp @@ -158,7 +158,7 @@ void TraceDB::updateDependenciesInTimespan(const Timespan &span) selectDependenciesByTimespan.bindValue(":begin", span.Begin()); selectDependenciesByTimespan.bindValue(":end", span.End()); executeQuery(selectDependenciesByTimespan); - _updateDependenciesFromQuery(selectDependenciesByTimespan); + mUpdateDependenciesFromQuery(selectDependenciesByTimespan); } @@ -491,7 +491,7 @@ vector> TraceDB::parseTransactionsFromQuery( return result; } -void TraceDB::_updateDependenciesFromQuery(QSqlQuery &query) { +void TraceDB::mUpdateDependenciesFromQuery(QSqlQuery &query) { DependencyType type; while(query.next()) { ID delayedID = query.value(0).toInt(); diff --git a/DRAMSys/traceAnalyzer/data/tracedb.h b/DRAMSys/traceAnalyzer/data/tracedb.h index c81599a9..5b8157be 100644 --- a/DRAMSys/traceAnalyzer/data/tracedb.h +++ b/DRAMSys/traceAnalyzer/data/tracedb.h @@ -97,7 +97,6 @@ public: // std::shared_ptr getNextActb(ID currentTransactionId); // std::shared_ptr getNextRefb(ID currentTransactionId); - void _updateDependenciesFromQuery(QSqlQuery &query); std::shared_ptr getTransactionByID(ID id); ID getTransactionIDFromPhaseID(ID phaseID); @@ -107,7 +106,6 @@ public: std::vector getDebugMessagesInTimespan(const Timespan &span, unsigned int limit); - // TODO DependencyInfos getDependencyInfos(DependencyInfos::Type infoType); QSqlDatabase getDatabase() const; @@ -141,6 +139,7 @@ private: bool updateVisiblePhases = false); std::vector parseCommentsFromQuery(QSqlQuery &query); + void mUpdateDependenciesFromQuery(QSqlQuery &query); DependencyInfos parseDependencyInfos(QSqlQuery & query, const DependencyInfos::Type infoType); void executeScriptFile(QString fileName); diff --git a/DRAMSys/traceAnalyzer/tracefiletab.cpp b/DRAMSys/traceAnalyzer/tracefiletab.cpp index e6368c31..f3d3cb34 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.cpp +++ b/DRAMSys/traceAnalyzer/tracefiletab.cpp @@ -68,7 +68,8 @@ TraceFileTab::TraceFileTab(QWidget *parent, const QString &path) : QWidget(parent), ui(new Ui::TraceFileTab), commentModel(new CommentModel(this)), navigator(new TraceNavigator(path, commentModel, this)), mcConfigModel(new McConfigModel(navigator->TraceFile(), this)), - memSpecModel(new MemSpecModel(navigator->TraceFile(), this)), savingChangesToDB(false) + memSpecModel(new MemSpecModel(navigator->TraceFile(), this)), savingChangesToDB(false), + depInfosView(new DependencyInfosModel(navigator->TraceFile(), this)) { ui->setupUi(this); this->path = path; @@ -88,6 +89,9 @@ TraceFileTab::TraceFileTab(QWidget *parent, const QString &path) ui->memSpecView->setModel(memSpecModel); ui->memSpecView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); + ui->depInfosView->setModel(depInfosView); + ui->depInfosView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); + tracefileChanged(); } diff --git a/DRAMSys/traceAnalyzer/tracefiletab.h b/DRAMSys/traceAnalyzer/tracefiletab.h index fb4c9392..b82a2ba1 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.h +++ b/DRAMSys/traceAnalyzer/tracefiletab.h @@ -95,6 +95,8 @@ private: QAbstractItemModel *mcConfigModel; QAbstractItemModel *memSpecModel; + QAbstractItemModel *depInfosView; + void setUpQueryEditor(QString path); bool savingChangesToDB; diff --git a/DRAMSys/traceAnalyzer/tracefiletab.ui b/DRAMSys/traceAnalyzer/tracefiletab.ui index 6a8594d2..0f885402 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.ui +++ b/DRAMSys/traceAnalyzer/tracefiletab.ui @@ -202,6 +202,22 @@ Customize Plot + + + + Dependency Information + + + + + + true + + + + + + Comments