1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-05-05 05:34:00 -04:00

Profiler: Add maximum time coloumn. Add global runtime.

This commit is contained in:
Jon Beniston 2026-03-25 15:29:49 +00:00
parent 6baa38f887
commit 2a366b875a
6 changed files with 80 additions and 4 deletions

View File

@ -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) {

View File

@ -22,6 +22,7 @@
QHash<QString, ProfileData> GlobalProfileData::m_profileData;
QMutex GlobalProfileData::m_mutex;
QElapsedTimer GlobalProfileData::m_startTimer;
QHash<QString, ProfileData>& GlobalProfileData::getProfileData()
{
@ -38,5 +39,6 @@ void GlobalProfileData::resetProfileData()
{
m_mutex.lock();
m_profileData.clear();
m_startTimer.start();
m_mutex.unlock();
}

View File

@ -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<QString, ProfileData>& getProfileData();
static void releaseProfileData();
static void resetProfileData();
static qint64 getMSSinceStart() { return m_startTimer.elapsed(); }
private:
static QHash<QString, ProfileData> m_profileData;
static QMutex m_mutex;
static QElapsedTimer m_startTimer;
};

View File

@ -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);
}

View File

@ -52,6 +52,7 @@ private:
COL_TOTAL,
COL_AVERAGE,
COL_LAST,
COL_MAX,
COL_NUM_SAMPLES
};

View File

@ -24,7 +24,41 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="layout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="timeLabel">
<property name="text">
<string>Runtime</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="time">
<property name="toolTip">
<string>Elapsed run-time since reset button pressed</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="table">
<column>
@ -59,6 +93,14 @@
<string>Time for last execution of the code</string>
</property>
</column>
<column>
<property name="text">
<string>Max</string>
</property>
<property name="toolTip">
<string>Maximum length of time taken to execute the code</string>
</property>
</column>
<column>
<property name="text">
<string>Samples</string>
@ -74,10 +116,10 @@
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Reset</set>
<set>QDialogButtonBox::StandardButton::Close|QDialogButtonBox::StandardButton::Reset</set>
</property>
</widget>
</item>