Move cache size breakdown calculation to CachePlotWidget
MODIFY
src/cachesim/cacheconfigwidget.cpp
src/cachesim/cacheconfigwidget.cpp
@@ -23,9 +23,6 @@ CacheConfigWidget::CacheConfigWidget(QWidget* parent) : QWidget(parent), m_ui(ne
void CacheConfigWidget::setCache(std::shared_ptr<CacheSim>& cache) {
m_cache = cache;
- const QIcon sizeBreakdownIcon = QIcon(":/icons/info.svg");
- m_ui->sizeBreakdownButton->setIcon(sizeBreakdownIcon);
-
setupEnumCombobox(m_ui->replacementPolicy, s_cacheReplPolicyStrings);
setupEnumCombobox(m_ui->wrHit, s_cacheWritePolicyStrings);
setupEnumCombobox(m_ui->wrMiss, s_cacheWriteAllocateStrings);
@@ -37,7 +34,6 @@ void CacheConfigWidget::setCache(std::shared_ptr<CacheSim>& cache) {
connect(m_ui->ways, QOverload<int>::of(&QSpinBox::valueChanged), m_cache.get(), &CacheSim::setWays);
connect(m_ui->blocks, QOverload<int>::of(&QSpinBox::valueChanged), m_cache.get(), &CacheSim::setBlocks);
connect(m_ui->lines, QOverload<int>::of(&QSpinBox::valueChanged), m_cache.get(), &CacheSim::setLines);
- connect(m_ui->sizeBreakdownButton, &QPushButton::clicked, this, &CacheConfigWidget::showSizeBreakdown);
connect(m_ui->replacementPolicy, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index) {
m_cache->setReplacementPolicy(qvariant_cast<CacheSim::ReplPolicy>(m_ui->replacementPolicy->itemData(index)));
@@ -51,7 +47,6 @@ void CacheConfigWidget::setCache(std::shared_ptr<CacheSim>& cache) {
connect(m_cache.get(), &CacheSim::configurationChanged, this, &CacheConfigWidget::handleConfigurationChanged);
connect(m_cache.get(), &CacheSim::configurationChanged, [=] { emit configurationChanged(); });
- connect(m_cache.get(), &CacheSim::hitrateChanged, this, &CacheConfigWidget::updateHitrate);
setupPresets();
handleConfigurationChanged();
@@ -107,30 +102,6 @@ void CacheConfigWidget::handleConfigurationChanged() {
m_justSetPreset = false;
std::for_each(m_configItems.begin(), m_configItems.end(), [](QObject* o) { o->blockSignals(false); });
-
- m_ui->size->setText(QString::number(m_cache->getCacheSize().bits));
- updateHitrate();
-}
-
-void CacheConfigWidget::updateHitrate() {
- m_ui->hitrate->setText(QString::number(m_cache->getHitRate(), 'G', 4));
- m_ui->hits->setText(QString::number(m_cache->getHits()));
- m_ui->misses->setText(QString::number(m_cache->getMisses()));
- m_ui->writebacks->setText(QString::number(m_cache->getWritebacks()));
-}
-
-void CacheConfigWidget::showSizeBreakdown() {
- QString sizeText;
-
- const auto cacheSize = m_cache->getCacheSize();
-
- for (const auto& component : cacheSize.components) {
- sizeText += component + "\n";
- }
-
- sizeText += "\nTotal: " + QString::number(cacheSize.bits) + " Bits";
-
- QMessageBox::information(this, "Cache Size Breakdown", sizeText);
}
CacheConfigWidget::~CacheConfigWidget() {

MODIFY
src/cachesim/cacheconfigwidget.h
src/cachesim/cacheconfigwidget.h
@@ -22,7 +22,6 @@ signals:
void configurationChanged();
public slots:
- void updateHitrate();
void handleConfigurationChanged();
private:

MODIFY
src/cachesim/cacheconfigwidget.ui
src/cachesim/cacheconfigwidget.ui
<x>0</x>
<y>0</y>
<width>637</width>
- <height>175</height>
+ <height>191</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
- <property name="leftMargin">
- <number>0</number>
- </property>
- <property name="topMargin">
- <number>0</number>
- </property>
- <property name="rightMargin">
- <number>0</number>
- </property>
- <property name="bottomMargin">
- <number>0</number>
- </property>
- <property name="spacing">
- <number>0</number>
- </property>
<item row="0" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0">
- <item>
- <layout class="QVBoxLayout" name="verticalLayout_4">
+ <layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
- <item row="6" column="0">
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;2&lt;span style=&quot; vertical-align:super;&quot;&gt;N&lt;/span&gt; Blocks:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ <item row="6" column="1">
+ <widget class="QSpinBox" name="blocks">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="maximum">
+ <number>10</number>
</property>
</widget>
</item>
- <item row="6" column="3">
- <widget class="QComboBox" name="wrMiss"/>
- </item>
- <item row="5" column="3">
- <widget class="QComboBox" name="wrHit"/>
- </item>
<item row="6" column="2">
<widget class="QLabel" name="label_10">
<property name="text">
</property>
</widget>
</item>
- <item row="4" column="0">
- <widget class="QLabel" name="label_4">
+ <item row="6" column="0">
+ <widget class="QLabel" name="label_3">
<property name="text">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;2&lt;span style=&quot; vertical-align:super;&quot;&gt;N&lt;/span&gt; Lines:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;2&lt;span style=&quot; vertical-align:super;&quot;&gt;N&lt;/span&gt; Blocks:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</property>
</widget>
</item>
- <item row="5" column="2">
- <widget class="QLabel" name="label_9">
- <property name="text">
- <string>Wr. hit:</string>
- </property>
- </widget>
- </item>
<item row="4" column="3">
<widget class="QComboBox" name="replacementPolicy"/>
</item>
- <item row="4" column="2">
- <widget class="QLabel" name="label_8">
+ <item row="4" column="0">
+ <widget class="QLabel" name="label_4">
<property name="text">
- <string>Repl. policy:</string>
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;2&lt;span style=&quot; vertical-align:super;&quot;&gt;N&lt;/span&gt; Lines:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
- <item row="4" column="1">
- <widget class="QSpinBox" name="lines">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="maximum">
- <number>10</number>
+ <item row="5" column="2">
+ <widget class="QLabel" name="label_9">
+ <property name="text">
+ <string>Wr. hit:</string>
</property>
</widget>
</item>
</property>
</widget>
</item>
- <item row="6" column="1">
- <widget class="QSpinBox" name="blocks">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="maximum">
- <number>10</number>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QVBoxLayout" name="verticalLayout_6">
- <item>
- <widget class="QGroupBox" name="groupBox_2">
- <property name="title">
- <string>Statistics:</string>
- </property>
- <layout class="QGridLayout" name="gridLayout_5">
- <item row="0" column="0">
- <layout class="QVBoxLayout" name="verticalLayout_3">
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_7">
- <item>
- <widget class="QLabel" name="label_6">
- <property name="text">
- <string>Size (bits):</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="size">
- <property name="sizePolicy">
- <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- <property name="readOnly">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QToolButton" name="sizeBreakdownButton">
- <property name="text">
- <string>...</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
+ <item row="6" column="3">
+ <widget class="QComboBox" name="wrMiss"/>
</item>
- <item row="1" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout_4">
- <item>
- <layout class="QGridLayout" name="gridLayout_6">
- <item row="0" column="1">
- <widget class="QLineEdit" name="hitrate">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- <property name="readOnly">
- <bool>true</bool>
- </property>
- </widget>
+ <item row="5" column="3">
+ <widget class="QComboBox" name="wrHit"/>
</item>
- <item row="0" column="2">
- <widget class="QLabel" name="label_7">
+ <item row="4" column="2">
+ <widget class="QLabel" name="label_8">
<property name="text">
- <string>Writebacks:</string>
+ <string>Repl. policy:</string>
</property>
</widget>
</item>
- <item row="0" column="3">
- <widget class="QLineEdit" name="writebacks">
+ <item row="4" column="1">
+ <widget class="QSpinBox" name="lines">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- <property name="readOnly">
- <bool>true</bool>
+ <property name="maximum">
+ <number>10</number>
</property>
</widget>
</item>
- <item row="0" column="0">
+ <item row="4" column="4">
<widget class="QLabel" name="label_5">
<property name="text">
- <string>Hit rate:</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_11">
- <property name="text">
- <string>Hits:</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QLineEdit" name="hits">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- <property name="readOnly">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="1" column="2">
- <widget class="QLabel" name="label_12">
- <property name="text">
- <string>Misses:</string>
+ <string>Acc. latency:</string>
</property>
</widget>
</item>
- <item row="1" column="3">
- <widget class="QLineEdit" name="misses">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
+ <item row="4" column="5">
+ <widget class="QSpinBox" name="spinBox">
+ <property name="minimum">
+ <number>0</number>
</property>
- <property name="readOnly">
- <bool>true</bool>
+ <property name="maximum">
+ <number>99999</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
- </item>
- </layout>
</widget>
<resources/>
<connections/>

MODIFY
src/cachesim/cacheplotwidget.cpp
src/cachesim/cacheplotwidget.cpp
#include <QClipboard>
#include <QFileDialog>
+#include <QPushButton>
#include <QToolBar>
#include <QtCharts/QAreaSeries>
#include <QtCharts/QChartView>
@@ -94,15 +95,38 @@ CachePlotWidget::CachePlotWidget(QWidget* parent) : QWidget(parent), m_ui(new Ui
connect(m_ui->plotType, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&CachePlotWidget::plotTypeChanged);
+
+ const QIcon sizeBreakdownIcon = QIcon(":/icons/info.svg");
+ m_ui->sizeBreakdownButton->setIcon(sizeBreakdownIcon);
+ connect(m_ui->sizeBreakdownButton, &QPushButton::clicked, this, &CachePlotWidget::showSizeBreakdown);
+}
+
+void CachePlotWidget::showSizeBreakdown() {
+ QString sizeText;
+
+ const auto cacheSize = m_cache->getCacheSize();
+
+ for (const auto& component : cacheSize.components) {
+ sizeText += component + "\n";
+ }
+
+ sizeText += "\nTotal: " + QString::number(cacheSize.bits) + " Bits";
+
+ QMessageBox::information(this, "Cache Size Breakdown", sizeText);
}
void CachePlotWidget::setCache(std::shared_ptr<CacheSim> cache) {
m_cache = cache;
+ connect(m_cache.get(), &CacheSim::hitrateChanged, this, &CachePlotWidget::updateHitrate);
+ connect(m_cache.get(), &CacheSim::configurationChanged,
+ [=] { m_ui->size->setText(QString::number(m_cache->getCacheSize().bits)); });
+
// Synchronize widget state
plotTypeChanged();
variablesChanged();
rangeChanged();
+ updateHitrate();
}
CachePlotWidget::~CachePlotWidget() {
@@ -430,4 +454,11 @@ void CachePlotWidget::setPlot(QChart* plot) {
m_ui->plotView->setPlot(m_currentPlot);
}
+void CachePlotWidget::updateHitrate() {
+ m_ui->hitrate->setText(QString::number(m_cache->getHitRate(), 'G', 4));
+ m_ui->hits->setText(QString::number(m_cache->getHits()));
+ m_ui->misses->setText(QString::number(m_cache->getMisses()));
+ m_ui->writebacks->setText(QString::number(m_cache->getWritebacks()));
+}
+
} // namespace Ripes

MODIFY
src/cachesim/cacheplotwidget.h
src/cachesim/cacheplotwidget.h
@@ -39,6 +39,7 @@ private slots:
void variablesChanged();
void rangeChanged();
void plotTypeChanged();
+ void updateHitrate();
private:
/**
@@ -49,6 +50,7 @@ private:
std::map<Variable, QList<QPoint>> gatherData(unsigned fromCycle = 0) const;
void setupToolbar();
void setupStackedVariablesList();
+ void showSizeBreakdown();
void setPlot(QChart* plot);
void copyPlotDataToClipboard() const;
void savePlot();

MODIFY
src/cachesim/cacheplotwidget.ui
src/cachesim/cacheplotwidget.ui
<rect>
<x>0</x>
<y>0</y>
- <width>893</width>
- <height>536</height>
+ <width>617</width>
+ <height>330</height>
</rect>
</property>
<property name="windowTitle">
<rect>
<x>0</x>
<y>0</y>
- <width>676</width>
- <height>106</height>
+ <width>221</width>
+ <height>214</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
</widget>
</widget>
</item>
+ <item>
+ <widget class="QGroupBox" name="groupBox_2">
+ <property name="title">
+ <string>Statistics:</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_5">
+ <item row="0" column="0">
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_7">
+ <item>
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Size (bits):</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="size">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="sizeBreakdownButton">
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0">
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <layout class="QGridLayout" name="gridLayout_6">
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="hitrate">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QLabel" name="label_7">
+ <property name="text">
+ <string>Writebacks:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3">
+ <widget class="QLineEdit" name="writebacks">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Hit rate:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_11">
+ <property name="text">
+ <string>Hits:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="hits">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QLabel" name="label_12">
+ <property name="text">
+ <string>Misses:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="3">
+ <widget class="QLineEdit" name="misses">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
</layout>
</item>
<item>

Move cache size breakdown calculation to CachePlotWidget