Add clock rate display to ProcessorTab
MODIFY
src/processortab.cpp
src/processortab.cpp
namespace Ripes {
+namespace {
+//
+inline QString convertToSIUnits(const double l_value, int precision = 2) {
+ QString unit;
+ double value;
+
+ if (l_value < 0) {
+ value = l_value * -1;
+ } else {
+ value = l_value;
+ }
+
+ if (value >= 1000000 && value < 1000000000) {
+ value = value / 1000000;
+ unit = "M";
+ } else if (value >= 1000 && value < 1000000) {
+ value = value / 1000;
+ unit = "K";
+ } else if (value >= 1 && value < 1000) {
+ value = value * 1;
+ } else if ((value * 1000) >= 1 && value < 1000) {
+ value = value * 1000;
+ unit = "m";
+ } else if ((value * 1000000) >= 1 && value < 1000000) {
+ value = value * 1000000;
+ unit = QChar(0x00B5);
+ } else if ((value * 1000000000) >= 1 && value < 1000000000) {
+ value = value * 1000000000;
+ unit = "n";
+ }
+
+ if (l_value > 0) {
+ return (QString::number(value, 10, precision) + " " + unit);
+ } else if (l_value < 0) {
+ return (QString::number(value * -1, 10, precision) + " " + unit);
+ }
+ return QString::number(0) + " ";
+}
+} // namespace
+
ProcessorTab::ProcessorTab(QToolBar* controlToolbar, QToolBar* additionalToolbar, QWidget* parent)
: RipesTab(additionalToolbar, parent), m_ui(new Ui::ProcessorTab) {
m_ui->setupUi(this);
@@ -192,19 +232,38 @@ void ProcessorTab::setupSimulatorActions(QToolBar* controlToolbar) {
}
void ProcessorTab::updateStatistics() {
- const auto cycles = ProcessorHandler::get()->getProcessor()->getCycleCount();
+ static auto lastUpdateTime = std::chrono::system_clock::now();
+ static long long lastCycleCount = ProcessorHandler::get()->getProcessor()->getCycleCount();
+
+ const auto timeNow = std::chrono::system_clock::now();
+ const auto cycleCount = ProcessorHandler::get()->getProcessor()->getCycleCount();
const auto instrsRetired = ProcessorHandler::get()->getProcessor()->getInstructionsRetired();
- m_ui->cycleCount->setText(QString::number(cycles));
+ const auto timeDiff =
+ std::chrono::duration_cast<std::chrono::milliseconds>(timeNow - lastUpdateTime).count() / 1000.0; // in seconds
+ const auto cycleDiff = cycleCount - lastCycleCount;
+
+ // Cycle count
+ m_ui->cycleCount->setText(QString::number(cycleCount));
+ // Instructions retired
m_ui->instructionsRetired->setText(QString::number(instrsRetired));
QString cpiText, ipcText;
- if (cycles != 0 && instrsRetired != 0) {
- const double cpi = static_cast<double>(cycles) / static_cast<double>(instrsRetired);
+ if (cycleCount != 0 && instrsRetired != 0) {
+ const double cpi = static_cast<double>(cycleCount) / static_cast<double>(instrsRetired);
const double ipc = 1 / cpi;
cpiText = QString::number(cpi, 'g', 3);
ipcText = QString::number(ipc, 'g', 3);
}
+ // CPI & IPC
m_ui->cpi->setText(cpiText);
m_ui->ipc->setText(ipcText);
+
+ // Clock rate
+ const double clockRate = static_cast<double>(cycleDiff) / timeDiff;
+ m_ui->clockRate->setText(convertToSIUnits(clockRate) + "Hz");
+
+ // Record timestamp values
+ lastUpdateTime = timeNow;
+ lastCycleCount = cycleCount;
}
void ProcessorTab::pause() {

MODIFY
src/processortab.h
src/processortab.h
@@ -37,6 +37,7 @@ public:
signals:
void update();
+ void processorWasReset();
void appendToLog(QString string);
public slots:

MODIFY
src/processortab.ui
src/processortab.ui
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
- <string>Statistics</string>
+ <string>Execution info</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_7">
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="instructionsRetired">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="toolTip">
</property>
</widget>
</item>
- <item row="0" column="0">
- <widget class="QLabel" name="label_3">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Cycles:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
- </property>
- <property name="textFormat">
- <enum>Qt::RichText</enum>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLineEdit" name="cycleCount">
+ <item row="2" column="1">
+ <widget class="QLineEdit" name="cpi">
<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="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</property>
</widget>
</item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="toolTip">
+ <string>Instructions per cycle</string>
+ </property>
+ <property name="text">
+ <string>IPC:</string>
+ </property>
+ </widget>
+ </item>
<item row="1" column="0">
<widget class="QLabel" name="nInstrExecutedLabel">
<property name="sizePolicy">
</property>
</widget>
</item>
- <item row="2" column="1">
- <widget class="QLineEdit" name="cpi">
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="cycleCount">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QLineEdit" name="ipc">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="minimumSize">
<size>
<width>0</width>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
</widget>
</item>
- <item row="1" column="1">
- <widget class="QLineEdit" name="instructionsRetired">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_3">
<property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ <property name="text">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Cycles:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
- <property name="readOnly">
- <bool>true</bool>
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
</property>
</widget>
</item>
- <item row="3" column="0">
- <widget class="QLabel" name="label_2">
- <property name="toolTip">
- <string>Instructions per cycle</string>
- </property>
+ <item row="4" column="0">
+ <widget class="QLabel" name="label_4">
<property name="text">
- <string>IPC:</string>
+ <string>Clock rate:</string>
</property>
</widget>
</item>
- <item row="3" column="1">
- <widget class="QLineEdit" name="ipc">
+ <item row="4" column="1">
+ <widget class="QLineEdit" name="clockRate">
<property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <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="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
</widget>
</item>
</layout>

Add clock rate display to ProcessorTab