From 09f8c04bb6397b54e291a08f6957e5a596a5d81b Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Tue, 31 Dec 2024 22:29:01 +0100 Subject: [PATCH] GUI: Cache dock move work to paint event --- src/gui/windows/cache/cachedock.cpp | 50 ++++++++++++++++++----------- src/gui/windows/cache/cachedock.h | 11 +++++++ 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/gui/windows/cache/cachedock.cpp b/src/gui/windows/cache/cachedock.cpp index 0efaea42..e70c6ce5 100644 --- a/src/gui/windows/cache/cachedock.cpp +++ b/src/gui/windows/cache/cachedock.cpp @@ -39,6 +39,14 @@ CacheDock::CacheDock(QWidget *parent, const QString &type) } void CacheDock::setup(const machine::Cache *cache, bool cache_after_cache) { + memory_reads = 0; + memory_writes = 0; + hit = 0; + miss = 0; + stalled = 0; + speed_improv = 0.0; + hit_rate = 0.0; + l_hit->setText("0"); l_miss->setText("0"); l_stalled->setText("0"); @@ -48,19 +56,12 @@ void CacheDock::setup(const machine::Cache *cache, bool cache_after_cache) { l_speed->setText("100%"); l_speed->setHidden(cache_after_cache); if (cache != nullptr) { + connect(cache, &machine::Cache::hit_update, this, &CacheDock::hit_update); + connect(cache, &machine::Cache::miss_update, this, &CacheDock::miss_update); + connect(cache, &machine::Cache::memory_reads_update, this, &CacheDock::memory_reads_update); connect( - cache, &machine::Cache::hit_update, this, &CacheDock::hit_update); - connect( - cache, &machine::Cache::miss_update, this, &CacheDock::miss_update); - connect( - cache, &machine::Cache::memory_reads_update, this, - &CacheDock::memory_reads_update); - connect( - cache, &machine::Cache::memory_writes_update, this, - &CacheDock::memory_writes_update); - connect( - cache, &machine::Cache::statistics_update, this, - &CacheDock::statistics_update); + cache, &machine::Cache::memory_writes_update, this, &CacheDock::memory_writes_update); + connect(cache, &machine::Cache::statistics_update, this, &CacheDock::statistics_update); } top_form->setVisible(cache != nullptr); no_cache->setVisible(cache == nullptr || !cache->get_config().enabled()); @@ -71,27 +72,38 @@ void CacheDock::setup(const machine::Cache *cache, bool cache_after_cache) { graphicsview->setVisible(cache != nullptr && cache->get_config().enabled()); } +void CacheDock::paintEvent(QPaintEvent *event) { + l_stalled->setText(QString::number(stalled)); + l_hit_rate->setText(QString::number(hit_rate, 'f', 3) + QString("%")); + l_speed->setText(QString::number(speed_improv, 'f', 0) + QString("%")); + l_hit->setText(QString::number(hit)); + l_miss->setText(QString::number(miss)); + l_m_reads->setText(QString::number(memory_reads)); + l_m_writes->setText(QString::number(memory_writes)); + QDockWidget::paintEvent(event); +} + void CacheDock::hit_update(unsigned val) { - l_hit->setText(QString::number(val)); + hit = val; } void CacheDock::miss_update(unsigned val) { - l_miss->setText(QString::number(val)); + miss = val; } void CacheDock::memory_reads_update(unsigned val) { - l_m_reads->setText(QString::number(val)); + memory_reads = val; } void CacheDock::memory_writes_update(unsigned val) { - l_m_writes->setText(QString::number(val)); + memory_writes = val; } void CacheDock::statistics_update( unsigned stalled_cycles, double speed_improv, double hit_rate) { - l_stalled->setText(QString::number(stalled_cycles)); - l_hit_rate->setText(QString::number(hit_rate, 'f', 3) + QString("%")); - l_speed->setText(QString::number(speed_improv, 'f', 0) + QString("%")); + this->stalled = stalled_cycles; + this->hit = hit_rate; + this->speed_improv = speed_improv; } diff --git a/src/gui/windows/cache/cachedock.h b/src/gui/windows/cache/cachedock.h index 867857f3..b50945d1 100644 --- a/src/gui/windows/cache/cachedock.h +++ b/src/gui/windows/cache/cachedock.h @@ -16,6 +16,8 @@ class CacheDock : public QDockWidget { void setup(const machine::Cache *cache, bool cache_after_cache = false); + void paintEvent(QPaintEvent *event) override; + private slots: void hit_update(unsigned); void miss_update(unsigned); @@ -35,6 +37,15 @@ private slots: QLabel *l_m_reads, *l_m_writes; GraphicsView *graphicsview; CacheViewScene *cachescene; + + // Statistics + unsigned memory_reads = 0; + unsigned memory_writes = 0; + unsigned hit = 0; + unsigned miss = 0; + unsigned stalled = 0; + double speed_improv = 0.0; + double hit_rate = 0.0; }; #endif // CACHEDOCK_H