Skip to content

Commit

Permalink
GUI: Cache dock move work to paint event
Browse files Browse the repository at this point in the history
  • Loading branch information
jdupak committed Dec 31, 2024
1 parent a7f185d commit 09f8c04
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
50 changes: 31 additions & 19 deletions src/gui/windows/cache/cachedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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());
Expand All @@ -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;
}
11 changes: 11 additions & 0 deletions src/gui/windows/cache/cachedock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

0 comments on commit 09f8c04

Please sign in to comment.