From d705a36183aa1267c20671182fbe0363e4197238 Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Tue, 23 Nov 2021 12:11:15 +0100 Subject: [PATCH 01/14] Testing new color configuration -- Refactored ColorGenerator and added HSV15. --- DRAMSys/traceAnalyzer/CMakeLists.txt | 1 + .../businessObjects/phases/phase.cpp | 2 +- .../presentation/util/colorgenerator.cpp | 89 ++------- .../presentation/util/colorgenerator.h | 21 +- .../presentation/util/colorobject.cpp | 179 ++++++++++++++++++ .../presentation/util/colorobject.h | 71 +++++++ 6 files changed, 286 insertions(+), 77 deletions(-) create mode 100644 DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp create mode 100644 DRAMSys/traceAnalyzer/presentation/util/colorobject.h diff --git a/DRAMSys/traceAnalyzer/CMakeLists.txt b/DRAMSys/traceAnalyzer/CMakeLists.txt index 355a8c90..c703e713 100644 --- a/DRAMSys/traceAnalyzer/CMakeLists.txt +++ b/DRAMSys/traceAnalyzer/CMakeLists.txt @@ -68,6 +68,7 @@ add_executable(TraceAnalyzer data/tracedb.cpp presentation/tracenavigator.cpp presentation/util/colorgenerator.cpp + presentation/util/colorobject.cpp presentation/tracedrawing.cpp presentation/traceplotitem.cpp gototimedialog.cpp diff --git a/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp b/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp index 15ec782a..55a7e0d0 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp @@ -187,7 +187,7 @@ QColor Phase::getColor(const TraceDrawingProperties &drawingProperties) const return ColorGenerator::getColor(static_cast(transaction.lock()->thread)); break; case ColorGrouping::AlphaTransaction: - return ColorGenerator::getAlphaColored(transaction.lock()->id); + return ColorGenerator::getAlphaColored(transaction.lock()->id, ColorName::HSV15); break; case ColorGrouping::Transaction: diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.cpp b/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.cpp index ae3070a6..11cf1023 100644 --- a/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.cpp +++ b/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.cpp @@ -38,79 +38,30 @@ #include "colorgenerator.h" #include -ColorGenerator::ColorGenerator() + +QColor ColorGenerator::getColor(unsigned int i, ColorName color) { - r[0] = 0xFF; - r[1] = 0x00; - r[2] = 0x00; - r[3] = 0xFF; - g[0] = 0x00; - g[1] = 0xFF; - g[2] = 0x00; - g[3] = 0xFF; - b[0] = 0x00; - b[1] = 0x00; - b[2] = 0xFF; - b[3] = 0x00; - - r[4] = 0xFF; - r[5] = 0x00; - r[6] = 0xFF; - r[7] = 0x6B; - g[4] = 0x00; - g[5] = 0xFF; - g[6] = 0xA5; - g[7] = 0x8E; - b[4] = 0xFF; - b[5] = 0xFF; - b[6] = 0x00; - b[7] = 0x23; - - r[8] = 0x8A; - r[9] = 0xFF; - r[10] = 0x7C; - r[11] = 0x00; - g[8] = 0x2B; - g[9] = 0xD7; - g[10] = 0xFC; - g[11] = 0x00; - b[8] = 0xE2; - b[9] = 0x00; - b[10] = 0x00; - b[11] = 0x80; - - r[12] = 0x80; - r[13] = 0x00; - r[14] = 0xEE; - r[15] = 0xFF; - g[12] = 0x00; - g[13] = 0x80; - g[14] = 0x82; - g[15] = 0x45; - b[12] = 0x00; - b[13] = 0x00; - b[14] = 0xEE; - b[15] = 0x00; + switch(color) { + case ColorName::Default: + return cDefault.getColor(i); + case ColorName::HSV15: + return cHSV15.getColor(i); + } + return {0, 0, 0}; } -QColor ColorGenerator::getColor(unsigned int i) +QColor ColorGenerator::getAlphaColored(unsigned int i, ColorName color) { - static ColorGenerator gen; - i = i % 16; - QColor result(gen.r[i], gen.g[i], gen.b[i]); - result.setAlpha(130); - return result; + switch(color) { + case ColorName::Default: + return cDefault.getAlphaColored(i); + case ColorName::HSV15: + return cHSV15.getAlphaColored(i); + } + + return {0, 0, 0}; } -QColor ColorGenerator::getAlphaColored(unsigned int i) -{ - static ColorGenerator gen; - const int minAlpha = 25; - const int alphaLevels = 40 - 255 / minAlpha; - int alpha = minAlpha + (int)(((255. - minAlpha) / alphaLevels) * (i % alphaLevels)); - i = (i / alphaLevels) % 16; - QColor result(gen.r[i], gen.g[i], gen.b[i]); - result.setAlpha(alpha); - return result; -} +ColorDefault ColorGenerator::cDefault; +ColorHSV15 ColorGenerator::cHSV15; diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.h b/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.h index 35941474..7897393d 100644 --- a/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.h +++ b/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.h @@ -39,21 +39,28 @@ #ifndef COLORGENERATOR_H #define COLORGENERATOR_H +#include "colorobject.h" + #include #include +enum ColorName +{ + Default, + HSV15 +}; + class ColorGenerator { private: - static constexpr int NumberOfColors = 16; - int r[NumberOfColors]; - int g[NumberOfColors]; - int b[NumberOfColors]; - ColorGenerator(); + ColorGenerator() = delete; + + static ColorDefault cDefault; + static ColorHSV15 cHSV15; public: - static QColor getColor(unsigned int i); - static QColor getAlphaColored(unsigned int i); + static QColor getColor(unsigned int i, ColorName color = ColorName::Default); + static QColor getAlphaColored(unsigned int i, ColorName color = ColorName::Default); }; diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp b/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp new file mode 100644 index 00000000..9f708e98 --- /dev/null +++ b/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp @@ -0,0 +1,179 @@ +/* + * 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 + * Iron Prando da Silva + */ + +#include "colorobject.h" + + +QColor ColorObject::getColor(unsigned int i) +{ + i = i % numberOfColors; + QColor result(r[i], g[i], b[i]); + result.setAlpha(130); + return result; +} + +QColor ColorObject::getAlphaColored(unsigned int i) +{ + const int minAlpha = 50; + const int alphaLevels = 20 - 255 / minAlpha; + + int alpha = minAlpha + (int)(((255. - minAlpha) / alphaLevels) * (i % alphaLevels)); + i = (i / alphaLevels) % numberOfColors; + QColor result(r[i], g[i], b[i]); + result.setAlpha(alpha); + + return result; +} + +ColorDefault::ColorDefault() +{ + numberOfColors = 16; + + r.resize(numberOfColors); + g.resize(numberOfColors); + b.resize(numberOfColors); + + r[0] = 0xFF; + r[1] = 0x00; + r[2] = 0x00; + r[3] = 0xFF; + g[0] = 0x00; + g[1] = 0xFF; + g[2] = 0x00; + g[3] = 0xFF; + b[0] = 0x00; + b[1] = 0x00; + b[2] = 0xFF; + b[3] = 0x00; + + r[4] = 0xFF; + r[5] = 0x00; + r[6] = 0xFF; + r[7] = 0x6B; + g[4] = 0x00; + g[5] = 0xFF; + g[6] = 0xA5; + g[7] = 0x8E; + b[4] = 0xFF; + b[5] = 0xFF; + b[6] = 0x00; + b[7] = 0x23; + + r[8] = 0x8A; + r[9] = 0xFF; + r[10] = 0x7C; + r[11] = 0x00; + g[8] = 0x2B; + g[9] = 0xD7; + g[10] = 0xFC; + g[11] = 0x00; + b[8] = 0xE2; + b[9] = 0x00; + b[10] = 0x00; + b[11] = 0x80; + + r[12] = 0x80; + r[13] = 0x00; + r[14] = 0xEE; + r[15] = 0xFF; + g[12] = 0x00; + g[13] = 0x80; + g[14] = 0x82; + g[15] = 0x45; + b[12] = 0x00; + b[13] = 0x00; + b[14] = 0xEE; + b[15] = 0x00; +} + +ColorHSV15::ColorHSV15() +{ + numberOfColors = 15; + + r.resize(numberOfColors); + g.resize(numberOfColors); + b.resize(numberOfColors); + + r[0] = 0XFF; + r[1] = 0XFF; + r[2] = 0XFF; + r[3] = 0XD1; + r[4] = 0X6C; + r[5] = 0X08; + r[6] = 0X00; + r[7] = 0X00; + r[8] = 0X00; + r[9] = 0X00; + r[10] = 0X00; + r[11] = 0X54; + r[12] = 0XB9; + r[13] = 0XFF; + r[14] = 0XFF; + + g[0] = 0X00; + g[1] = 0X64; + g[2] = 0XC9; + g[3] = 0XFF; + g[4] = 0XFF; + g[5] = 0XFF; + g[6] = 0XFF; + g[7] = 0XFF; + g[8] = 0XD9; + g[9] = 0X74; + g[10] = 0X10; + g[11] = 0X00; + g[12] = 0X00; + g[13] = 0X00; + g[14] = 0X00; + + b[0] = 0X00; + b[1] = 0X00; + b[2] = 0X00; + b[3] = 0X00; + b[4] = 0X00; + b[5] = 0X00; + b[6] = 0X5C; + b[7] = 0XC1; + b[8] = 0XFF; + b[9] = 0XFF; + b[10] = 0XFF; + b[11] = 0XFF; + b[12] = 0XFF; + b[13] = 0XE1; + b[14] = 0X7C; +} diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorobject.h b/DRAMSys/traceAnalyzer/presentation/util/colorobject.h new file mode 100644 index 00000000..f54ee8f4 --- /dev/null +++ b/DRAMSys/traceAnalyzer/presentation/util/colorobject.h @@ -0,0 +1,71 @@ +/* + * 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 + * Iron Prando da Silva + */ + +#pragma once + +#include + +class ColorObject +{ +protected: + int numberOfColors = 0; + + std::vector r; + std::vector g; + std::vector b; + // std::vector a; + + ColorObject() {}; + +public: + + virtual QColor getColor(unsigned int i); + virtual QColor getAlphaColored(unsigned int i); +}; + +class ColorDefault : public ColorObject +{ +public: + ColorDefault(); +}; + +class ColorHSV15 : public ColorObject +{ +public: + ColorHSV15(); +}; From 92c8e0c72c6a371d344907c53b2e4b2c07eff582 Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Tue, 23 Nov 2021 13:22:09 +0100 Subject: [PATCH 02/14] Minor correction to alpha distribution equation. --- DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp b/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp index 9f708e98..a3e21ca8 100644 --- a/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp +++ b/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp @@ -51,8 +51,9 @@ QColor ColorObject::getAlphaColored(unsigned int i) { const int minAlpha = 50; const int alphaLevels = 20 - 255 / minAlpha; - - int alpha = minAlpha + (int)(((255. - minAlpha) / alphaLevels) * (i % alphaLevels)); + const int alphaStep = (255. - minAlpha) / alphaLevels; + + int alpha = minAlpha + (int)(alphaStep * (i % alphaLevels)); i = (i / alphaLevels) % numberOfColors; QColor result(r[i], g[i], b[i]); result.setAlpha(alpha); From 2f93773913b7ad7b4601e13bed88a3fdfab52d41 Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Thu, 25 Nov 2021 14:05:14 +0100 Subject: [PATCH 03/14] Renamed 'Alpha Colored' to 'Rainbow Colored'. --- .../businessObjects/phases/phase.cpp | 4 ++-- .../presentation/tracedrawingproperties.h | 2 +- DRAMSys/traceAnalyzer/presentation/traceplot.cpp | 16 ++++++++-------- DRAMSys/traceAnalyzer/presentation/traceplot.h | 4 ++-- .../presentation/util/colorgenerator.cpp | 6 +++--- .../presentation/util/colorgenerator.h | 2 +- .../presentation/util/colorobject.cpp | 2 +- .../presentation/util/colorobject.h | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp b/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp index 55a7e0d0..42c9d66d 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/phases/phase.cpp @@ -186,8 +186,8 @@ QColor Phase::getColor(const TraceDrawingProperties &drawingProperties) const case ColorGrouping::Thread: return ColorGenerator::getColor(static_cast(transaction.lock()->thread)); break; - case ColorGrouping::AlphaTransaction: - return ColorGenerator::getAlphaColored(transaction.lock()->id, ColorName::HSV15); + case ColorGrouping::RainbowTransaction: + return ColorGenerator::getRainbowColored(transaction.lock()->id, ColorName::HSV15); break; case ColorGrouping::Transaction: diff --git a/DRAMSys/traceAnalyzer/presentation/tracedrawingproperties.h b/DRAMSys/traceAnalyzer/presentation/tracedrawingproperties.h index 2573606e..0b71ce48 100644 --- a/DRAMSys/traceAnalyzer/presentation/tracedrawingproperties.h +++ b/DRAMSys/traceAnalyzer/presentation/tracedrawingproperties.h @@ -57,7 +57,7 @@ enum class ColorGrouping PhaseType, Transaction, Thread, - AlphaTransaction + RainbowTransaction }; class TracePlot; diff --git a/DRAMSys/traceAnalyzer/presentation/traceplot.cpp b/DRAMSys/traceAnalyzer/presentation/traceplot.cpp index 7c93d29d..9389c5e5 100644 --- a/DRAMSys/traceAnalyzer/presentation/traceplot.cpp +++ b/DRAMSys/traceAnalyzer/presentation/traceplot.cpp @@ -147,10 +147,10 @@ void TracePlot::setUpActions() QObject::connect(setColorGroupingTransaction, SIGNAL(triggered()), this, SLOT(on_colorGroupingTransaction())); - setColorGroupingAlphaTransaction = new QAction("Group by Transaction - Alpha Colored", this); - addAction(setColorGroupingAlphaTransaction); - QObject::connect(setColorGroupingAlphaTransaction, SIGNAL(triggered()), this, - SLOT(on_colorGroupingAlphaTransaction())); + setColorGroupingRainbowTransaction = new QAction("Group by Transaction - Rainbow Colored", this); + addAction(setColorGroupingRainbowTransaction); + QObject::connect(setColorGroupingRainbowTransaction, SIGNAL(triggered()), this, + SLOT(on_colorGroupingRainbowTransaction())); setColorGroupingThread = new QAction("Group by Thread", this); addAction(setColorGroupingThread); @@ -222,7 +222,7 @@ void TracePlot::setUpContextMenu() QMenu *colorGroupingSubMenu = new QMenu("Group by", contextMenu); colorGroupingSubMenu->addActions( - {setColorGroupingPhase, setColorGroupingTransaction, setColorGroupingThread, setColorGroupingAlphaTransaction}); + {setColorGroupingPhase, setColorGroupingTransaction, setColorGroupingRainbowTransaction, setColorGroupingThread}); contextMenu->addMenu(colorGroupingSubMenu); dependenciesSubMenu = new QMenu("Show dependencies", contextMenu); @@ -586,10 +586,10 @@ void TracePlot::on_colorGroupingTransaction() replot(); } -void TracePlot::on_colorGroupingAlphaTransaction() +void TracePlot::on_colorGroupingRainbowTransaction() { - drawingProperties.colorGrouping = ColorGrouping::AlphaTransaction; - Q_EMIT(colorGroupingChanged(ColorGrouping::AlphaTransaction)); + drawingProperties.colorGrouping = ColorGrouping::RainbowTransaction; + Q_EMIT(colorGroupingChanged(ColorGrouping::RainbowTransaction)); replot(); } diff --git a/DRAMSys/traceAnalyzer/presentation/traceplot.h b/DRAMSys/traceAnalyzer/presentation/traceplot.h index c3ec388c..560b819f 100644 --- a/DRAMSys/traceAnalyzer/presentation/traceplot.h +++ b/DRAMSys/traceAnalyzer/presentation/traceplot.h @@ -108,7 +108,7 @@ private Q_SLOTS: void on_colorGroupingPhase(); void on_colorGroupingTransaction(); void on_colorGroupingThread(); - void on_colorGroupingAlphaTransaction(); + void on_colorGroupingRainbowTransaction(); void on_goToTransaction(); void on_goToPhase(); void on_deselectAll(); @@ -181,7 +181,7 @@ private: QAction *setColorGroupingPhase; QAction *setColorGroupingTransaction; QAction *setColorGroupingThread; - QAction *setColorGroupingAlphaTransaction; + QAction *setColorGroupingRainbowTransaction; QAction *exportToPdf; ToggleCollapsedAction *toggleCollapsedState; diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.cpp b/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.cpp index 11cf1023..c42339f5 100644 --- a/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.cpp +++ b/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.cpp @@ -51,13 +51,13 @@ QColor ColorGenerator::getColor(unsigned int i, ColorName color) return {0, 0, 0}; } -QColor ColorGenerator::getAlphaColored(unsigned int i, ColorName color) +QColor ColorGenerator::getRainbowColored(unsigned int i, ColorName color) { switch(color) { case ColorName::Default: - return cDefault.getAlphaColored(i); + return cDefault.getRainbowColored(i); case ColorName::HSV15: - return cHSV15.getAlphaColored(i); + return cHSV15.getRainbowColored(i); } return {0, 0, 0}; diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.h b/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.h index 7897393d..e1e98ec0 100644 --- a/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.h +++ b/DRAMSys/traceAnalyzer/presentation/util/colorgenerator.h @@ -60,7 +60,7 @@ private: public: static QColor getColor(unsigned int i, ColorName color = ColorName::Default); - static QColor getAlphaColored(unsigned int i, ColorName color = ColorName::Default); + static QColor getRainbowColored(unsigned int i, ColorName color = ColorName::Default); }; diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp b/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp index a3e21ca8..a9a4e82b 100644 --- a/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp +++ b/DRAMSys/traceAnalyzer/presentation/util/colorobject.cpp @@ -47,7 +47,7 @@ QColor ColorObject::getColor(unsigned int i) return result; } -QColor ColorObject::getAlphaColored(unsigned int i) +QColor ColorObject::getRainbowColored(unsigned int i) { const int minAlpha = 50; const int alphaLevels = 20 - 255 / minAlpha; diff --git a/DRAMSys/traceAnalyzer/presentation/util/colorobject.h b/DRAMSys/traceAnalyzer/presentation/util/colorobject.h index f54ee8f4..d3ec584c 100644 --- a/DRAMSys/traceAnalyzer/presentation/util/colorobject.h +++ b/DRAMSys/traceAnalyzer/presentation/util/colorobject.h @@ -55,7 +55,7 @@ protected: public: virtual QColor getColor(unsigned int i); - virtual QColor getAlphaColored(unsigned int i); + virtual QColor getRainbowColored(unsigned int i); }; class ColorDefault : public ColorObject From da63d2670e019985883b2f945812728e8c0fcf9b Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Wed, 8 Dec 2021 14:44:35 +0100 Subject: [PATCH 04/14] Began adding base algorithm for dependency calculations. --- DRAMSys/traceAnalyzer/CMakeLists.txt | 1 + .../phasedependenciestracker.cpp | 134 ++++++++++++++++++ .../phasedependenciestracker.h | 45 ++++++ .../businessObjects/phases/phasedependency.h | 4 +- DRAMSys/traceAnalyzer/data/tracedb.cpp | 12 +- DRAMSys/traceAnalyzer/data/tracedb.h | 3 + DRAMSys/traceAnalyzer/tracefiletab.cpp | 20 +++ DRAMSys/traceAnalyzer/tracefiletab.h | 1 + DRAMSys/traceAnalyzer/tracefiletab.ui | 9 ++ 9 files changed, 222 insertions(+), 7 deletions(-) create mode 100644 DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp create mode 100644 DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h diff --git a/DRAMSys/traceAnalyzer/CMakeLists.txt b/DRAMSys/traceAnalyzer/CMakeLists.txt index c703e713..cdea25c1 100644 --- a/DRAMSys/traceAnalyzer/CMakeLists.txt +++ b/DRAMSys/traceAnalyzer/CMakeLists.txt @@ -91,6 +91,7 @@ add_executable(TraceAnalyzer businessObjects/pythoncaller.cpp businessObjects/tracetestresults.cpp presentation/tracemetrictreewidget.cpp + businessObjects/phasedependenciestracker.cpp businessObjects/phases/phase.cpp businessObjects/phases/phasedependency.cpp businessObjects/phases/dependencyinfos.cpp diff --git a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp new file mode 100644 index 00000000..715eed86 --- /dev/null +++ b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp @@ -0,0 +1,134 @@ + +#include "phasedependenciestracker.h" + +void +PhaseDependenciesTracker::calculateDependencies(TraceDB& tdb, const std::vector& commands) { + mDropTable(tdb); + mCreateTable(tdb); + + auto& phases = mGetAllPhases(tdb, commands); + + auto& entries = mCalculateDependencies(phases); + + mInsertIntoTable(tdb, entries); + +} + +void PhaseDependenciesTracker::mDropTable(TraceDB& tdb) { + QString command = "DROP TABLE DirectDependencies; "; + + auto query = mExecuteQuery(tdb, command); + query.finish(); +} + +void PhaseDependenciesTracker::mCreateTable(TraceDB& tdb) { + QString command = "CREATE TABLE DirectDependencies( DelayedPhaseID, DelayedPhaseName, DependencyType, TimeDependency, DependencyPhaseID, DependencyPhaseName ); "; + + auto query = mExecuteQuery(tdb, command); + query.finish(); +} + +void PhaseDependenciesTracker::mInsertIntoTable(TraceDB& tdb, const std::vector& entries) { + auto numberOfEntries = entries.size(); + size_t bulkInsertionSize = 1000; + + QString command; + size_t counter = 0; + for (auto& entry : entries) { + if (counter == 0) { + // TODO Reset command string and add first command + command = ""; + + } else if (counter == bulkInsertionSize) { + // TODO Write last command and submit + + counter = 0; + + } else { + // TODO + + counter++; + + } + + } + + if (counter != 0) { + // TODO Submit command string + } + +} + +const std::vector> +PhaseDependenciesTracker::mGetAllPhases(TraceDB& tdb, const std::vector& commands) { + std::vector> phases; + + QString queryStr = "SELECT Phases.*, Transactions.TBank, Transactions.TRank " + " FROM Phases " + " INNER JOIN Transactions " + " ON Phases.Transact=Transactions.ID " + " WHERE PhaseName IN ("; + + for (auto cmd : commands) { + queryStr += '\"' + QString::fromStdString(cmd + "\","); + } + queryStr.back() = ')'; + queryStr += " ORDER BY PhaseBegin "; + + auto query = mExecuteQuery(tdb, queryStr); + + if (!query.last()) { + throw sqlException( ("Query:\n " + tdb.queryToString(query) + "\n failed. Error: \n" + "Could not retrieve number of rows\n").toStdString(), + tdb.pathToDB.toStdString()); + } + + size_t nrows = query.at() + 1; + + if (!query.first()) { + throw sqlException( ("Query:\n " + tdb.queryToString(query) + "\n failed. Error: \n" + "Could not safely retrieve number of rows\n").toStdString(), + tdb.pathToDB.toStdString()); + } + + phases.resize(nrows); + + size_t rowIt = 0; + do { + DBPhaseEntry phase; + phase.id = query.value(0).toLongLong(); + phase.phaseName = query.value(1).toString(); + phase.phaseBegin = query.value(2).toLongLong(); + phase.phaseEnd = query.value(3).toLongLong(); + phase.transact = query.value(4).toLongLong(); + phase.tBank = query.value(5).toLongLong(); + phase.tRank = query.value(6).toLongLong(); + + phases[rowIt] = std::make_shared(phase); + ++rowIt; + } while (query.next()); + + if (rowIt != nrows) { + throw std::runtime_error("An error occurred while fetching phases in 'PhaseDependenciesTracker::mGetAllPhases': expected " + std::to_string(nrows) + " rows, but found " + std::to_string(rowIt) + "\n"); + } + + return phases; +} + +const std::vector +PhaseDependenciesTracker::mCalculateDependencies(const std::vector>& transactions) { + std::vector entries; + + // TODO Get dependency object for specific trace + // TODO Main dependency calculation loop + + return entries; +} + +QSqlQuery PhaseDependenciesTracker::mExecuteQuery(TraceDB& tdb, const QString queryStr) { + QSqlQuery query(tdb.getDatabase()); + query.prepare(queryStr); + tdb.executeQuery(query); + + return query; +} diff --git a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h new file mode 100644 index 00000000..fcfe7021 --- /dev/null +++ b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h @@ -0,0 +1,45 @@ + +#pragma once + +#include +#include +#include + +#include "data/tracedb.h" + +struct DBPhaseEntry { + size_t id; + QString phaseName; + size_t phaseBegin; + size_t phaseEnd; + size_t transact; + size_t tBank; + size_t tRank; +}; + +struct DBDependencyEntry { + size_t delayedPhaseID; + QString delayedPhaseName; + QString dependencyType; + QString timeDependency; + size_t dependencyPhaseID; + QString dependencyPhaseName; +}; + +class PhaseDependenciesTracker { +public: + static void calculateDependencies(TraceDB& tdb, const std::vector& commands); + +private: + static void mDropTable(TraceDB& tdb); + static void mCreateTable(TraceDB& tdb); + static void mInsertIntoTable(TraceDB& tdb, const std::vector& entries); + + static const std::vector> mGetAllPhases(TraceDB& tdb, const std::vector& commands); + static const std::vector mCalculateDependencies(const std::vector>& phases); + + static QSqlQuery mExecuteQuery(TraceDB& tdb, const QString queryStr); + + PhaseDependenciesTracker() = delete; + ~PhaseDependenciesTracker() = delete; +}; diff --git a/DRAMSys/traceAnalyzer/businessObjects/phases/phasedependency.h b/DRAMSys/traceAnalyzer/businessObjects/phases/phasedependency.h index 41be1c1e..fa203556 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phases/phasedependency.h +++ b/DRAMSys/traceAnalyzer/businessObjects/phases/phasedependency.h @@ -48,8 +48,8 @@ class Phase; enum DependencyType { - Bank, - Rank, + IntraBank, + IntraRank, InterRank }; diff --git a/DRAMSys/traceAnalyzer/data/tracedb.cpp b/DRAMSys/traceAnalyzer/data/tracedb.cpp index 98fa0978..0bf0bf42 100644 --- a/DRAMSys/traceAnalyzer/data/tracedb.cpp +++ b/DRAMSys/traceAnalyzer/data/tracedb.cpp @@ -152,10 +152,12 @@ vector> TraceDB::getTransactionsInTimespan(const Timespa bool TraceDB::checkDependencyTableExists() { executeQuery(checkDependenciesExist); - if (checkDependenciesExist.next() && checkDependenciesExist.value(0).toInt() == 1) - return true; - return false; + bool exists = checkDependenciesExist.next() && checkDependenciesExist.value(0).toInt() == 1; + + checkDependenciesExist.finish(); + + return exists; } void TraceDB::updateDependenciesInTimespan(const Timespan &span) @@ -505,11 +507,11 @@ void TraceDB::mUpdateDependenciesFromQuery(QSqlQuery &query) QString dependencyTypeStr = query.value(2).toString(); if (dependencyTypeStr == "bank") { - type = DependencyType::Bank; + type = DependencyType::IntraBank; } else if (dependencyTypeStr == "rank") { - type = DependencyType::Rank; + type = DependencyType::IntraRank; } else if (dependencyTypeStr == "interRank") { diff --git a/DRAMSys/traceAnalyzer/data/tracedb.h b/DRAMSys/traceAnalyzer/data/tracedb.h index 525824b8..e6450f8e 100644 --- a/DRAMSys/traceAnalyzer/data/tracedb.h +++ b/DRAMSys/traceAnalyzer/data/tracedb.h @@ -151,6 +151,9 @@ private: unsigned int getLengthOfCommandFromDB(const std::string& command); std::map> _visiblePhases; // Updated at parseTransactionsFromQuery + + // At businessObjects/phasedependenciestracker.h + friend class PhaseDependenciesTracker; }; diff --git a/DRAMSys/traceAnalyzer/tracefiletab.cpp b/DRAMSys/traceAnalyzer/tracefiletab.cpp index 8135e0f8..7f060bfb 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.cpp +++ b/DRAMSys/traceAnalyzer/tracefiletab.cpp @@ -42,6 +42,7 @@ #include "businessObjects/commentmodel.h" #include "businessObjects/configmodels.h" #include "businessObjects/pythoncaller.h" +#include "businessObjects/phasedependenciestracker.h" #include "presentation/traceselector.h" #include "qmessagebox.h" #include "queryeditor.h" @@ -303,6 +304,25 @@ void TraceFileTab::on_latencyTreeView_doubleClicked(const QModelIndex &index) } } +void TraceFileTab::on_calculateDependencies_clicked() { + // TODO - anything else? Update view maybe? + // TODO - For now fixed, but must be selectable + std::vector commands = { + "ACT", + "PRE", + "RD", + "RDA", + "WR", + "WRA", + "PDE", + "PDX", + "PREA" + }; + + PhaseDependenciesTracker::calculateDependencies(navigator->TraceFile(), commands); + +} + void TraceFileTab::on_startLatencyAnalysis_clicked() { // Setup Database: diff --git a/DRAMSys/traceAnalyzer/tracefiletab.h b/DRAMSys/traceAnalyzer/tracefiletab.h index a3dd8d43..fdd0374e 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.h +++ b/DRAMSys/traceAnalyzer/tracefiletab.h @@ -110,6 +110,7 @@ Q_SIGNALS: private Q_SLOTS: void on_latencyTreeView_doubleClicked(const QModelIndex &index); + void on_calculateDependencies_clicked(); void on_startLatencyAnalysis_clicked(); void on_startPowerAnalysis_clicked(); }; diff --git a/DRAMSys/traceAnalyzer/tracefiletab.ui b/DRAMSys/traceAnalyzer/tracefiletab.ui index 22a0a210..f2cac71d 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.ui +++ b/DRAMSys/traceAnalyzer/tracefiletab.ui @@ -208,6 +208,13 @@ Dependency Information + + + + Calculate Dependencies + + + @@ -247,6 +254,7 @@ + @@ -295,6 +303,7 @@ + true From 4219d1832dc023eafae452bd14afc6d09b3d9a85 Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Wed, 8 Dec 2021 16:56:52 +0100 Subject: [PATCH 05/14] Began adding time dependencies interface for to be generated code. --- DRAMSys/traceAnalyzer/CMakeLists.txt | 1 + .../timedependenciesIF.cpp | 85 +++++++++++++++++++ .../dramTimeDependencies/timedependenciesIF.h | 44 ++++++++++ 3 files changed, 130 insertions(+) create mode 100644 DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp create mode 100644 DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h diff --git a/DRAMSys/traceAnalyzer/CMakeLists.txt b/DRAMSys/traceAnalyzer/CMakeLists.txt index cdea25c1..ab6f8302 100644 --- a/DRAMSys/traceAnalyzer/CMakeLists.txt +++ b/DRAMSys/traceAnalyzer/CMakeLists.txt @@ -95,6 +95,7 @@ add_executable(TraceAnalyzer businessObjects/phases/phase.cpp businessObjects/phases/phasedependency.cpp businessObjects/phases/dependencyinfos.cpp + businessObjects/dramTimeDependencies/timedependenciesIF.cpp presentation/tracedrawingproperties.cpp presentation/util/traceplotline.cpp presentation/util/traceplotlinecache.cpp diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp new file mode 100644 index 00000000..89cb4052 --- /dev/null +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp @@ -0,0 +1,85 @@ + +#include "timedependenciesIF.h" + +#include + +DRAMTimeDependenciesIF::DRAMTimeDependenciesIF(const TraceDB& tdb) { + mGetMemspec(tdb); + +} + +QMap +DRAMTimeDependenciesIF::getDependencies(const std::vector& commands) const { + QMap dependenciesMap; + + dependenciesMap = mSpecializedGetDependencies(); + + mFilterDependencyMap(dependenciesMap, commands); + + auto it = dependenciesMap.begin(); + while (it != dependenciesMap.end()) { + mFilterDependencyList(it.value().dependencies, commands); + it.value().maxTime = mFindVectorMaximum(it.value().dependencies); + } + + return dependenciesMap; +} + +void DRAMTimeDependenciesIF::mGetMemspec(const TraceDB& tdb) { + QSqlDatabase db = tdb.getDatabase(); + QString query = "SELECT Memspec FROM GeneralInfo"; + QSqlQuery sqlQuery = db.exec(query); + + sqlQuery.next(); + QString memSpecJson = sqlQuery.value(0).toString(); + sqlQuery.finish(); + + QJsonDocument jsonDocument = QJsonDocument::fromJson(memSpecJson.toUtf8()); + mMemspecJson = jsonDocument.object()["memspec"].toObject(); + +} + +void DRAMTimeDependenciesIF::mFilterDependencyList(std::vector& dependencyList, const std::vector& commands) const { + std::vector newDepList(dependencyList.size()); + + std::copy_if( + dependencyList.begin(), + dependencyList.end(), + newDepList.begin(), + [ commands ](const TimeDependency& dep) { + return dep.phaseDep == "NAW" + || ( + std::find_if( + commands.begin(), + commands.end(), + [ dep ](const QString& cmd) { + return dep.phaseDep == cmd; + } + ) != commands.end() ) + ; + } + ); + + newDepList.shrink_to_fit(); + + dependencyList = newDepList; + +} + +void DRAMTimeDependenciesIF::mFilterDependencyMap(QMap& dependencyList, const std::vector& commands) const { + // TODO +} + +size_t DRAMTimeDependenciesIF::mFindVectorMaximum(const std::vector& dependencyList) const { + auto maxElement = std::max_element( + dependencyList.begin(), + dependencyList.end(), + [](const TimeDependency& dep1, const TimeDependency& dep2) { + return dep1.timeValue < dep2.timeValue; + } + ); + + if (maxElement == dependencyList.end()) return 0; + + return maxElement->timeValue; +} diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h new file mode 100644 index 00000000..7234090d --- /dev/null +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h @@ -0,0 +1,44 @@ + +#pragma once + +#include +#include +#include +#include + +#include "data/tracedb.h" +#include "businessObjects/phases/phasedependency.h" + +struct TimeDependency { + size_t timeValue; + QString phaseDep; + DependencyType depType; + QString timeDepName; +}; + +struct PhaseTimeDependencies { + QString phaseName; + std::vector dependencies; + size_t maxTime; +}; + +class DRAMTimeDependenciesIF { +public: + DRAMTimeDependenciesIF(const TraceDB& tdb); + virtual ~DRAMTimeDependenciesIF() = default; + + QMap getDependencies(const std::vector& commands) const; + +protected: + void mFilterDependencyList(std::vector& dependencyList, const std::vector& commands) const; + void mFilterDependencyMap(QMap& dependencyList, const std::vector& commands) const; + size_t mFindVectorMaximum(const std::vector& dependencyList) const; + +protected: + QJsonObject mMemspecJson; + virtual void mInitializeValues() = 0; + virtual QMap mSpecializedGetDependencies() const = 0; + +private: + void mGetMemspec(const TraceDB& tdb); +}; From 71e98adbda48004bdb5c67d55bf971bb4af8162e Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Thu, 9 Dec 2021 12:43:19 +0100 Subject: [PATCH 06/14] Finished interface class for auto-generated time dependencies code. --- .../timedependenciesIF.cpp | 88 ++++++++++++++----- .../dramTimeDependencies/timedependenciesIF.h | 15 ++-- .../phasedependenciestracker.cpp | 5 +- DRAMSys/traceAnalyzer/tracefiletab.cpp | 7 +- 4 files changed, 84 insertions(+), 31 deletions(-) diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp index 89cb4052..8f6c8c7f 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp @@ -8,18 +8,26 @@ DRAMTimeDependenciesIF::DRAMTimeDependenciesIF(const TraceDB& tdb) { } -QMap -DRAMTimeDependenciesIF::getDependencies(const std::vector& commands) const { - QMap dependenciesMap; +std::map +DRAMTimeDependenciesIF::getDependencies(std::vector& dependencyFilter) const { + std::map dependenciesMap; + + std::sort( + dependencyFilter.begin(), + dependencyFilter.end(), + [](const QString& s1, const QString& s2) { + return s1.compare(s2); + } + ); dependenciesMap = mSpecializedGetDependencies(); - mFilterDependencyMap(dependenciesMap, commands); + mFilterDependencyMap(dependenciesMap, dependencyFilter); auto it = dependenciesMap.begin(); while (it != dependenciesMap.end()) { - mFilterDependencyList(it.value().dependencies, commands); - it.value().maxTime = mFindVectorMaximum(it.value().dependencies); + mFilterDependencyList(it->second.dependencies, dependencyFilter); + it->second.maxTime = mFindVectorMaximum(it->second.dependencies); } return dependenciesMap; @@ -39,24 +47,26 @@ void DRAMTimeDependenciesIF::mGetMemspec(const TraceDB& tdb) { } -void DRAMTimeDependenciesIF::mFilterDependencyList(std::vector& dependencyList, const std::vector& commands) const { +void DRAMTimeDependenciesIF::mFilterDependencyList(std::vector& dependencyList, const std::vector& dependencyFilter) const { std::vector newDepList(dependencyList.size()); std::copy_if( dependencyList.begin(), dependencyList.end(), newDepList.begin(), - [ commands ](const TimeDependency& dep) { - return dep.phaseDep == "NAW" - || ( - std::find_if( - commands.begin(), - commands.end(), - [ dep ](const QString& cmd) { - return dep.phaseDep == cmd; - } - ) != commands.end() ) - ; + [ dependencyFilter ](const TimeDependency& dep) { + auto it = std::lower_bound( + dependencyFilter.begin(), + dependencyFilter.end(), + dep.phaseDep, + [](const QString& cmd, const QString& value) { + return value.compare(cmd); + } + ); + + if (it != dependencyFilter.end() && *it == dep.phaseDep) return true; + + return false; } ); @@ -66,8 +76,46 @@ void DRAMTimeDependenciesIF::mFilterDependencyList(std::vector& } -void DRAMTimeDependenciesIF::mFilterDependencyMap(QMap& dependencyList, const std::vector& commands) const { - // TODO +void DRAMTimeDependenciesIF::mFilterDependencyMap(std::map& dependencyMap, const std::vector& dependencyFilter) const { + if (!dependencyMap.empty()) { + + auto itFilter = dependencyFilter.begin(); + auto itFilterLast = std::lower_bound( + dependencyFilter.begin(), + dependencyFilter.end(), + dependencyMap.rbegin()->first + ); + + auto itDependencyMap = dependencyMap.begin(); + + while (true) { + + auto pair = std::mismatch( + itFilter, + itFilterLast, + itDependencyMap, + [](const QString& cmd, const std::pair& vpair) { + return cmd == vpair.first; + } + ); + + if (pair.first == dependencyFilter.end() || pair.second == dependencyMap.end()) { + dependencyMap.erase(pair.second, dependencyMap.end()); + break; + + } else if (pair.first->compare(pair.second->first) < 0) { + ++(pair.first); + + } else { + pair.second = dependencyMap.erase(pair.second); + + } + + itFilter = pair.first; + itDependencyMap = pair.second; + + } + } } size_t DRAMTimeDependenciesIF::mFindVectorMaximum(const std::vector& dependencyList) const { diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h index 7234090d..2d0c657f 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include "data/tracedb.h" @@ -27,17 +27,20 @@ public: DRAMTimeDependenciesIF(const TraceDB& tdb); virtual ~DRAMTimeDependenciesIF() = default; - QMap getDependencies(const std::vector& commands) const; + std::map getDependencies(std::vector& dependencyFilter) const; protected: - void mFilterDependencyList(std::vector& dependencyList, const std::vector& commands) const; - void mFilterDependencyMap(QMap& dependencyList, const std::vector& commands) const; + void mFilterDependencyList(std::vector& dependencyList, const std::vector& dependencyFilter) const; + void mFilterDependencyMap(std::map& dependencyMap, const std::vector& dependencyFilter) const; size_t mFindVectorMaximum(const std::vector& dependencyList) const; - + protected: QJsonObject mMemspecJson; + +// To be implemented +protected: virtual void mInitializeValues() = 0; - virtual QMap mSpecializedGetDependencies() const = 0; + virtual std::map mSpecializedGetDependencies() const = 0; private: void mGetMemspec(const TraceDB& tdb); diff --git a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp index 715eed86..667a046d 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp @@ -29,12 +29,13 @@ void PhaseDependenciesTracker::mCreateTable(TraceDB& tdb) { } void PhaseDependenciesTracker::mInsertIntoTable(TraceDB& tdb, const std::vector& entries) { + static const size_t bulkInsertionSize = 1000; + auto numberOfEntries = entries.size(); - size_t bulkInsertionSize = 1000; QString command; size_t counter = 0; - for (auto& entry : entries) { + for (const auto& entry : entries) { if (counter == 0) { // TODO Reset command string and add first command command = ""; diff --git a/DRAMSys/traceAnalyzer/tracefiletab.cpp b/DRAMSys/traceAnalyzer/tracefiletab.cpp index 7f060bfb..f25587bd 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.cpp +++ b/DRAMSys/traceAnalyzer/tracefiletab.cpp @@ -307,7 +307,7 @@ void TraceFileTab::on_latencyTreeView_doubleClicked(const QModelIndex &index) void TraceFileTab::on_calculateDependencies_clicked() { // TODO - anything else? Update view maybe? // TODO - For now fixed, but must be selectable - std::vector commands = { + std::vector dependencyFilter = { "ACT", "PRE", "RD", @@ -316,10 +316,11 @@ void TraceFileTab::on_calculateDependencies_clicked() { "WRA", "PDE", "PDX", - "PREA" + "PREA", + "NAW" }; - PhaseDependenciesTracker::calculateDependencies(navigator->TraceFile(), commands); + PhaseDependenciesTracker::calculateDependencies(navigator->TraceFile(), dependencyFilter); } From f6b84b19b994ff6705e2603afa3fa0bc361639de Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Thu, 9 Dec 2021 13:29:06 +0100 Subject: [PATCH 07/14] Added stl map QString comparator. --- .../timedependenciesIF.cpp | 22 +++++++++++-------- .../dramTimeDependencies/timedependenciesIF.h | 16 +++++++++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp index 8f6c8c7f..692c87c4 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp @@ -8,16 +8,14 @@ DRAMTimeDependenciesIF::DRAMTimeDependenciesIF(const TraceDB& tdb) { } -std::map +DependencyMap DRAMTimeDependenciesIF::getDependencies(std::vector& dependencyFilter) const { - std::map dependenciesMap; + DependencyMap dependenciesMap; std::sort( dependencyFilter.begin(), dependencyFilter.end(), - [](const QString& s1, const QString& s2) { - return s1.compare(s2); - } + QStringsComparator::compareQStrings ); dependenciesMap = mSpecializedGetDependencies(); @@ -59,9 +57,7 @@ void DRAMTimeDependenciesIF::mFilterDependencyList(std::vector& dependencyFilter.begin(), dependencyFilter.end(), dep.phaseDep, - [](const QString& cmd, const QString& value) { - return value.compare(cmd); - } + QStringsComparator::compareQStrings ); if (it != dependencyFilter.end() && *it == dep.phaseDep) return true; @@ -76,7 +72,7 @@ void DRAMTimeDependenciesIF::mFilterDependencyList(std::vector& } -void DRAMTimeDependenciesIF::mFilterDependencyMap(std::map& dependencyMap, const std::vector& dependencyFilter) const { +void DRAMTimeDependenciesIF::mFilterDependencyMap(DependencyMap& dependencyMap, const std::vector& dependencyFilter) const { if (!dependencyMap.empty()) { auto itFilter = dependencyFilter.begin(); @@ -131,3 +127,11 @@ size_t DRAMTimeDependenciesIF::mFindVectorMaximum(const std::vectortimeValue; } + +bool QStringsComparator::operator()(const QString& s1, const QString& s2) { + return s1.compare(s2) < 0; +} + +bool QStringsComparator::compareQStrings(const QString& s1, const QString& s2) { + return s1.compare(s2) < 0; +} diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h index 2d0c657f..a9bbde13 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h @@ -22,16 +22,24 @@ struct PhaseTimeDependencies { size_t maxTime; }; + +struct QStringsComparator { + bool operator()(const QString& s1, const QString& s2); + static bool compareQStrings(const QString& s1, const QString& s2); +}; + +typedef std::map DependencyMap; + class DRAMTimeDependenciesIF { public: DRAMTimeDependenciesIF(const TraceDB& tdb); virtual ~DRAMTimeDependenciesIF() = default; - std::map getDependencies(std::vector& dependencyFilter) const; + DependencyMap getDependencies(std::vector& dependencyFilter) const; protected: void mFilterDependencyList(std::vector& dependencyList, const std::vector& dependencyFilter) const; - void mFilterDependencyMap(std::map& dependencyMap, const std::vector& dependencyFilter) const; + void mFilterDependencyMap(DependencyMap& dependencyMap, const std::vector& dependencyFilter) const; size_t mFindVectorMaximum(const std::vector& dependencyList) const; protected: @@ -40,8 +48,10 @@ protected: // To be implemented protected: virtual void mInitializeValues() = 0; - virtual std::map mSpecializedGetDependencies() const = 0; + virtual DependencyMap mSpecializedGetDependencies() const = 0; private: void mGetMemspec(const TraceDB& tdb); + }; + From 5c71da1afe990342c62ac1fcdab13d3b48202694 Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Thu, 9 Dec 2021 15:50:26 +0100 Subject: [PATCH 08/14] Started adding manual code for DDR3 time dependencies. --- DRAMSys/traceAnalyzer/CMakeLists.txt | 7 +- .../DDR3TimeDependencies.cpp | 80 +++++++++++++++++++ .../DDR3TimeDependencies.h | 59 ++++++++++++++ ...nciesIF.cpp => dramtimedependenciesIF.cpp} | 21 +++-- ...endenciesIF.h => dramtimedependenciesIF.h} | 20 +++-- .../dramtimedependencyfactory.cpp | 17 ++++ .../dramtimedependencyfactory.h | 15 ++++ .../phasedependenciestracker.cpp | 6 +- .../phasedependenciestracker.h | 3 +- 9 files changed, 209 insertions(+), 19 deletions(-) create mode 100644 DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp create mode 100644 DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h rename DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/{timedependenciesIF.cpp => dramtimedependenciesIF.cpp} (85%) rename DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/{timedependenciesIF.h => dramtimedependenciesIF.h} (72%) create mode 100644 DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp create mode 100644 DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.h diff --git a/DRAMSys/traceAnalyzer/CMakeLists.txt b/DRAMSys/traceAnalyzer/CMakeLists.txt index ab6f8302..7b84d13f 100644 --- a/DRAMSys/traceAnalyzer/CMakeLists.txt +++ b/DRAMSys/traceAnalyzer/CMakeLists.txt @@ -91,11 +91,9 @@ add_executable(TraceAnalyzer businessObjects/pythoncaller.cpp businessObjects/tracetestresults.cpp presentation/tracemetrictreewidget.cpp - businessObjects/phasedependenciestracker.cpp businessObjects/phases/phase.cpp businessObjects/phases/phasedependency.cpp businessObjects/phases/dependencyinfos.cpp - businessObjects/dramTimeDependencies/timedependenciesIF.cpp presentation/tracedrawingproperties.cpp presentation/util/traceplotline.cpp presentation/util/traceplotlinecache.cpp @@ -104,6 +102,11 @@ add_executable(TraceAnalyzer businessObjects/configmodels.cpp businessObjects/commentmodel.cpp + businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp + businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp + businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp + businessObjects/phasedependenciestracker.cpp + selectmetrics.ui preferences.ui evaluationtool.ui diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp new file mode 100644 index 00000000..e1e375cf --- /dev/null +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp @@ -0,0 +1,80 @@ + +#include "DDR3TimeDependencies.h" + +DDR3TimeDependencies::DDR3TimeDependencies(const QJsonObject& memspec) : DRAMTimeDependenciesIF(memspec) { + mInitializeValues(); +} + +void DDR3TimeDependencies::mInitializeValues() { + burstLength = mMemspecJson["memarchitecturespec"].toObject()["burstLength"].toString().toLongLong(); + dataRate = mMemspecJson["memarchitecturespec"].toObject()["dataRate"].toString().toLongLong(); + clk = mMemspecJson["memarchitecturespec"].toArray()[0].toString().toLongLong(); + + nActivateWindow = 4; + + tRP = mMemspecJson["memtimingspec"].toObject()["RP"].toString().toLongLong(); + tRAS = mMemspecJson["memtimingspec"].toObject()["RAS"].toString().toLongLong(); + tRC = mMemspecJson["memtimingspec"].toObject()["RC"].toString().toLongLong(); + tRTP = mMemspecJson["memtimingspec"].toObject()["RTP"].toString().toLongLong(); + tRRD = mMemspecJson["memtimingspec"].toObject()["RRD"].toString().toLongLong(); + tCCD = mMemspecJson["memtimingspec"].toObject()["CCD"].toString().toLongLong(); + tRCD = mMemspecJson["memtimingspec"].toObject()["RCD"].toString().toLongLong(); + tNAW = mMemspecJson["memtimingspec"].toObject()["NAW"].toString().toLongLong(); + tRL = mMemspecJson["memtimingspec"].toObject()["RL"].toString().toLongLong(); + tWL = mMemspecJson["memtimingspec"].toObject()["WL"].toString().toLongLong(); + tWR = mMemspecJson["memtimingspec"].toObject()["WR"].toString().toLongLong(); + tWTR = mMemspecJson["memtimingspec"].toObject()["WTR"].toString().toLongLong(); + tCKESR = mMemspecJson["memtimingspec"].toObject()["CKESR"].toString().toLongLong(); + tCKE = mMemspecJson["memtimingspec"].toObject()["CKE"].toString().toLongLong(); + tXP = mMemspecJson["memtimingspec"].toObject()["XP"].toString().toLongLong(); + tXPDLL = mMemspecJson["memtimingspec"].toObject()["XPDLL"].toString().toLongLong(); + tXS = mMemspecJson["memtimingspec"].toObject()["XS"].toString().toLongLong(); + tXSDLL = mMemspecJson["memtimingspec"].toObject()["XSDLL"].toString().toLongLong(); + tAL = mMemspecJson["memtimingspec"].toObject()["AL"].toString().toLongLong(); + tRFC = mMemspecJson["memtimingspec"].toObject()["RFC"].toString().toLongLong(); + tREFI = mMemspecJson["memtimingspec"].toObject()["REFI"].toString().toLongLong(); + tRTRS = mMemspecJson["memtimingspec"].toObject()["RTRS"].toString().toLongLong(); + tACTPDEN = mMemspecJson["memtimingspec"].toObject()["ACTPDEN"].toString().toLongLong(); + tPRPDEN = mMemspecJson["memtimingspec"].toObject()["PRPDEN"].toString().toLongLong(); + tREFPDEN = mMemspecJson["memtimingspec"].toObject()["REFPDEN"].toString().toLongLong(); + tCKE = mMemspecJson["memtimingspec"].toObject()["CKE"].toString().toLongLong(); + + tPD = tCKE; + tBURST = (int) ((burstLength / dataRate) * clk); + tRDWR = tRL + tBURST + 2 * clk - tWL; + tRDWR_R = tRL + tBURST + tRTRS - tWL; + tWRRD = tWL + tBURST + tWTR; + tWRRD_R = tWL + tBURST + tRTRS - tRL; + tWRPRE = tWL + tBURST + tWR; + tRDPDEN = tRL + tBURST + clk; + tWRPDEN = tWL + tBURST + tWR; + tWRAPDEN = tWL + tBURST + tWR + clk; +} + +DependencyMap DDR3TimeDependencies::mSpecializedGetDependencies() const { + DependencyMap dmap; + + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("ACT"), + std::forward_as_tuple( + std::initializer_list{ + TimeDependency{tRC, "ACT", DependencyType::IntraBank, "tRC"}, + TimeDependency{tAL + tRTP + tRP, "RDA", DependencyType::IntraBank, "tAL + tRTP + tRP"}, + TimeDependency{tWRPRE + tRP, "WRA", DependencyType::IntraBank, "tWRPRE + tRP"}, + TimeDependency{tRP, "PRE", DependencyType::IntraBank, "tRP"}, + TimeDependency{tRRD, "ACT", DependencyType::IntraRank, "tRRD"}, + TimeDependency{tRP, "PREA", DependencyType::IntraRank, "tRP"}, + TimeDependency{tXP, "PDXA", DependencyType::IntraRank, "tXP"}, + TimeDependency{tXP, "PDXP", DependencyType::IntraRank, "tXP"}, + TimeDependency{tRFC, "REFA", DependencyType::IntraRank, "tRFC"}, + TimeDependency{tXS, "SREFEX", DependencyType::IntraRank, "tXS"}, + TimeDependency{tNAW, "NAW", DependencyType::IntraRank, "tNAW"} + } + ) + ); + + // TODO add all the rest + + return dmap; +} \ No newline at end of file diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h new file mode 100644 index 00000000..793b50f1 --- /dev/null +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h @@ -0,0 +1,59 @@ + +#pragma once + +#include "dramtimedependenciesIF.h" + +class DDR3TimeDependencies : public DRAMTimeDependenciesIF { +public: + DDR3TimeDependencies(const QJsonObject& memspec); + +protected: + void mInitializeValues() override; + DependencyMap mSpecializedGetDependencies() const override; + +protected: + size_t burstLength; + size_t dataRate; + size_t clk; + + size_t nActivateWindow; + + size_t tRP; + size_t tRAS; + size_t tRC; + size_t tRTP; + size_t tRRD; + size_t tCCD; + size_t tRCD; + size_t tNAW; + size_t tRL; + size_t tWL; + size_t tWR; + size_t tWTR; + size_t tCKESR; + size_t tCKE; + size_t tXP; + size_t tXPDLL; + size_t tXS; + size_t tXSDLL; + size_t tAL; + size_t tRFC; + size_t tREFI; + size_t tRTRS; + + size_t tACTPDEN; + size_t tPRPDEN; + size_t tREFPDEN; + + size_t tPD; + size_t tBURST; + size_t tRDWR; + size_t tRDWR_R; + size_t tWRRD; + size_t tWRRD_R; + size_t tWRPRE; + size_t tRDPDEN; + size_t tWRPDEN; + size_t tWRAPDEN; + +}; diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp similarity index 85% rename from DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp rename to DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp index 692c87c4..c740a801 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp @@ -1,10 +1,10 @@ -#include "timedependenciesIF.h" +#include "dramtimedependenciesIF.h" #include -DRAMTimeDependenciesIF::DRAMTimeDependenciesIF(const TraceDB& tdb) { - mGetMemspec(tdb); +DRAMTimeDependenciesIF::DRAMTimeDependenciesIF(const QJsonObject& memspec) { + mMemspecJson = memspec; } @@ -31,7 +31,7 @@ DRAMTimeDependenciesIF::getDependencies(std::vector& dependencyFilter) return dependenciesMap; } -void DRAMTimeDependenciesIF::mGetMemspec(const TraceDB& tdb) { +const QJsonObject DRAMTimeDependenciesIF::getMemspec(const TraceDB& tdb) { QSqlDatabase db = tdb.getDatabase(); QString query = "SELECT Memspec FROM GeneralInfo"; QSqlQuery sqlQuery = db.exec(query); @@ -41,13 +41,16 @@ void DRAMTimeDependenciesIF::mGetMemspec(const TraceDB& tdb) { sqlQuery.finish(); QJsonDocument jsonDocument = QJsonDocument::fromJson(memSpecJson.toUtf8()); - mMemspecJson = jsonDocument.object()["memspec"].toObject(); + return jsonDocument.object()["memspec"].toObject(); } void DRAMTimeDependenciesIF::mFilterDependencyList(std::vector& dependencyList, const std::vector& dependencyFilter) const { std::vector newDepList(dependencyList.size()); + // TODO - probably there is a smarter way to filter these values, + // although the lists are not to be greater than 20-50 elements + std::copy_if( dependencyList.begin(), dependencyList.end(), @@ -70,6 +73,14 @@ void DRAMTimeDependenciesIF::mFilterDependencyList(std::vector& dependencyList = newDepList; + std::sort( + dependencyList.begin(), + dependencyList.end(), + [](const TimeDependency& v1, const TimeDependency& v2) { + return v1.timeValue < v2.timeValue; + } + ); + } void DRAMTimeDependenciesIF::mFilterDependencyMap(DependencyMap& dependencyMap, const std::vector& dependencyFilter) const { diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.h similarity index 72% rename from DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h rename to DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.h index a9bbde13..7071ef84 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/timedependenciesIF.h +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.h @@ -4,6 +4,10 @@ #include #include #include + +#include +#include +#include #include #include "data/tracedb.h" @@ -17,7 +21,8 @@ struct TimeDependency { }; struct PhaseTimeDependencies { - QString phaseName; + explicit PhaseTimeDependencies(std::initializer_list d) : dependencies(d) {} + std::vector dependencies; size_t maxTime; }; @@ -32,11 +37,13 @@ typedef std::map DependencyM class DRAMTimeDependenciesIF { public: - DRAMTimeDependenciesIF(const TraceDB& tdb); + DRAMTimeDependenciesIF(const QJsonObject& memspec); virtual ~DRAMTimeDependenciesIF() = default; DependencyMap getDependencies(std::vector& dependencyFilter) const; + static const QJsonObject getMemspec(const TraceDB& tdb); + protected: void mFilterDependencyList(std::vector& dependencyList, const std::vector& dependencyFilter) const; void mFilterDependencyMap(DependencyMap& dependencyMap, const std::vector& dependencyFilter) const; @@ -45,13 +52,10 @@ protected: protected: QJsonObject mMemspecJson; -// To be implemented +// To be implemented by the specializing class protected: - virtual void mInitializeValues() = 0; - virtual DependencyMap mSpecializedGetDependencies() const = 0; - -private: - void mGetMemspec(const TraceDB& tdb); + virtual void mInitializeValues() {} ; + virtual DependencyMap mSpecializedGetDependencies() const { DependencyMap map; return map; } ; }; diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp new file mode 100644 index 00000000..f9c72c91 --- /dev/null +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp @@ -0,0 +1,17 @@ + +#include "dramtimedependencyfactory.h" + +DRAMTimeDependenciesIF DRAMTimeDependencyFactory::make(const TraceDB& tdb) { + const QJsonObject& memspec = DRAMTimeDependenciesIF::getMemspec(tdb); + QString deviceType = memspec["memspec"]["memoryType"].toString(); + + if (deviceType == "DDR3") { + return DDR3TimeDependencies(memspec); + + } else { + // TODO maybe throw? + return DRAMTimeDependenciesIF(memspec); + + } + +} diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.h new file mode 100644 index 00000000..d6232ffe --- /dev/null +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.h @@ -0,0 +1,15 @@ + +#pragma once + +#include "dramtimedependenciesIF.h" +#include "DDR3TimeDependencies.h" +#include "data/tracedb.h" + +class DRAMTimeDependencyFactory { +public: + static DRAMTimeDependenciesIF make(const TraceDB& tdb); + +private: + DRAMTimeDependencyFactory() = delete; + ~DRAMTimeDependencyFactory() = delete; +}; diff --git a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp index 667a046d..984a8886 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp @@ -8,7 +8,7 @@ PhaseDependenciesTracker::calculateDependencies(TraceDB& tdb, const std::vector< auto& phases = mGetAllPhases(tdb, commands); - auto& entries = mCalculateDependencies(phases); + auto& entries = mCalculateDependencies(tdb, phases); mInsertIntoTable(tdb, entries); @@ -117,10 +117,10 @@ PhaseDependenciesTracker::mGetAllPhases(TraceDB& tdb, const std::vector -PhaseDependenciesTracker::mCalculateDependencies(const std::vector>& transactions) { +PhaseDependenciesTracker::mCalculateDependencies(const TraceDB& tdb, const std::vector>& transactions) { std::vector entries; - // TODO Get dependency object for specific trace + DRAMTimeDependenciesIF deviceDependencies = DRAMTimeDependencyFactory::make(tdb); // TODO Main dependency calculation loop return entries; diff --git a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h index fcfe7021..a46d6c05 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h +++ b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h @@ -6,6 +6,7 @@ #include #include "data/tracedb.h" +#include "dramTimeDependencies/dramtimedependencyfactory.h" struct DBPhaseEntry { size_t id; @@ -36,7 +37,7 @@ private: static void mInsertIntoTable(TraceDB& tdb, const std::vector& entries); static const std::vector> mGetAllPhases(TraceDB& tdb, const std::vector& commands); - static const std::vector mCalculateDependencies(const std::vector>& phases); + static const std::vector mCalculateDependencies(const TraceDB& tdb, const std::vector>& phases); static QSqlQuery mExecuteQuery(TraceDB& tdb, const QString queryStr); From 866d1f476511a2d7c83e47e21775426dfe1605a6 Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Fri, 10 Dec 2021 11:07:21 +0100 Subject: [PATCH 09/14] Added DDR3 time dependencies code manually. --- .../DDR3TimeDependencies.cpp | 210 ++++++++++++++++-- 1 file changed, 197 insertions(+), 13 deletions(-) diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp index e1e375cf..237939d3 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp @@ -59,22 +59,206 @@ DependencyMap DDR3TimeDependencies::mSpecializedGetDependencies() const { std::forward_as_tuple("ACT"), std::forward_as_tuple( std::initializer_list{ - TimeDependency{tRC, "ACT", DependencyType::IntraBank, "tRC"}, - TimeDependency{tAL + tRTP + tRP, "RDA", DependencyType::IntraBank, "tAL + tRTP + tRP"}, - TimeDependency{tWRPRE + tRP, "WRA", DependencyType::IntraBank, "tWRPRE + tRP"}, - TimeDependency{tRP, "PRE", DependencyType::IntraBank, "tRP"}, - TimeDependency{tRRD, "ACT", DependencyType::IntraRank, "tRRD"}, - TimeDependency{tRP, "PREA", DependencyType::IntraRank, "tRP"}, - TimeDependency{tXP, "PDXA", DependencyType::IntraRank, "tXP"}, - TimeDependency{tXP, "PDXP", DependencyType::IntraRank, "tXP"}, - TimeDependency{tRFC, "REFA", DependencyType::IntraRank, "tRFC"}, - TimeDependency{tXS, "SREFEX", DependencyType::IntraRank, "tXS"}, - TimeDependency{tNAW, "NAW", DependencyType::IntraRank, "tNAW"} + {tRC, "ACT", DependencyType::IntraBank, "tRC"}, + {tAL + tRTP + tRP, "RDA", DependencyType::IntraBank, "tAL + tRTP + tRP"}, + {tWRPRE + tRP, "WRA", DependencyType::IntraBank, "tWRPRE + tRP"}, + {tRP, "PREPB", DependencyType::IntraBank, "tRP"}, + {tRRD, "ACT", DependencyType::IntraRank, "tRRD"}, + {tRP, "PREAB", DependencyType::IntraRank, "tRP"}, + {tXP, "PDXA", DependencyType::IntraRank, "tXP"}, + {tXP, "PDXP", DependencyType::IntraRank, "tXP"}, + {tRFC, "REFAB", DependencyType::IntraRank, "tRFC"}, + {tXS, "SREFEX", DependencyType::IntraRank, "tXS"}, + {tNAW, "NAW", DependencyType::IntraRank, "tNAW"} } ) ); - // TODO add all the rest + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("RD"), + std::forward_as_tuple( + std::initializer_list{ + {tRCD - tAL, "ACT", DependencyType::IntraBank, "tRCD - tAL"}, + {tCCD, "RD", DependencyType::IntraRank, "tCCD"}, + {tCCD, "RDA", DependencyType::IntraRank, "tCCD"}, + {tWRRD, "WR", DependencyType::IntraRank, "tWRRD"}, + {tWRRD, "WRA", DependencyType::IntraRank, "tWRRD"}, + {tXP, "PDXA", DependencyType::IntraRank, "tXP"}, + {tXSDLL, "SREFEX", DependencyType::IntraRank, "tXSDLL"}, + {tBURST + tRTRS, "RD", DependencyType::InterRank, "tBURST + tRTRS"}, + {tBURST + tRTRS, "RDA", DependencyType::InterRank, "tBURST + tRTRS"}, + {tWRRD_R, "WR", DependencyType::InterRank, "tWRRD_R"}, + {tWRRD_R, "WRA", DependencyType::InterRank, "tWRRD_R"} + } + ) + ); + + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("RDA"), + std::forward_as_tuple( + std::initializer_list{ + {tRCD - tAL, "ACT", DependencyType::IntraBank, "tRCD - tAL"}, + {tWRPRE - tRTP, "WR", DependencyType::IntraBank, "tWRPRE - tRTP"}, + {tCCD, "RD", DependencyType::IntraRank, "tCCD"}, + {tCCD, "RDA", DependencyType::IntraRank, "tCCD"}, + {tWRRD, "WR", DependencyType::IntraRank, "tWRRD"}, + {tWRRD, "WRA", DependencyType::IntraRank, "tWRRD"}, + {tXP, "PDXA", DependencyType::IntraRank, "tXP"}, + {tXSDLL, "SREFEX", DependencyType::IntraRank, "tXSDLL"}, + {tBURST + tRTRS, "RD", DependencyType::InterRank, "tBURST + tRTRS"}, + {tBURST + tRTRS, "RDA", DependencyType::InterRank, "tBURST + tRTRS"}, + {tWRRD_R, "WR", DependencyType::InterRank, "tWRRD_R"}, + {tWRRD_R, "WRA", DependencyType::InterRank, "tWRRD_R"} + } + ) + ); + + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("WR"), + std::forward_as_tuple( + std::initializer_list{ + {tRCD - tAL, "ACT", DependencyType::IntraBank, "tRCD - tAL"}, + {tRDWR, "RD", DependencyType::IntraRank, "tRDWR"}, + {tRDWR, "RDA", DependencyType::IntraRank, "tRDWR"}, + {tCCD, "WR", DependencyType::IntraRank, "tCCD"}, + {tCCD, "WRA", DependencyType::IntraRank, "tCCD"}, + {tXP, "PDXA", DependencyType::IntraRank, "tXP"}, + {tXSDLL, "SREFEX", DependencyType::IntraRank, "tXSDLL"}, + {tRDWR_R, "RD", DependencyType::InterRank, "tRDWR_R"}, + {tRDWR_R, "RDA", DependencyType::InterRank, "tRDWR_R"}, + {tBURST + tRTRS, "WR", DependencyType::InterRank, "tBURST + tRTRS"}, + {tBURST + tRTRS, "WRA", DependencyType::InterRank, "tBURST + tRTRS"} + } + ) + ); + + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("PREPB"), + std::forward_as_tuple( + std::initializer_list{ + {tRAS, "ACT", DependencyType::IntraBank, "tRAS"}, + {tAL + tRTP, "RD", DependencyType::IntraBank, "tAL + tRTP"}, + {tWRPRE, "WR", DependencyType::IntraBank, "tWRPRE"}, + {tXP, "PDXA", DependencyType::IntraRank, "tXP"} + } + ) + ); + + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("PREAB"), + std::forward_as_tuple( + std::initializer_list{ + {tRAS, "ACT", DependencyType::IntraRank, "tRAS"}, + {tAL + tRTP, "RD", DependencyType::IntraRank, "tAL + tRTP"}, + {tAL + tRTP, "RDA", DependencyType::IntraRank, "tAL + tRTP"}, + {tWRPRE, "WR", DependencyType::IntraRank, "tWRPRE"}, + {tWRPRE, "WRA", DependencyType::IntraRank, "tWRPRE"}, + {tXP, "PDXA", DependencyType::IntraRank, "tXP"} + } + ) + ); + + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("REFAB"), + std::forward_as_tuple( + std::initializer_list{ + {tRC, "ACT", DependencyType::IntraRank, "tRC"}, + {tAL + tRTP + tRP, "RDA", DependencyType::IntraRank, "tAL + tRTP + tRP"}, + {tWRPRE + tRP, "WRA", DependencyType::IntraRank, "tWRPRE + tRP"}, + {tRP, "PREPB", DependencyType::IntraRank, "tRP"}, + {tRP, "PREAB", DependencyType::IntraRank, "tRP"}, + {tXP, "PDXP", DependencyType::IntraRank, "tXP"}, + {tRFC, "REFAB", DependencyType::IntraRank, "tRFC"}, + {tXS, "SREFEX", DependencyType::IntraRank, "tXS"} + } + ) + ); + + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("REFAB"), + std::forward_as_tuple( + std::initializer_list{ + {tACTPDEN, "ACT", DependencyType::IntraRank, "tACTPDEN"}, + {tRDPDEN, "RD", DependencyType::IntraRank, "tRDPDEN"}, + {tRDPDEN, "RDA", DependencyType::IntraRank, "tRDPDEN"}, + {tWRPDEN, "WR", DependencyType::IntraRank, "tWRPDEN"}, + {tWRAPDEN, "WRA", DependencyType::IntraRank, "tWRAPDEN"}, + {tPRPDEN, "PREPB", DependencyType::IntraRank, "tPRPDEN"}, + {tCKE, "PDXA", DependencyType::IntraRank, "tCKE"} + } + ) + ); + + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("PDXA"), + std::forward_as_tuple( + std::initializer_list{ + {tPD, "PDEA", DependencyType::IntraRank, "tPD"} + } + ) + ); + + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("PDEP"), + std::forward_as_tuple( + std::initializer_list{ + {tRDPDEN, "RD", DependencyType::IntraRank, "tRDPDEN"}, + {tRDPDEN, "RDA", DependencyType::IntraRank, "tRDPDEN"}, + {tWRAPDEN, "WRA", DependencyType::IntraRank, "tWRAPDEN"}, + {tPRPDEN, "PREPB", DependencyType::IntraRank, "tPRPDEN"}, + {tPRPDEN, "PREAB", DependencyType::IntraRank, "tPRPDEN"}, + {tCKE, "PDXP", DependencyType::IntraRank, "tCKE"}, + {tREFPDEN, "REFAB", DependencyType::IntraRank, "tREFPDEN"}, + {tXS, "SREFEX", DependencyType::IntraRank, "tXS"} + } + ) + ); + + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("PDXP"), + std::forward_as_tuple( + std::initializer_list{ + {tPD, "PDEP", DependencyType::IntraRank, "tPD"} + } + ) + ); + + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("SREFEN"), + std::forward_as_tuple( + std::initializer_list{ + {tRC, "ACT", DependencyType::IntraRank, "tRC"}, + {std::max({tRDPDEN, tAL + tRTP + tRP}), "RDA", DependencyType::IntraRank, "max(tRDPDEN, tAL + tRTP + tRP)"}, + {std::max({tWRAPDEN, tWRPRE + tRP}), "WRA", DependencyType::IntraRank, "max(tWRAPDEN, tWRPRE + tRP)"}, + {tRP, "PREPB", DependencyType::IntraRank, "tRP"}, + {tRP, "PREAB", DependencyType::IntraRank, "tRP"}, + {tXP, "PDXP", DependencyType::IntraRank, "tXP"}, + {tRFC, "REFAB", DependencyType::IntraRank, "tRFC"}, + {tXS, "SREFEX", DependencyType::IntraRank, "tXS"} + } + ) + ); + + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("SREFEX"), + std::forward_as_tuple( + std::initializer_list{ + {tCKESR, "SREFEN", DependencyType::IntraRank, "tCKESR"} + } + ) + ); return dmap; -} \ No newline at end of file +} From 8bf98ac051dad295994f6f727696aa4ec760e8ca Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Fri, 10 Dec 2021 15:14:39 +0100 Subject: [PATCH 10/14] Added main calculation loop and other modifications and corrections. Still missing table data storing and test. --- .../DDR3TimeDependencies.cpp | 83 ++++++++----- .../DDR3TimeDependencies.h | 79 ++++++------- .../dramtimedependenciesIF.cpp | 14 ++- .../dramtimedependenciesIF.h | 9 +- .../dramtimedependencyfactory.cpp | 8 +- .../dramtimedependencyfactory.h | 4 +- .../phasedependenciestracker.cpp | 109 ++++++++++++++++-- .../phasedependenciestracker.h | 6 +- .../phases/phasedependency.cpp | 20 +++- .../businessObjects/phases/phasedependency.h | 2 + DRAMSys/traceAnalyzer/tracefiletab.cpp | 7 +- 11 files changed, 244 insertions(+), 97 deletions(-) diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp index 237939d3..5b494732 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp @@ -6,41 +6,41 @@ DDR3TimeDependencies::DDR3TimeDependencies(const QJsonObject& memspec) : DRAMTim } void DDR3TimeDependencies::mInitializeValues() { - burstLength = mMemspecJson["memarchitecturespec"].toObject()["burstLength"].toString().toLongLong(); - dataRate = mMemspecJson["memarchitecturespec"].toObject()["dataRate"].toString().toLongLong(); - clk = mMemspecJson["memarchitecturespec"].toArray()[0].toString().toLongLong(); + burstLength = mMemspecJson["memarchitecturespec"].toObject()["burstLength"].toString().toInt(); + dataRate = mMemspecJson["memarchitecturespec"].toObject()["dataRate"].toString().toInt(); + clk = mMemspecJson["memarchitecturespec"].toArray()[0].toString().toInt(); nActivateWindow = 4; - tRP = mMemspecJson["memtimingspec"].toObject()["RP"].toString().toLongLong(); - tRAS = mMemspecJson["memtimingspec"].toObject()["RAS"].toString().toLongLong(); - tRC = mMemspecJson["memtimingspec"].toObject()["RC"].toString().toLongLong(); - tRTP = mMemspecJson["memtimingspec"].toObject()["RTP"].toString().toLongLong(); - tRRD = mMemspecJson["memtimingspec"].toObject()["RRD"].toString().toLongLong(); - tCCD = mMemspecJson["memtimingspec"].toObject()["CCD"].toString().toLongLong(); - tRCD = mMemspecJson["memtimingspec"].toObject()["RCD"].toString().toLongLong(); - tNAW = mMemspecJson["memtimingspec"].toObject()["NAW"].toString().toLongLong(); - tRL = mMemspecJson["memtimingspec"].toObject()["RL"].toString().toLongLong(); - tWL = mMemspecJson["memtimingspec"].toObject()["WL"].toString().toLongLong(); - tWR = mMemspecJson["memtimingspec"].toObject()["WR"].toString().toLongLong(); - tWTR = mMemspecJson["memtimingspec"].toObject()["WTR"].toString().toLongLong(); - tCKESR = mMemspecJson["memtimingspec"].toObject()["CKESR"].toString().toLongLong(); - tCKE = mMemspecJson["memtimingspec"].toObject()["CKE"].toString().toLongLong(); - tXP = mMemspecJson["memtimingspec"].toObject()["XP"].toString().toLongLong(); - tXPDLL = mMemspecJson["memtimingspec"].toObject()["XPDLL"].toString().toLongLong(); - tXS = mMemspecJson["memtimingspec"].toObject()["XS"].toString().toLongLong(); - tXSDLL = mMemspecJson["memtimingspec"].toObject()["XSDLL"].toString().toLongLong(); - tAL = mMemspecJson["memtimingspec"].toObject()["AL"].toString().toLongLong(); - tRFC = mMemspecJson["memtimingspec"].toObject()["RFC"].toString().toLongLong(); - tREFI = mMemspecJson["memtimingspec"].toObject()["REFI"].toString().toLongLong(); - tRTRS = mMemspecJson["memtimingspec"].toObject()["RTRS"].toString().toLongLong(); - tACTPDEN = mMemspecJson["memtimingspec"].toObject()["ACTPDEN"].toString().toLongLong(); - tPRPDEN = mMemspecJson["memtimingspec"].toObject()["PRPDEN"].toString().toLongLong(); - tREFPDEN = mMemspecJson["memtimingspec"].toObject()["REFPDEN"].toString().toLongLong(); - tCKE = mMemspecJson["memtimingspec"].toObject()["CKE"].toString().toLongLong(); + tRP = mMemspecJson["memtimingspec"].toObject()["RP"].toString().toInt(); + tRAS = mMemspecJson["memtimingspec"].toObject()["RAS"].toString().toInt(); + tRC = mMemspecJson["memtimingspec"].toObject()["RC"].toString().toInt(); + tRTP = mMemspecJson["memtimingspec"].toObject()["RTP"].toString().toInt(); + tRRD = mMemspecJson["memtimingspec"].toObject()["RRD"].toString().toInt(); + tCCD = mMemspecJson["memtimingspec"].toObject()["CCD"].toString().toInt(); + tRCD = mMemspecJson["memtimingspec"].toObject()["RCD"].toString().toInt(); + tNAW = mMemspecJson["memtimingspec"].toObject()["NAW"].toString().toInt(); + tRL = mMemspecJson["memtimingspec"].toObject()["RL"].toString().toInt(); + tWL = mMemspecJson["memtimingspec"].toObject()["WL"].toString().toInt(); + tWR = mMemspecJson["memtimingspec"].toObject()["WR"].toString().toInt(); + tWTR = mMemspecJson["memtimingspec"].toObject()["WTR"].toString().toInt(); + tCKESR = mMemspecJson["memtimingspec"].toObject()["CKESR"].toString().toInt(); + tCKE = mMemspecJson["memtimingspec"].toObject()["CKE"].toString().toInt(); + tXP = mMemspecJson["memtimingspec"].toObject()["XP"].toString().toInt(); + tXPDLL = mMemspecJson["memtimingspec"].toObject()["XPDLL"].toString().toInt(); + tXS = mMemspecJson["memtimingspec"].toObject()["XS"].toString().toInt(); + tXSDLL = mMemspecJson["memtimingspec"].toObject()["XSDLL"].toString().toInt(); + tAL = mMemspecJson["memtimingspec"].toObject()["AL"].toString().toInt(); + tRFC = mMemspecJson["memtimingspec"].toObject()["RFC"].toString().toInt(); + tREFI = mMemspecJson["memtimingspec"].toObject()["REFI"].toString().toInt(); + tRTRS = mMemspecJson["memtimingspec"].toObject()["RTRS"].toString().toInt(); + tACTPDEN = mMemspecJson["memtimingspec"].toObject()["ACTPDEN"].toString().toInt(); + tPRPDEN = mMemspecJson["memtimingspec"].toObject()["PRPDEN"].toString().toInt(); + tREFPDEN = mMemspecJson["memtimingspec"].toObject()["REFPDEN"].toString().toInt(); + tCKE = mMemspecJson["memtimingspec"].toObject()["CKE"].toString().toInt(); tPD = tCKE; - tBURST = (int) ((burstLength / dataRate) * clk); + tBURST = (uint) ((burstLength / (float) dataRate) * clk); tRDWR = tRL + tBURST + 2 * clk - tWL; tRDWR_R = tRL + tBURST + tRTRS - tWL; tWRRD = tWL + tBURST + tWTR; @@ -49,6 +49,7 @@ void DDR3TimeDependencies::mInitializeValues() { tRDPDEN = tRL + tBURST + clk; tWRPDEN = tWL + tBURST + tWR; tWRAPDEN = tWL + tBURST + tWR + clk; + } DependencyMap DDR3TimeDependencies::mSpecializedGetDependencies() const { @@ -135,6 +136,26 @@ DependencyMap DDR3TimeDependencies::mSpecializedGetDependencies() const { ) ); + dmap.emplace( + std::piecewise_construct, + std::forward_as_tuple("WRA"), + std::forward_as_tuple( + std::initializer_list{ + {tRCD - tAL, "ACT", DependencyType::IntraBank, "tRCD - tAL"}, + {tRDWR, "RD", DependencyType::IntraRank, "tRDWR"}, + {tRDWR, "RDA", DependencyType::IntraRank, "tRDWR"}, + {tCCD, "WR", DependencyType::IntraRank, "tCCD"}, + {tCCD, "WRA", DependencyType::IntraRank, "tCCD"}, + {tXP, "PDXA", DependencyType::IntraRank, "tXP"}, + {tXSDLL, "SREFEX", DependencyType::IntraRank, "tXSDLL"}, + {tRDWR_R, "RD", DependencyType::InterRank, "tRDWR_R"}, + {tRDWR_R, "RDA", DependencyType::InterRank, "tRDWR_R"}, + {tBURST + tRTRS, "WR", DependencyType::InterRank, "tBURST + tRTRS"}, + {tBURST + tRTRS, "WRA", DependencyType::InterRank, "tBURST + tRTRS"} + } + ) + ); + dmap.emplace( std::piecewise_construct, std::forward_as_tuple("PREPB"), @@ -182,7 +203,7 @@ DependencyMap DDR3TimeDependencies::mSpecializedGetDependencies() const { dmap.emplace( std::piecewise_construct, - std::forward_as_tuple("REFAB"), + std::forward_as_tuple("PDEA"), std::forward_as_tuple( std::initializer_list{ {tACTPDEN, "ACT", DependencyType::IntraRank, "tACTPDEN"}, diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h index 793b50f1..53568c34 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h @@ -10,50 +10,47 @@ public: protected: void mInitializeValues() override; DependencyMap mSpecializedGetDependencies() const override; - + protected: - size_t burstLength; - size_t dataRate; - size_t clk; + uint burstLength; + uint dataRate; - size_t nActivateWindow; + uint tRP; + uint tRAS; + uint tRC; + uint tRTP; + uint tRRD; + uint tCCD; + uint tRCD; + uint tNAW; + uint tRL; + uint tWL; + uint tWR; + uint tWTR; + uint tCKESR; + uint tCKE; + uint tXP; + uint tXPDLL; + uint tXS; + uint tXSDLL; + uint tAL; + uint tRFC; + uint tREFI; + uint tRTRS; - size_t tRP; - size_t tRAS; - size_t tRC; - size_t tRTP; - size_t tRRD; - size_t tCCD; - size_t tRCD; - size_t tNAW; - size_t tRL; - size_t tWL; - size_t tWR; - size_t tWTR; - size_t tCKESR; - size_t tCKE; - size_t tXP; - size_t tXPDLL; - size_t tXS; - size_t tXSDLL; - size_t tAL; - size_t tRFC; - size_t tREFI; - size_t tRTRS; + uint tACTPDEN; + uint tPRPDEN; + uint tREFPDEN; - size_t tACTPDEN; - size_t tPRPDEN; - size_t tREFPDEN; - - size_t tPD; - size_t tBURST; - size_t tRDWR; - size_t tRDWR_R; - size_t tWRRD; - size_t tWRRD_R; - size_t tWRPRE; - size_t tRDPDEN; - size_t tWRPDEN; - size_t tWRAPDEN; + uint tPD; + uint tBURST; + uint tRDWR; + uint tRDWR_R; + uint tWRRD; + uint tWRRD_R; + uint tWRPRE; + uint tRDPDEN; + uint tWRPDEN; + uint tWRAPDEN; }; diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp index c740a801..0960d646 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp @@ -26,8 +26,11 @@ DRAMTimeDependenciesIF::getDependencies(std::vector& dependencyFilter) while (it != dependenciesMap.end()) { mFilterDependencyList(it->second.dependencies, dependencyFilter); it->second.maxTime = mFindVectorMaximum(it->second.dependencies); + + ++it; } + return dependenciesMap; } @@ -60,7 +63,9 @@ void DRAMTimeDependenciesIF::mFilterDependencyList(std::vector& dependencyFilter.begin(), dependencyFilter.end(), dep.phaseDep, - QStringsComparator::compareQStrings + [](const QString& cmd, const QString& depName){ + return cmd == "NAW" || QStringsComparator::compareQStrings(cmd, depName); + } ); if (it != dependencyFilter.end() && *it == dep.phaseDep) return true; @@ -102,7 +107,7 @@ void DRAMTimeDependenciesIF::mFilterDependencyMap(DependencyMap& dependencyMap, itFilterLast, itDependencyMap, [](const QString& cmd, const std::pair& vpair) { - return cmd == vpair.first; + return cmd.compare(vpair.first) == 0; } ); @@ -113,6 +118,8 @@ void DRAMTimeDependenciesIF::mFilterDependencyMap(DependencyMap& dependencyMap, } else if (pair.first->compare(pair.second->first) < 0) { ++(pair.first); + } else if (pair.first->compare(pair.second->first) == 0) { + ++(pair.second); } else { pair.second = dependencyMap.erase(pair.second); @@ -123,9 +130,10 @@ void DRAMTimeDependenciesIF::mFilterDependencyMap(DependencyMap& dependencyMap, } } + } -size_t DRAMTimeDependenciesIF::mFindVectorMaximum(const std::vector& dependencyList) const { +uint DRAMTimeDependenciesIF::mFindVectorMaximum(const std::vector& dependencyList) const { auto maxElement = std::max_element( dependencyList.begin(), dependencyList.end(), diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.h index 7071ef84..cc818162 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.h +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.h @@ -35,6 +35,7 @@ struct QStringsComparator { typedef std::map DependencyMap; + class DRAMTimeDependenciesIF { public: DRAMTimeDependenciesIF(const QJsonObject& memspec); @@ -44,10 +45,13 @@ public: static const QJsonObject getMemspec(const TraceDB& tdb); + const uint getClk() const { return clk; } + const uint getNAW() const { return nActivateWindow; }; + protected: void mFilterDependencyList(std::vector& dependencyList, const std::vector& dependencyFilter) const; void mFilterDependencyMap(DependencyMap& dependencyMap, const std::vector& dependencyFilter) const; - size_t mFindVectorMaximum(const std::vector& dependencyList) const; + uint mFindVectorMaximum(const std::vector& dependencyList) const; protected: QJsonObject mMemspecJson; @@ -56,6 +60,9 @@ protected: protected: virtual void mInitializeValues() {} ; virtual DependencyMap mSpecializedGetDependencies() const { DependencyMap map; return map; } ; + + uint clk = 0; + uint nActivateWindow = 0; }; diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp index f9c72c91..65f41cc7 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp @@ -1,16 +1,16 @@ #include "dramtimedependencyfactory.h" -DRAMTimeDependenciesIF DRAMTimeDependencyFactory::make(const TraceDB& tdb) { +std::shared_ptr DRAMTimeDependencyFactory::make(const TraceDB& tdb) { const QJsonObject& memspec = DRAMTimeDependenciesIF::getMemspec(tdb); - QString deviceType = memspec["memspec"]["memoryType"].toString(); + QString deviceType = memspec["memoryType"].toString(); if (deviceType == "DDR3") { - return DDR3TimeDependencies(memspec); + return std::make_shared(memspec); } else { // TODO maybe throw? - return DRAMTimeDependenciesIF(memspec); + throw std::invalid_argument("Could not find the device type '" + deviceType.toStdString() + '\''); } diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.h index d6232ffe..748c5ab1 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.h +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.h @@ -1,13 +1,15 @@ #pragma once +#include + #include "dramtimedependenciesIF.h" #include "DDR3TimeDependencies.h" #include "data/tracedb.h" class DRAMTimeDependencyFactory { public: - static DRAMTimeDependenciesIF make(const TraceDB& tdb); + static std::shared_ptr make(const TraceDB& tdb); private: DRAMTimeDependencyFactory() = delete; diff --git a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp index 984a8886..7a18e978 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp @@ -2,13 +2,13 @@ #include "phasedependenciestracker.h" void -PhaseDependenciesTracker::calculateDependencies(TraceDB& tdb, const std::vector& commands) { +PhaseDependenciesTracker::calculateDependencies(TraceDB& tdb, std::vector& commands) { mDropTable(tdb); mCreateTable(tdb); auto& phases = mGetAllPhases(tdb, commands); - auto& entries = mCalculateDependencies(tdb, phases); + auto& entries = mCalculateDependencies(tdb, phases, commands); mInsertIntoTable(tdb, entries); @@ -61,7 +61,7 @@ void PhaseDependenciesTracker::mInsertIntoTable(TraceDB& tdb, const std::vector< } const std::vector> -PhaseDependenciesTracker::mGetAllPhases(TraceDB& tdb, const std::vector& commands) { +PhaseDependenciesTracker::mGetAllPhases(TraceDB& tdb, const std::vector& commands) { std::vector> phases; QString queryStr = "SELECT Phases.*, Transactions.TBank, Transactions.TRank " @@ -70,8 +70,8 @@ PhaseDependenciesTracker::mGetAllPhases(TraceDB& tdb, const std::vector -PhaseDependenciesTracker::mCalculateDependencies(const TraceDB& tdb, const std::vector>& transactions) { +PhaseDependenciesTracker::mCalculateDependencies(const TraceDB& tdb, const std::vector>& phases, std::vector& commands) { std::vector entries; - DRAMTimeDependenciesIF deviceDependencies = DRAMTimeDependencyFactory::make(tdb); - // TODO Main dependency calculation loop + // Get dependencies for tdb device + auto device = DRAMTimeDependencyFactory::make(tdb); + DependencyMap deviceDependencies = device->getDependencies(commands); + + // Tries to find all timing dependencies for each phase on the trace + std::vector tmpPotentialNAW; + tmpPotentialNAW.reserve(16); + for (size_t i = 1; i < phases.size(); i++) { + // NAW dependencies variables reset + tmpPotentialNAW.clear(); + size_t nawCount = 0; + + // Auxiliary variables + const auto& phase = phases[i]; + const size_t cmdBank = phase->tBank; + const size_t cmdRank = phase->tRank; + + // Get time dependency descriptions for the current phase + const auto& deps = deviceDependencies.at(phase->phaseName); + + // Loop all previous phases until there cannot be any more time dependencies + for (int j = i-1; j >= 0; j--) { + // Get next phase to analyse + const auto& otherPhase = phases[j]; + // Calculates the time difference in nanoseconds + const auto timeDiff = phase->phaseBegin - otherPhase->phaseBegin; + + // Time difference begin greater than the maximum possible dependency time ends the internal loop + if (timeDiff > deps.maxTime) break; + + // For each possible dependency for the current phase, + // checks if otherPhase would match as a dependency + for (const auto& dep : deps.dependencies) { + if (dep.phaseDep != "NAW" && dep.phaseDep != otherPhase->phaseName) continue; + + if ( + dep.depType == DependencyType::IntraBank && cmdBank != otherPhase->tBank + || dep.depType == DependencyType::IntraRank && cmdBank != otherPhase->tRank + || dep.depType == DependencyType::InterRank && cmdRank == otherPhase->tRank // TODO - is this last comparison correct? + ) { + continue; + } + + if (dep.phaseDep == "NAW") { + if (otherPhase->phaseName == "ACT") { + if (timeDiff == dep.timeValue) { + // Captures only the first (or exactly matching time) ACT in + // the ACT window as a dependency + tmpPotentialNAW.emplace_back(DBDependencyEntry{ + phase->id, + phase->phaseName, + PhaseDependency::dependencyTypeName(dep.depType), + dep.timeDepName, + otherPhase->id, + otherPhase->phaseName + }); + } + nawCount++; + + } + + continue; // TODO should this continue here or should it be removed for potentially more time dependencies to be captured? + } + + if (timeDiff == dep.timeValue) { + entries.emplace_back(DBDependencyEntry{ + phase->id, + phase->phaseName, + PhaseDependency::dependencyTypeName(dep.depType), + dep.timeDepName, + otherPhase->id, + otherPhase->phaseName + }); + } + + } + + if (timeDiff == device->getClk()) { + entries.emplace_back(DBDependencyEntry{ + phase->id, + phase->phaseName, + PhaseDependency::dependencyTypeName(DependencyType::IntraRank), + "CommandBus", + otherPhase->id, + otherPhase->phaseName + }); + } + + } + + if (nawCount >= device->getNAW()) { + entries.insert( entries.end(), tmpPotentialNAW.begin(), tmpPotentialNAW.end() ); + } + + } return entries; } diff --git a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h index a46d6c05..a01c537a 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h +++ b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h @@ -29,15 +29,15 @@ struct DBDependencyEntry { class PhaseDependenciesTracker { public: - static void calculateDependencies(TraceDB& tdb, const std::vector& commands); + static void calculateDependencies(TraceDB& tdb, std::vector& dependencyFilter); private: static void mDropTable(TraceDB& tdb); static void mCreateTable(TraceDB& tdb); static void mInsertIntoTable(TraceDB& tdb, const std::vector& entries); - static const std::vector> mGetAllPhases(TraceDB& tdb, const std::vector& commands); - static const std::vector mCalculateDependencies(const TraceDB& tdb, const std::vector>& phases); + static const std::vector> mGetAllPhases(TraceDB& tdb, const std::vector& commands); + static const std::vector mCalculateDependencies(const TraceDB& tdb, const std::vector>& phases, std::vector& commands); static QSqlQuery mExecuteQuery(TraceDB& tdb, const QString queryStr); diff --git a/DRAMSys/traceAnalyzer/businessObjects/phases/phasedependency.cpp b/DRAMSys/traceAnalyzer/businessObjects/phases/phasedependency.cpp index e76d0f8e..de6c65ff 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phases/phasedependency.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/phases/phasedependency.cpp @@ -129,4 +129,22 @@ void PhaseDependency::mDraw(QPoint &end, double depY, const TraceDrawingProperti drawText(painter, mTimeDependency, textPosition, alignment); } -} \ No newline at end of file +} + +QString PhaseDependency::dependencyTypeName(DependencyType dtype) { + switch(dtype) { + case IntraBank: + return "IntraBank"; + + case IntraRank: + return "IntraRank"; + + case InterRank: + return "InterRank"; + + default: + // TODO - maybe throw? + return ""; + + } +} diff --git a/DRAMSys/traceAnalyzer/businessObjects/phases/phasedependency.h b/DRAMSys/traceAnalyzer/businessObjects/phases/phasedependency.h index fa203556..439f973c 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phases/phasedependency.h +++ b/DRAMSys/traceAnalyzer/businessObjects/phases/phasedependency.h @@ -68,6 +68,8 @@ public: bool draw(QPoint &end, const TraceDrawingProperties &drawingProperties, QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap); + static QString dependencyTypeName(DependencyType); + protected: DependencyType mType; QString mTimeDependency; diff --git a/DRAMSys/traceAnalyzer/tracefiletab.cpp b/DRAMSys/traceAnalyzer/tracefiletab.cpp index f25587bd..d0949ba3 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.cpp +++ b/DRAMSys/traceAnalyzer/tracefiletab.cpp @@ -307,17 +307,16 @@ void TraceFileTab::on_latencyTreeView_doubleClicked(const QModelIndex &index) void TraceFileTab::on_calculateDependencies_clicked() { // TODO - anything else? Update view maybe? // TODO - For now fixed, but must be selectable - std::vector dependencyFilter = { + std::vector dependencyFilter = { "ACT", - "PRE", + "PREPB", "RD", "RDA", "WR", "WRA", "PDE", "PDX", - "PREA", - "NAW" + "PREAB" }; PhaseDependenciesTracker::calculateDependencies(navigator->TraceFile(), dependencyFilter); From 0e1245ad98a607f8ce72579db4f3db7c4c146d17 Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Mon, 13 Dec 2021 13:31:15 +0100 Subject: [PATCH 11/14] Added dependency calculations. Still missing tests and interface. --- .../DDR3TimeDependencies.cpp | 60 ++++++++------- .../DDR3TimeDependencies.h | 2 +- .../dramtimedependenciesIF.cpp | 11 ++- .../dramtimedependenciesIF.h | 4 +- .../dramtimedependencyfactory.cpp | 5 +- .../phasedependenciestracker.cpp | 73 ++++++++++++++++--- .../phasedependenciestracker.h | 9 +++ DRAMSys/traceAnalyzer/tracefiletab.cpp | 2 +- 8 files changed, 114 insertions(+), 52 deletions(-) diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp index 5b494732..1b59a3eb 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp @@ -1,43 +1,41 @@ #include "DDR3TimeDependencies.h" -DDR3TimeDependencies::DDR3TimeDependencies(const QJsonObject& memspec) : DRAMTimeDependenciesIF(memspec) { +DDR3TimeDependencies::DDR3TimeDependencies(const QJsonObject& memspec, const uint clk) : DRAMTimeDependenciesIF(memspec, clk) { mInitializeValues(); } void DDR3TimeDependencies::mInitializeValues() { - burstLength = mMemspecJson["memarchitecturespec"].toObject()["burstLength"].toString().toInt(); - dataRate = mMemspecJson["memarchitecturespec"].toObject()["dataRate"].toString().toInt(); - clk = mMemspecJson["memarchitecturespec"].toArray()[0].toString().toInt(); + burstLength = mMemspecJson["memarchitecturespec"].toObject()["burstLength"].toInt(); + dataRate = mMemspecJson["memarchitecturespec"].toObject()["dataRate"].toInt(); nActivateWindow = 4; - - tRP = mMemspecJson["memtimingspec"].toObject()["RP"].toString().toInt(); - tRAS = mMemspecJson["memtimingspec"].toObject()["RAS"].toString().toInt(); - tRC = mMemspecJson["memtimingspec"].toObject()["RC"].toString().toInt(); - tRTP = mMemspecJson["memtimingspec"].toObject()["RTP"].toString().toInt(); - tRRD = mMemspecJson["memtimingspec"].toObject()["RRD"].toString().toInt(); - tCCD = mMemspecJson["memtimingspec"].toObject()["CCD"].toString().toInt(); - tRCD = mMemspecJson["memtimingspec"].toObject()["RCD"].toString().toInt(); - tNAW = mMemspecJson["memtimingspec"].toObject()["NAW"].toString().toInt(); - tRL = mMemspecJson["memtimingspec"].toObject()["RL"].toString().toInt(); - tWL = mMemspecJson["memtimingspec"].toObject()["WL"].toString().toInt(); - tWR = mMemspecJson["memtimingspec"].toObject()["WR"].toString().toInt(); - tWTR = mMemspecJson["memtimingspec"].toObject()["WTR"].toString().toInt(); - tCKESR = mMemspecJson["memtimingspec"].toObject()["CKESR"].toString().toInt(); - tCKE = mMemspecJson["memtimingspec"].toObject()["CKE"].toString().toInt(); - tXP = mMemspecJson["memtimingspec"].toObject()["XP"].toString().toInt(); - tXPDLL = mMemspecJson["memtimingspec"].toObject()["XPDLL"].toString().toInt(); - tXS = mMemspecJson["memtimingspec"].toObject()["XS"].toString().toInt(); - tXSDLL = mMemspecJson["memtimingspec"].toObject()["XSDLL"].toString().toInt(); - tAL = mMemspecJson["memtimingspec"].toObject()["AL"].toString().toInt(); - tRFC = mMemspecJson["memtimingspec"].toObject()["RFC"].toString().toInt(); - tREFI = mMemspecJson["memtimingspec"].toObject()["REFI"].toString().toInt(); - tRTRS = mMemspecJson["memtimingspec"].toObject()["RTRS"].toString().toInt(); - tACTPDEN = mMemspecJson["memtimingspec"].toObject()["ACTPDEN"].toString().toInt(); - tPRPDEN = mMemspecJson["memtimingspec"].toObject()["PRPDEN"].toString().toInt(); - tREFPDEN = mMemspecJson["memtimingspec"].toObject()["REFPDEN"].toString().toInt(); - tCKE = mMemspecJson["memtimingspec"].toObject()["CKE"].toString().toInt(); + tRP = clk * mMemspecJson["memtimingspec"].toObject()["RP"].toInt(); + tRAS = clk * mMemspecJson["memtimingspec"].toObject()["RAS"].toInt(); + tRC = clk * mMemspecJson["memtimingspec"].toObject()["RC"].toInt(); + tRTP = clk * mMemspecJson["memtimingspec"].toObject()["RTP"].toInt(); + tRRD = clk * mMemspecJson["memtimingspec"].toObject()["RRD"].toInt(); + tCCD = clk * mMemspecJson["memtimingspec"].toObject()["CCD"].toInt(); + tRCD = clk * mMemspecJson["memtimingspec"].toObject()["RCD"].toInt(); + tNAW = clk * mMemspecJson["memtimingspec"].toObject()["FAW"].toInt(); + tRL = clk * mMemspecJson["memtimingspec"].toObject()["RL"].toInt(); + tWL = clk * mMemspecJson["memtimingspec"].toObject()["WL"].toInt(); + tWR = clk * mMemspecJson["memtimingspec"].toObject()["WR"].toInt(); + tWTR = clk * mMemspecJson["memtimingspec"].toObject()["WTR"].toInt(); + tCKESR = clk * mMemspecJson["memtimingspec"].toObject()["CKESR"].toInt(); + tCKE = clk * mMemspecJson["memtimingspec"].toObject()["CKE"].toInt(); + tXP = clk * mMemspecJson["memtimingspec"].toObject()["XP"].toInt(); + tXPDLL = clk * mMemspecJson["memtimingspec"].toObject()["XPDLL"].toInt(); + tXS = clk * mMemspecJson["memtimingspec"].toObject()["XS"].toInt(); + tXSDLL = clk * mMemspecJson["memtimingspec"].toObject()["XSDLL"].toInt(); + tAL = clk * mMemspecJson["memtimingspec"].toObject()["AL"].toInt(); + tRFC = clk * mMemspecJson["memtimingspec"].toObject()["RFC"].toInt(); + tREFI = clk * mMemspecJson["memtimingspec"].toObject()["REFI"].toInt(); + tRTRS = clk * mMemspecJson["memtimingspec"].toObject()["RTRS"].toInt(); + tACTPDEN = clk * mMemspecJson["memtimingspec"].toObject()["ACTPDEN"].toInt(); + tPRPDEN = clk * mMemspecJson["memtimingspec"].toObject()["PRPDEN"].toInt(); + tREFPDEN = clk * mMemspecJson["memtimingspec"].toObject()["REFPDEN"].toInt(); + tCKE = clk * mMemspecJson["memtimingspec"].toObject()["CKE"].toInt(); tPD = tCKE; tBURST = (uint) ((burstLength / (float) dataRate) * clk); diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h index 53568c34..7c8a30f4 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h @@ -5,7 +5,7 @@ class DDR3TimeDependencies : public DRAMTimeDependenciesIF { public: - DDR3TimeDependencies(const QJsonObject& memspec); + DDR3TimeDependencies(const QJsonObject& memspec, const uint clk); protected: void mInitializeValues() override; diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp index 0960d646..40f43b6a 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp @@ -3,8 +3,9 @@ #include -DRAMTimeDependenciesIF::DRAMTimeDependenciesIF(const QJsonObject& memspec) { +DRAMTimeDependenciesIF::DRAMTimeDependenciesIF(const QJsonObject& memspec, const uint inClk) { mMemspecJson = memspec; + clk = inClk; } @@ -34,16 +35,18 @@ DRAMTimeDependenciesIF::getDependencies(std::vector& dependencyFilter) return dependenciesMap; } -const QJsonObject DRAMTimeDependenciesIF::getMemspec(const TraceDB& tdb) { +const QJsonObject DRAMTimeDependenciesIF::getMemspec(const TraceDB& tdb, uint& clk) { QSqlDatabase db = tdb.getDatabase(); - QString query = "SELECT Memspec FROM GeneralInfo"; + QString query = "SELECT clk, Memspec FROM GeneralInfo"; QSqlQuery sqlQuery = db.exec(query); sqlQuery.next(); - QString memSpecJson = sqlQuery.value(0).toString(); + clk = sqlQuery.value(0).toInt(); + QString memSpecJson = sqlQuery.value(1).toString(); sqlQuery.finish(); QJsonDocument jsonDocument = QJsonDocument::fromJson(memSpecJson.toUtf8()); + return jsonDocument.object()["memspec"].toObject(); } diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.h index cc818162..bd495583 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.h +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependenciesIF.h @@ -38,12 +38,12 @@ typedef std::map DependencyM class DRAMTimeDependenciesIF { public: - DRAMTimeDependenciesIF(const QJsonObject& memspec); + DRAMTimeDependenciesIF(const QJsonObject& memspec, const uint clk); virtual ~DRAMTimeDependenciesIF() = default; DependencyMap getDependencies(std::vector& dependencyFilter) const; - static const QJsonObject getMemspec(const TraceDB& tdb); + static const QJsonObject getMemspec(const TraceDB& tdb, uint& clk); const uint getClk() const { return clk; } const uint getNAW() const { return nActivateWindow; }; diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp index 65f41cc7..1586406f 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp @@ -2,11 +2,12 @@ #include "dramtimedependencyfactory.h" std::shared_ptr DRAMTimeDependencyFactory::make(const TraceDB& tdb) { - const QJsonObject& memspec = DRAMTimeDependenciesIF::getMemspec(tdb); + uint clk = 0; + const QJsonObject& memspec = DRAMTimeDependenciesIF::getMemspec(tdb, clk); QString deviceType = memspec["memoryType"].toString(); if (deviceType == "DDR3") { - return std::make_shared(memspec); + return std::make_shared(memspec, clk); } else { // TODO maybe throw? diff --git a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp index 7a18e978..2f0a8e45 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp @@ -3,15 +3,22 @@ void PhaseDependenciesTracker::calculateDependencies(TraceDB& tdb, std::vector& commands) { + mBeginTransaction(tdb); + mDropTable(tdb); mCreateTable(tdb); auto& phases = mGetAllPhases(tdb, commands); + if (phases.size() == 0) { + mRollbackChanges(tdb); + } + auto& entries = mCalculateDependencies(tdb, phases, commands); mInsertIntoTable(tdb, entries); + mCommitTransaction(tdb); } void PhaseDependenciesTracker::mDropTable(TraceDB& tdb) { @@ -29,7 +36,7 @@ void PhaseDependenciesTracker::mCreateTable(TraceDB& tdb) { } void PhaseDependenciesTracker::mInsertIntoTable(TraceDB& tdb, const std::vector& entries) { - static const size_t bulkInsertionSize = 1000; + static const size_t bulkInsertionSize = 200; auto numberOfEntries = entries.size(); @@ -37,25 +44,33 @@ void PhaseDependenciesTracker::mInsertIntoTable(TraceDB& tdb, const std::vector< size_t counter = 0; for (const auto& entry : entries) { if (counter == 0) { - // TODO Reset command string and add first command - command = ""; + // Reset command string and add first entry + command = "INSERT INTO 'DirectDependencies' ('DelayedPhaseID', 'DelayedPhaseName', 'DependencyType', 'TimeDependency', 'DependencyPhaseID', 'DependencyPhaseName') "; + mAddFirstEntryCommandString(command, entry); + + counter++; - } else if (counter == bulkInsertionSize) { - // TODO Write last command and submit + } else if (counter == bulkInsertionSize-1) { + // Write last entry and submit + mAddEntryCommandString(command, entry); + + mExecuteQuery(tdb, command); counter = 0; } else { - // TODO + // Write entry + mAddEntryCommandString(command, entry); counter++; + } } if (counter != 0) { - // TODO Submit command string + mExecuteQuery(tdb, command); } } @@ -74,7 +89,7 @@ PhaseDependenciesTracker::mGetAllPhases(TraceDB& tdb, const std::vector queryStr = queryStr + '\"' + cmd + "\","; } queryStr.back() = ')'; - queryStr += " ORDER BY PhaseBegin "; + queryStr += " ORDER BY PhaseBegin; "; auto query = mExecuteQuery(tdb, queryStr); @@ -119,6 +134,7 @@ PhaseDependenciesTracker::mGetAllPhases(TraceDB& tdb, const std::vector const std::vector PhaseDependenciesTracker::mCalculateDependencies(const TraceDB& tdb, const std::vector>& phases, std::vector& commands) { std::vector entries; + entries.reserve((size_t) (0.4 * phases.size())); // Get dependencies for tdb device auto device = DRAMTimeDependencyFactory::make(tdb); @@ -146,7 +162,6 @@ PhaseDependenciesTracker::mCalculateDependencies(const TraceDB& tdb, const std:: const auto& otherPhase = phases[j]; // Calculates the time difference in nanoseconds const auto timeDiff = phase->phaseBegin - otherPhase->phaseBegin; - // Time difference begin greater than the maximum possible dependency time ends the internal loop if (timeDiff > deps.maxTime) break; @@ -157,12 +172,11 @@ PhaseDependenciesTracker::mCalculateDependencies(const TraceDB& tdb, const std:: if ( dep.depType == DependencyType::IntraBank && cmdBank != otherPhase->tBank - || dep.depType == DependencyType::IntraRank && cmdBank != otherPhase->tRank + || dep.depType == DependencyType::IntraRank && cmdRank != otherPhase->tRank || dep.depType == DependencyType::InterRank && cmdRank == otherPhase->tRank // TODO - is this last comparison correct? ) { continue; } - if (dep.phaseDep == "NAW") { if (otherPhase->phaseName == "ACT") { if (timeDiff == dep.timeValue) { @@ -226,3 +240,40 @@ QSqlQuery PhaseDependenciesTracker::mExecuteQuery(TraceDB& tdb, const QString qu return query; } + +void PhaseDependenciesTracker::mBeginTransaction(TraceDB& tdb) { + const QString queryStr = "BEGIN TRANSACTION;"; + mExecuteQuery(tdb, queryStr); + +} + +void PhaseDependenciesTracker::mRollbackChanges(TraceDB& tdb) { + const QString queryStr = "ROLLBACK;"; + mExecuteQuery(tdb, queryStr); + +} + +void PhaseDependenciesTracker::mCommitTransaction(TraceDB& tdb) { + const QString queryStr = "COMMIT;"; + mExecuteQuery(tdb, queryStr); + +} + +void PhaseDependenciesTracker::mAddFirstEntryCommandString(QString& command, const DBDependencyEntry& entry) { + command = command + " SELECT '" + QString::number(entry.delayedPhaseID) + "' AS 'DelayedPhaseID', '" + + entry.delayedPhaseName + "' AS 'DelayedPhaseName', '" + + entry.dependencyType + "' AS 'DependencyType', '" + + entry.timeDependency + "' AS 'TimeDependency', '" + + QString::number(entry.dependencyPhaseID) + "' AS 'DependencyPhaseID', '" + + entry.dependencyPhaseName + "' AS 'DependencyPhaseName' "; + +} + +void PhaseDependenciesTracker::mAddEntryCommandString(QString& command, const DBDependencyEntry& entry) { + command = command + " UNION ALL SELECT '" + QString::number(entry.delayedPhaseID) + "', '" + + entry.delayedPhaseName + "', '" + + entry.dependencyType + "', '" + + entry.timeDependency + "', '" + + QString::number(entry.dependencyPhaseID) + "', '" + + entry.dependencyPhaseName + "' "; +} diff --git a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h index a01c537a..17d5ecda 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h +++ b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.h @@ -43,4 +43,13 @@ private: PhaseDependenciesTracker() = delete; ~PhaseDependenciesTracker() = delete; + +private: + static void mBeginTransaction(TraceDB& tdb); + static void mRollbackChanges(TraceDB& tdb); + static void mCommitTransaction(TraceDB& tdb); + + static void mAddFirstEntryCommandString(QString& command, const DBDependencyEntry& entry); + static void mAddEntryCommandString(QString& command, const DBDependencyEntry& entry); + }; diff --git a/DRAMSys/traceAnalyzer/tracefiletab.cpp b/DRAMSys/traceAnalyzer/tracefiletab.cpp index d0949ba3..c98f4e2b 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.cpp +++ b/DRAMSys/traceAnalyzer/tracefiletab.cpp @@ -309,7 +309,7 @@ void TraceFileTab::on_calculateDependencies_clicked() { // TODO - For now fixed, but must be selectable std::vector dependencyFilter = { "ACT", - "PREPB", + "PREPB", "RD", "RDA", "WR", From 7bfb12813254d4e1a294fd9350237cb4b50a2650 Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Mon, 13 Dec 2021 16:30:45 +0100 Subject: [PATCH 12/14] Added interface for dependency calculation. --- DRAMSys/traceAnalyzer/CMakeLists.txt | 1 + .../businessObjects/configmodels.cpp | 139 ----------------- .../businessObjects/configmodels.h | 56 ------- .../businessObjects/dependencymodels.cpp | 141 ++++++++++++++++++ .../businessObjects/dependencymodels.h | 65 ++++++++ .../DDR3TimeDependencies.cpp | 18 +++ .../DDR3TimeDependencies.h | 2 + .../dramtimedependencyfactory.cpp | 29 ++++ .../dramtimedependencyfactory.h | 4 + .../phasedependenciestracker.cpp | 50 ++++--- DRAMSys/traceAnalyzer/data/QueryTexts.h | 10 +- DRAMSys/traceAnalyzer/data/tracedb.cpp | 9 +- .../traceAnalyzer/presentation/traceplot.cpp | 3 + DRAMSys/traceAnalyzer/tracefiletab.cpp | 36 +++-- DRAMSys/traceAnalyzer/tracefiletab.h | 3 + DRAMSys/traceAnalyzer/tracefiletab.ui | 16 +- 16 files changed, 343 insertions(+), 239 deletions(-) create mode 100644 DRAMSys/traceAnalyzer/businessObjects/dependencymodels.cpp create mode 100644 DRAMSys/traceAnalyzer/businessObjects/dependencymodels.h diff --git a/DRAMSys/traceAnalyzer/CMakeLists.txt b/DRAMSys/traceAnalyzer/CMakeLists.txt index 7b84d13f..327e057b 100644 --- a/DRAMSys/traceAnalyzer/CMakeLists.txt +++ b/DRAMSys/traceAnalyzer/CMakeLists.txt @@ -101,6 +101,7 @@ add_executable(TraceAnalyzer presentation/traceselector.cpp businessObjects/configmodels.cpp businessObjects/commentmodel.cpp + businessObjects/dependencymodels.cpp businessObjects/dramTimeDependencies/dramtimedependenciesIF.cpp businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp diff --git a/DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp b/DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp index 149ccf8d..439f85f1 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/configmodels.cpp @@ -283,142 +283,3 @@ 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); - - if (traceFile.checkDependencyTableExists()) - { - 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 7408db5c..9b5731db 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/configmodels.h +++ b/DRAMSys/traceAnalyzer/businessObjects/configmodels.h @@ -31,7 +31,6 @@ * * Authors: * Derek Christ - * Iron Prando da Silva */ #ifndef CONFIGMODELS_H @@ -124,59 +123,4 @@ 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/dependencymodels.cpp b/DRAMSys/traceAnalyzer/businessObjects/dependencymodels.cpp new file mode 100644 index 00000000..cbc39b65 --- /dev/null +++ b/DRAMSys/traceAnalyzer/businessObjects/dependencymodels.cpp @@ -0,0 +1,141 @@ + +#include "dependencymodels.h" + +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); + + if (traceFile.checkDependencyTableExists()) + { + 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/dependencymodels.h b/DRAMSys/traceAnalyzer/businessObjects/dependencymodels.h new file mode 100644 index 00000000..02736e13 --- /dev/null +++ b/DRAMSys/traceAnalyzer/businessObjects/dependencymodels.h @@ -0,0 +1,65 @@ + +#pragma once + +#include "../data/tracedb.h" +#include "phases/dependencyinfos.h" + +#include +#include +#include +#include + +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); +}; diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp index 1b59a3eb..fca581e0 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.cpp @@ -50,6 +50,24 @@ void DDR3TimeDependencies::mInitializeValues() { } +const std::vector DDR3TimeDependencies::getPossiblePhases() { + return {"ACT", + "RD", + "RDA", + "WR", + "WRA", + "PREPB", + "PREAB", + "REFAB", + "PDEA", + "PDXA", + "PDEP", + "PDXP", + "SREFEN", + "SREFEX" + }; +} + DependencyMap DDR3TimeDependencies::mSpecializedGetDependencies() const { DependencyMap dmap; diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h index 7c8a30f4..47d15f9a 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/DDR3TimeDependencies.h @@ -7,6 +7,8 @@ class DDR3TimeDependencies : public DRAMTimeDependenciesIF { public: DDR3TimeDependencies(const QJsonObject& memspec, const uint clk); + static const std::vector getPossiblePhases(); + protected: void mInitializeValues() override; DependencyMap mSpecializedGetDependencies() const override; diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp index 1586406f..a71e0eed 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.cpp @@ -16,3 +16,32 @@ std::shared_ptr DRAMTimeDependencyFactory::make(const Tr } } + +const std::vector DRAMTimeDependencyFactory::possiblePhases(const TraceDB& tdb) { + uint clk; // Not used + const QJsonObject& memspec = DRAMTimeDependenciesIF::getMemspec(tdb, clk); + QString deviceType = memspec["memoryType"].toString(); + + if (deviceType == "DDR3") { + return DDR3TimeDependencies::getPossiblePhases(); + + } else { + // TODO maybe throw? + throw std::invalid_argument("Could not find the device type '" + deviceType.toStdString() + '\''); + + } + +} + +bool DRAMTimeDependencyFactory::deviceSupported(const TraceDB& tdb) { + uint clk; // Not used + const QJsonObject& memspec = DRAMTimeDependenciesIF::getMemspec(tdb, clk); + QString deviceType = memspec["memoryType"].toString(); + + if (deviceType == "DDR3") { + return true; + + } else { + return false; + } +} diff --git a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.h b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.h index 748c5ab1..7a30dec4 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.h +++ b/DRAMSys/traceAnalyzer/businessObjects/dramTimeDependencies/dramtimedependencyfactory.h @@ -11,6 +11,10 @@ class DRAMTimeDependencyFactory { public: static std::shared_ptr make(const TraceDB& tdb); + static const std::vector possiblePhases(const TraceDB& tdb); + + static bool deviceSupported(const TraceDB& tdb); + private: DRAMTimeDependencyFactory() = delete; ~DRAMTimeDependencyFactory() = delete; diff --git a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp index 2f0a8e45..0c2c6450 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp @@ -6,23 +6,28 @@ PhaseDependenciesTracker::calculateDependencies(TraceDB& tdb, std::vector 0) { + mCreateTable(tdb); + + auto& phases = mGetAllPhases(tdb, commands); + + if (phases.size() != 0) { + auto& entries = mCalculateDependencies(tdb, phases, commands); + mInsertIntoTable(tdb, entries); + + } else { + // mRollbackChanges(tdb); + // return; + } + } - auto& entries = mCalculateDependencies(tdb, phases, commands); - - mInsertIntoTable(tdb, entries); - mCommitTransaction(tdb); } void PhaseDependenciesTracker::mDropTable(TraceDB& tdb) { - QString command = "DROP TABLE DirectDependencies; "; + QString command = "DROP TABLE IF EXISTS DirectDependencies; "; auto query = mExecuteQuery(tdb, command); query.finish(); @@ -54,7 +59,8 @@ void PhaseDependenciesTracker::mInsertIntoTable(TraceDB& tdb, const std::vector< // Write last entry and submit mAddEntryCommandString(command, entry); - mExecuteQuery(tdb, command); + auto query = mExecuteQuery(tdb, command); + query.finish(); counter = 0; @@ -70,7 +76,8 @@ void PhaseDependenciesTracker::mInsertIntoTable(TraceDB& tdb, const std::vector< } if (counter != 0) { - mExecuteQuery(tdb, command); + auto query = mExecuteQuery(tdb, command); + query.finish(); } } @@ -93,6 +100,9 @@ PhaseDependenciesTracker::mGetAllPhases(TraceDB& tdb, const std::vector auto query = mExecuteQuery(tdb, queryStr); + if (!query.next()) + return phases; + if (!query.last()) { throw sqlException( ("Query:\n " + tdb.queryToString(query) + "\n failed. Error: \n" "Could not retrieve number of rows\n").toStdString(), @@ -128,6 +138,8 @@ PhaseDependenciesTracker::mGetAllPhases(TraceDB& tdb, const std::vector throw std::runtime_error("An error occurred while fetching phases in 'PhaseDependenciesTracker::mGetAllPhases': expected " + std::to_string(nrows) + " rows, but found " + std::to_string(rowIt) + "\n"); } + query.finish(); + return phases; } @@ -243,20 +255,20 @@ QSqlQuery PhaseDependenciesTracker::mExecuteQuery(TraceDB& tdb, const QString qu void PhaseDependenciesTracker::mBeginTransaction(TraceDB& tdb) { const QString queryStr = "BEGIN TRANSACTION;"; - mExecuteQuery(tdb, queryStr); - + auto query = mExecuteQuery(tdb, queryStr); + query.finish(); } void PhaseDependenciesTracker::mRollbackChanges(TraceDB& tdb) { const QString queryStr = "ROLLBACK;"; - mExecuteQuery(tdb, queryStr); - + auto query = mExecuteQuery(tdb, queryStr); + query.finish(); } void PhaseDependenciesTracker::mCommitTransaction(TraceDB& tdb) { const QString queryStr = "COMMIT;"; - mExecuteQuery(tdb, queryStr); - + auto query = mExecuteQuery(tdb, queryStr); + query.finish(); } void PhaseDependenciesTracker::mAddFirstEntryCommandString(QString& command, const DBDependencyEntry& entry) { diff --git a/DRAMSys/traceAnalyzer/data/QueryTexts.h b/DRAMSys/traceAnalyzer/data/QueryTexts.h index 361ec855..0b877a5d 100644 --- a/DRAMSys/traceAnalyzer/data/QueryTexts.h +++ b/DRAMSys/traceAnalyzer/data/QueryTexts.h @@ -63,7 +63,7 @@ struct TransactionQueryTexts { "WITH timespanTransactions AS (" + selectTransactionsByTimespan + ") SELECT * from DirectDependencies WHERE DelayedPhaseID IN (" " SELECT DirectDependencies.DelayedPhaseID FROM DirectDependencies JOIN timespanTransactions " - " ON DirectDependencies.DelayedPhaseID = timespanTransactions.PhaseID )"; + " ON DirectDependencies.DelayedPhaseID = timespanTransactions.PhaseID ) "; // For some reason I could not use a parameter for these below selectDependencyTypePercentages = @@ -79,7 +79,7 @@ struct TransactionQueryTexts { ") " "SELECT param, ROUND(ndeps*100.0 / (SELECT total FROM TotalDeps), 3) as percentage " "FROM DependencyTypeDeps " - "ORDER BY percentage DESC "; + "ORDER BY percentage DESC ;"; selectTimeDependencyPercentages = "WITH TotalDeps (total) AS ( " @@ -94,7 +94,7 @@ struct TransactionQueryTexts { ") " "SELECT param, ROUND(ndeps*100.0 / (SELECT total FROM TotalDeps), 3) as percentage " "FROM DependencyTypeDeps " - "ORDER BY percentage DESC "; + "ORDER BY percentage DESC ;"; selectDelayedPhasePercentages = "WITH TotalDeps (total) AS ( " @@ -109,7 +109,7 @@ struct TransactionQueryTexts { ") " "SELECT param, ROUND(ndeps*100.0 / (SELECT total FROM TotalDeps), 3) as percentage " "FROM DependencyTypeDeps " - "ORDER BY percentage DESC "; + "ORDER BY percentage DESC ;"; selectDependencyPhasePercentages = "WITH TotalDeps (total) AS ( " @@ -124,7 +124,7 @@ struct TransactionQueryTexts { ") " "SELECT param, ROUND(ndeps*100.0 / (SELECT total FROM TotalDeps), 3) as percentage " "FROM DependencyTypeDeps " - "ORDER BY percentage DESC "; + "ORDER BY percentage DESC ;"; } }; diff --git a/DRAMSys/traceAnalyzer/data/tracedb.cpp b/DRAMSys/traceAnalyzer/data/tracedb.cpp index 0bf0bf42..47d12cf4 100644 --- a/DRAMSys/traceAnalyzer/data/tracedb.cpp +++ b/DRAMSys/traceAnalyzer/data/tracedb.cpp @@ -67,7 +67,10 @@ TraceDB::TraceDB(QString path, bool openExisting) database = QSqlDatabase::addDatabase("QSQLITE", path); database.setDatabaseName(path); - database.open(); + if (!database.open()) + { + qDebug() << database.lastError().text(); + } if (!openExisting) dropAndCreateTables(); prepareQueries(); @@ -399,6 +402,7 @@ DependencyInfos TraceDB::getDependencyInfos(DependencyInfos::Type infoType) executeQuery(checkDependenciesExist); if (!checkDependenciesExist.next() || checkDependenciesExist.value(0).toInt() != 1) { + checkDependenciesExist.finish(); return dummy; } @@ -562,6 +566,8 @@ DependencyInfos TraceDB::parseDependencyInfos(QSqlQuery &query, const Dependency infos.addInfo({query.value(0).toString(), query.value(1).toFloat()}); } + query.finish(); + return infos; } @@ -576,6 +582,7 @@ void TraceDB::executeQuery(QSqlQuery query) } else { + query.finish(); throw sqlException( ("Query:\n " + queryToString(query) + "\n failed. Error: \n" + query.lastError().text()).toStdString(), this->pathToDB.toStdString()); diff --git a/DRAMSys/traceAnalyzer/presentation/traceplot.cpp b/DRAMSys/traceAnalyzer/presentation/traceplot.cpp index 9389c5e5..7579a145 100644 --- a/DRAMSys/traceAnalyzer/presentation/traceplot.cpp +++ b/DRAMSys/traceAnalyzer/presentation/traceplot.cpp @@ -513,6 +513,9 @@ void TracePlot::currentTraceTimeChanged() } setAxisScale(xBottom, GetCurrentTimespan().Begin(), GetCurrentTimespan().End()); + + dependenciesSubMenu->setEnabled(navigator->TraceFile().checkDependencyTableExists()); + replot(); } diff --git a/DRAMSys/traceAnalyzer/tracefiletab.cpp b/DRAMSys/traceAnalyzer/tracefiletab.cpp index c98f4e2b..af64a089 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.cpp +++ b/DRAMSys/traceAnalyzer/tracefiletab.cpp @@ -85,6 +85,8 @@ TraceFileTab::TraceFileTab(QWidget *parent, const QString &path) setUpTraceSelector(); setUpCommentView(); + setUpPossiblePhases(); + ui->mcConfigView->setModel(mcConfigModel); ui->mcConfigView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); @@ -184,6 +186,18 @@ void TraceFileTab::setUpCommentView() commentModel, &CommentModel::rowDoubleClicked); } +void TraceFileTab::setUpPossiblePhases() { + const auto possiblePhases = DRAMTimeDependencyFactory::possiblePhases(navigator->TraceFile()); + for (auto p : possiblePhases) { + auto item = new QListWidgetItem(p, ui->depTabPossiblePhases); + item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // set checkable flag + item->setCheckState(Qt::Unchecked); // AND initialize check state + + } + + ui->calculateDependencies->setEnabled(DRAMTimeDependencyFactory::deviceSupported(navigator->TraceFile())); +} + void TraceFileTab::tracefileChanged() { if (savingChangesToDB == true) { @@ -305,21 +319,17 @@ void TraceFileTab::on_latencyTreeView_doubleClicked(const QModelIndex &index) } void TraceFileTab::on_calculateDependencies_clicked() { - // TODO - anything else? Update view maybe? - // TODO - For now fixed, but must be selectable - std::vector dependencyFilter = { - "ACT", - "PREPB", - "RD", - "RDA", - "WR", - "WRA", - "PDE", - "PDX", - "PREAB" - }; + std::vector dependencyFilter; + for (int row = 0; row < ui->depTabPossiblePhases->count(); row++) { + auto item = ui->depTabPossiblePhases->item(row); + if (item->checkState() == Qt::Checked) + dependencyFilter.push_back(item->text()); + } PhaseDependenciesTracker::calculateDependencies(navigator->TraceFile(), dependencyFilter); + depInfosView = new DependencyInfosModel(navigator->TraceFile(), this); + ui->depInfosView->setModel(depInfosView); + ui->depInfosView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); } diff --git a/DRAMSys/traceAnalyzer/tracefiletab.h b/DRAMSys/traceAnalyzer/tracefiletab.h index fdd0374e..5ae2b116 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.h +++ b/DRAMSys/traceAnalyzer/tracefiletab.h @@ -47,6 +47,7 @@ #include "presentation/traceplot.h" #include "presentation/tracescroller.h" #include "businessObjects/configmodels.h" +#include "businessObjects/dependencymodels.h" class CommentModel; @@ -66,6 +67,8 @@ public: void setUpTraceplotScrollbar(); void setUpTraceSelector(); void setUpCommentView(); + void setUpPossiblePhases(); + void initNavigatorAndItsDependentWidgets(QString path); QString getPathToTraceFile() { diff --git a/DRAMSys/traceAnalyzer/tracefiletab.ui b/DRAMSys/traceAnalyzer/tracefiletab.ui index f2cac71d..31e8134a 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.ui +++ b/DRAMSys/traceAnalyzer/tracefiletab.ui @@ -209,16 +209,20 @@ - - - Calculate Dependencies + + + true - - - true + + + + + + + Calculate Dependencies From 4e7b5995cd77687b6e3300afb936ff36950e8251 Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Mon, 13 Dec 2021 16:42:47 +0100 Subject: [PATCH 13/14] Closing database before removal. --- DRAMSys/traceAnalyzer/data/tracedb.cpp | 40 ++++++++++++++++++-------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/DRAMSys/traceAnalyzer/data/tracedb.cpp b/DRAMSys/traceAnalyzer/data/tracedb.cpp index 47d12cf4..c7d5d57f 100644 --- a/DRAMSys/traceAnalyzer/data/tracedb.cpp +++ b/DRAMSys/traceAnalyzer/data/tracedb.cpp @@ -61,8 +61,8 @@ TraceDB::TraceDB(QString path, bool openExisting) database = QSqlDatabase::database(path); if (database.isValid() && database.isOpen()) { // Close the database connection if it exists and was not closed yet. - database.removeDatabase(path); database.close(); + QSqlDatabase::removeDatabase(path); } database = QSqlDatabase::addDatabase("QSQLITE", path); @@ -81,28 +81,44 @@ TraceDB::TraceDB(QString path, bool openExisting) void TraceDB::prepareQueries() { selectTransactionsByTimespan = QSqlQuery(database); - selectTransactionsByTimespan.prepare(queryTexts.selectTransactionsByTimespan); - selectTransactionById = QSqlQuery(database); + if (!selectTransactionsByTimespan.prepare(queryTexts.selectTransactionsByTimespan)) + qDebug() << database.lastError().text(); + + selectTransactionById = QSqlQuery(database); + if (!selectTransactionById.prepare(queryTexts.selectTransactionById)) + qDebug() << database.lastError().text(); - selectTransactionById.prepare(queryTexts.selectTransactionById); selectDebugMessagesByTimespan = QSqlQuery(database); - selectDebugMessagesByTimespan.prepare("SELECT time, Message FROM DebugMessages WHERE :begin <= time AND time <= :end "); + if (!selectDebugMessagesByTimespan.prepare("SELECT time, Message FROM DebugMessages WHERE :begin <= time AND time <= :end ")) + qDebug() << database.lastError().text(); + selectDebugMessagesByTimespanWithLimit = QSqlQuery(database); - selectDebugMessagesByTimespanWithLimit.prepare("SELECT time, Message FROM DebugMessages WHERE :begin <= time AND time <= :end LIMIT :limit"); + if (!selectDebugMessagesByTimespanWithLimit.prepare("SELECT time, Message FROM DebugMessages WHERE :begin <= time AND time <= :end LIMIT :limit")) + qDebug() << database.lastError().text(); checkDependenciesExist = QSqlQuery(database); - checkDependenciesExist.prepare(queryTexts.checkDependenciesExist); + if (!checkDependenciesExist.prepare(queryTexts.checkDependenciesExist)) + qDebug() << database.lastError().text(); + selectDependenciesByTimespan = QSqlQuery(database); - selectDependenciesByTimespan.prepare(queryTexts.selectDependenciesByTimespan); + if (!selectDependenciesByTimespan.prepare(queryTexts.selectDependenciesByTimespan)) + qDebug() << database.lastError().text(); selectDependencyTypePercentages = QSqlQuery(database); - selectDependencyTypePercentages.prepare(queryTexts.selectDependencyTypePercentages); + if (!selectDependencyTypePercentages.prepare(queryTexts.selectDependencyTypePercentages)) + qDebug() << database.lastError().text(); + selectTimeDependencyPercentages = QSqlQuery(database); - selectTimeDependencyPercentages.prepare(queryTexts.selectTimeDependencyPercentages); + if (!selectTimeDependencyPercentages.prepare(queryTexts.selectTimeDependencyPercentages)) + qDebug() << database.lastError().text(); + selectDelayedPhasePercentages = QSqlQuery(database); - selectDelayedPhasePercentages.prepare(queryTexts.selectDelayedPhasePercentages); + if (!selectDelayedPhasePercentages.prepare(queryTexts.selectDelayedPhasePercentages)) + qDebug() << database.lastError().text(); + selectDependencyPhasePercentages = QSqlQuery(database); - selectDependencyPhasePercentages.prepare(queryTexts.selectDependencyPhasePercentages); + if (!selectDependencyPhasePercentages.prepare(queryTexts.selectDependencyPhasePercentages)) + qDebug() << database.lastError().text(); } void TraceDB::updateComments(const std::vector &comments) From 6f14e6e23ff7f2ee005854c3837b5386bcd7ae99 Mon Sep 17 00:00:00 2001 From: Iron Prando da Silva Date: Wed, 15 Dec 2021 11:33:05 +0100 Subject: [PATCH 14/14] Added INT types to ID columns in DirectDependencies table creation. --- .../traceAnalyzer/businessObjects/phasedependenciestracker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp index 0c2c6450..ccd0665c 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/phasedependenciestracker.cpp @@ -34,7 +34,7 @@ void PhaseDependenciesTracker::mDropTable(TraceDB& tdb) { } void PhaseDependenciesTracker::mCreateTable(TraceDB& tdb) { - QString command = "CREATE TABLE DirectDependencies( DelayedPhaseID, DelayedPhaseName, DependencyType, TimeDependency, DependencyPhaseID, DependencyPhaseName ); "; + QString command = "CREATE TABLE DirectDependencies( DelayedPhaseID INT, DelayedPhaseName, DependencyType, TimeDependency, DependencyPhaseID INT, DependencyPhaseName ); "; auto query = mExecuteQuery(tdb, command); query.finish();