diff --git a/app/main.cpp b/app/main.cpp index 4d9d4d93b..bb5318197 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -50,6 +50,7 @@ #include "mainwindow.h" #include "remotetcpsinkstarter.h" #include "dsp/dsptypes.h" +#include "util/profiler.h" #include "crashhandler.h" static void logExceptionStackTrace() @@ -340,6 +341,10 @@ int main(int argc, char* argv[]) installCrashHandler(logger); #endif +#ifdef ENABLE_PROFILER + GlobalProfileData::resetProfileData(); // Start timer +#endif + int res = runQtApplication(argc, argv, logger); if (logger) { diff --git a/sdrbase/util/profiler.cpp b/sdrbase/util/profiler.cpp index 4ec5a45be..081532ce7 100644 --- a/sdrbase/util/profiler.cpp +++ b/sdrbase/util/profiler.cpp @@ -22,6 +22,7 @@ QHash GlobalProfileData::m_profileData; QMutex GlobalProfileData::m_mutex; +QElapsedTimer GlobalProfileData::m_startTimer; QHash& GlobalProfileData::getProfileData() { @@ -38,5 +39,6 @@ void GlobalProfileData::resetProfileData() { m_mutex.lock(); m_profileData.clear(); + m_startTimer.start(); m_mutex.unlock(); } diff --git a/sdrbase/util/profiler.h b/sdrbase/util/profiler.h index 2e17f23db..8bdcd9b7a 100644 --- a/sdrbase/util/profiler.h +++ b/sdrbase/util/profiler.h @@ -68,19 +68,22 @@ public: ProfileData() : m_numSamples(0), m_last(0), - m_total(0) + m_total(0), + m_max(0) { } void reset() { m_numSamples = 0; m_total = 0; + m_max = 0; } void add(qint64 sample) { m_last = sample; m_total += sample; + m_max = std::max(m_max, sample); m_numSamples++; } @@ -95,12 +98,14 @@ public: qint64 getTotal() const { return m_total; } qint64 getLast() const { return m_last; } + qint64 getMax() const { return m_max; } quint64 getNumSamples() const { return m_numSamples; } private: quint64 m_numSamples; qint64 m_last; qint64 m_total; + qint64 m_max; }; // Global thread-safe profile data that can be displayed in the GUI @@ -112,11 +117,13 @@ public: static QHash& getProfileData(); static void releaseProfileData(); static void resetProfileData(); + static qint64 getMSSinceStart() { return m_startTimer.elapsed(); } private: static QHash m_profileData; static QMutex m_mutex; + static QElapsedTimer m_startTimer; }; diff --git a/sdrgui/gui/profiledialog.cpp b/sdrgui/gui/profiledialog.cpp index 25127fe41..24f319a1c 100644 --- a/sdrgui/gui/profiledialog.cpp +++ b/sdrgui/gui/profiledialog.cpp @@ -59,6 +59,7 @@ void ProfileDialog::resizeTable() ui->table->setItem(row, COL_TOTAL, new QTableWidgetItem("1000.000 ms")); ui->table->setItem(row, COL_AVERAGE, new QTableWidgetItem("1000.000 ns/frame")); ui->table->setItem(row, COL_LAST, new QTableWidgetItem("1000.000 ms")); + ui->table->setItem(row, COL_MAX, new QTableWidgetItem("1000.000 ms")); ui->table->setItem(row, COL_NUM_SAMPLES, new QTableWidgetItem("1000000000")); ui->table->resizeColumnsToContents(); ui->table->setRowCount(row); @@ -79,6 +80,7 @@ void ProfileDialog::updateData() double totalTime = data.getTotal(); double averageTime = data.getAverage(); double lastTime = data.getLast(); + double maxTime = data.getMax(); int i = 0; for (; i < ui->table->rowCount(); i++) @@ -90,6 +92,7 @@ void ProfileDialog::updateData() ui->table->item(i, COL_TOTAL)->setData(Qt::DisplayRole, totalTime); ui->table->item(i, COL_AVERAGE)->setData(Qt::DisplayRole, averageTime); ui->table->item(i, COL_LAST)->setData(Qt::DisplayRole, lastTime); + ui->table->item(i, COL_MAX)->setData(Qt::DisplayRole, maxTime); ui->table->item(i, COL_NUM_SAMPLES)->setData(Qt::DisplayRole, data.getNumSamples()); break; } @@ -105,31 +108,47 @@ void ProfileDialog::updateData() QTableWidgetItem *total = new QTableWidgetItem(); QTableWidgetItem *average = new QTableWidgetItem(); QTableWidgetItem *last = new QTableWidgetItem(); + QTableWidgetItem *max = new QTableWidgetItem(); QTableWidgetItem *numSamples = new QTableWidgetItem(); ui->table->setItem(row, COL_NAME, name); ui->table->setItem(row, COL_TOTAL, total); ui->table->setItem(row, COL_AVERAGE, average); ui->table->setItem(row, COL_LAST, last); + ui->table->setItem(row, COL_MAX, max); ui->table->setItem(row, COL_NUM_SAMPLES, numSamples); total->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); average->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); last->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); + max->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); numSamples->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); total->setData(Qt::DisplayRole, totalTime); average->setData(Qt::DisplayRole, averageTime); last->setData(Qt::DisplayRole, lastTime); + max->setData(Qt::DisplayRole, maxTime); numSamples->setData(Qt::DisplayRole, data.getNumSamples()); ui->table->setItemDelegateForColumn(COL_TOTAL, new NanoSecondsDelegate()); ui->table->setItemDelegateForColumn(COL_AVERAGE, new NanoSecondsDelegate()); ui->table->setItemDelegateForColumn(COL_LAST, new NanoSecondsDelegate()); + ui->table->setItemDelegateForColumn(COL_MAX, new NanoSecondsDelegate()); ui->table->setSortingEnabled(true); } } GlobalProfileData::releaseProfileData(); + + qint64 msecSinceStart = GlobalProfileData::getMSSinceStart(); + QString s; + + if (msecSinceStart < 1e3) { + s = QString("%1 ms").arg(msecSinceStart); + } else { + s = QString("%1 s").arg(msecSinceStart/1e3, 0, 'f', 3); + } + ui->time->setText(s); + } diff --git a/sdrgui/gui/profiledialog.h b/sdrgui/gui/profiledialog.h index a6a91e909..9cd2c2a04 100644 --- a/sdrgui/gui/profiledialog.h +++ b/sdrgui/gui/profiledialog.h @@ -52,6 +52,7 @@ private: COL_TOTAL, COL_AVERAGE, COL_LAST, + COL_MAX, COL_NUM_SAMPLES }; diff --git a/sdrgui/gui/profiledialog.ui b/sdrgui/gui/profiledialog.ui index 030ab6ccb..defb724a3 100644 --- a/sdrgui/gui/profiledialog.ui +++ b/sdrgui/gui/profiledialog.ui @@ -24,7 +24,41 @@ - + + + + + + + Runtime + + + + + + + Elapsed run-time since reset button pressed + + + true + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + @@ -59,6 +93,14 @@ Time for last execution of the code + + + Max + + + Maximum length of time taken to execute the code + + Samples @@ -74,10 +116,10 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - QDialogButtonBox::Close|QDialogButtonBox::Reset + QDialogButtonBox::StandardButton::Close|QDialogButtonBox::StandardButton::Reset