Skip to content

Commit 1702ca5

Browse files
committed
remove static functions from PerfRecord
1 parent 02005a7 commit 1702ca5

File tree

3 files changed

+44
-37
lines changed

3 files changed

+44
-37
lines changed

src/perfrecord.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ class PerfRecord : public QObject
4949
void stopRecording();
5050
void sendInput(const QByteArray& input);
5151

52-
static QString sudoUtil();
53-
static QString currentUsername();
52+
virtual QString sudoUtil();
53+
virtual QString currentUsername();
5454

55-
static bool canTrace(const QString& path);
56-
static bool canProfileOffCpu();
57-
static bool canSampleCpu();
58-
static bool canSwitchEvents();
59-
static bool canUseAio();
60-
static bool canCompress();
55+
virtual bool canTrace(const QString& path);
56+
virtual bool canProfileOffCpu();
57+
virtual bool canSampleCpu();
58+
virtual bool canSwitchEvents();
59+
virtual bool canUseAio();
60+
virtual bool canCompress();
6161

6262
static QStringList offCpuProfilingOptions();
6363

64-
static bool isPerfInstalled();
64+
virtual bool isPerfInstalled();
6565

6666
signals:
6767
void recordingStarted(const QString& perfBinary, const QStringList& arguments);

src/recordpage.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ RecordType selectedRecordType(const QScopedPointer<Ui::RecordPage>& ui)
9191
return ui->recordTypeComboBox->currentData().value<RecordType>();
9292
}
9393

94-
void updateStartRecordingButtonState(const QScopedPointer<Ui::RecordPage>& ui)
94+
void updateStartRecordingButtonState(PerfRecord* record, const QScopedPointer<Ui::RecordPage>& ui)
9595
{
96-
if (!PerfRecord::isPerfInstalled()) {
96+
if (!record->isPerfInstalled()) {
9797
ui->startRecordingButton->setEnabled(false);
9898
ui->applicationRecordErrorMessage->setText(QObject::tr("Please install perf before trying to record."));
9999
ui->applicationRecordErrorMessage->setVisible(true);
@@ -380,7 +380,7 @@ RecordPage::RecordPage(QWidget* parent)
380380
ui->processesTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
381381
ui->processesTableView->setSelectionMode(QAbstractItemView::MultiSelection);
382382
connect(ui->processesTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
383-
[this]() { updateStartRecordingButtonState(ui); });
383+
[this]() { updateStartRecordingButtonState(m_perfRecord, ui); });
384384

385385
ResultsUtil::connectFilter(ui->processesFilterBox, m_processProxyModel);
386386

@@ -406,7 +406,7 @@ RecordPage::RecordPage(QWidget* parent)
406406
ui->sampleCpuCheckBox->setChecked(config().readEntry(QStringLiteral("sampleCpu"), true));
407407
ui->mmapPagesSpinBox->setValue(config().readEntry(QStringLiteral("mmapPages"), 0));
408408
ui->mmapPagesUnitComboBox->setCurrentIndex(config().readEntry(QStringLiteral("mmapPagesUnit"), 2));
409-
ui->useAioCheckBox->setChecked(config().readEntry(QStringLiteral("useAio"), PerfRecord::canUseAio()));
409+
ui->useAioCheckBox->setChecked(config().readEntry(QStringLiteral("useAio"), m_perfRecord->canUseAio()));
410410

411411
const auto callGraph = config().readEntry("callGraph", ui->callGraphComboBox->currentData());
412412
const auto callGraphIdx = ui->callGraphComboBox->findData(callGraph);
@@ -438,19 +438,19 @@ RecordPage::RecordPage(QWidget* parent)
438438
}
439439
});
440440

441-
if (!PerfRecord::canSampleCpu()) {
441+
if (!m_perfRecord->canSampleCpu()) {
442442
ui->sampleCpuCheckBox->hide();
443443
ui->sampleCpuLabel->hide();
444444
}
445-
if (!PerfRecord::canSwitchEvents()) {
445+
if (!m_perfRecord->canSwitchEvents()) {
446446
ui->offCpuCheckBox->hide();
447447
ui->offCpuLabel->hide();
448448
}
449-
if (!PerfRecord::canUseAio()) {
449+
if (!m_perfRecord->canUseAio()) {
450450
ui->useAioCheckBox->hide();
451451
ui->useAioLabel->hide();
452452
}
453-
if (!PerfRecord::canCompress()) {
453+
if (!m_perfRecord->canCompress()) {
454454
ui->compressionComboBox->hide();
455455
ui->compressionLabel->hide();
456456
} else {
@@ -523,24 +523,24 @@ void RecordPage::onStartRecordingButtonClicked(bool checked)
523523
perfOptions += KShell::splitArgs(customOptions);
524524

525525
const bool offCpuProfilingEnabled = ui->offCpuCheckBox->isChecked();
526-
if (offCpuProfilingEnabled && PerfRecord::canSwitchEvents()) {
526+
if (offCpuProfilingEnabled && m_perfRecord->canSwitchEvents()) {
527527
if (eventType.isEmpty()) {
528528
// TODO: use clock event in VM context
529529
perfOptions += QStringLiteral("--event");
530530
perfOptions += QStringLiteral("cycles");
531531
}
532-
perfOptions += PerfRecord::offCpuProfilingOptions();
532+
perfOptions += m_perfRecord->offCpuProfilingOptions();
533533
}
534534
config().writeEntry(QStringLiteral("offCpuProfiling"), offCpuProfilingEnabled);
535535

536536
const bool useAioEnabled = ui->useAioCheckBox->isChecked();
537-
if (useAioEnabled && PerfRecord::canUseAio()) {
537+
if (useAioEnabled && m_perfRecord->canUseAio()) {
538538
perfOptions += QStringLiteral("--aio");
539539
}
540540
config().writeEntry(QStringLiteral("useAio"), useAioEnabled);
541541

542542
const auto compressionLevel = ui->compressionComboBox->currentData().toInt();
543-
if (PerfRecord::canCompress() && compressionLevel >= 0) {
543+
if (m_perfRecord->canCompress() && compressionLevel >= 0) {
544544
if (compressionLevel == 0)
545545
perfOptions += QStringLiteral("-z");
546546
else
@@ -551,7 +551,7 @@ void RecordPage::onStartRecordingButtonClicked(bool checked)
551551
const bool elevatePrivileges = ui->elevatePrivilegesCheckBox->isChecked();
552552

553553
const bool sampleCpuEnabled = ui->sampleCpuCheckBox->isChecked();
554-
if (sampleCpuEnabled && PerfRecord::canSampleCpu()) {
554+
if (sampleCpuEnabled && m_perfRecord->canSampleCpu()) {
555555
perfOptions += QStringLiteral("--sample-cpu");
556556
}
557557

@@ -672,7 +672,7 @@ void RecordPage::onApplicationNameChanged(const QString& filePath)
672672

673673
m_multiConfig->setConfig(applicationConfig(ui->applicationName->text()));
674674
}
675-
updateStartRecordingButtonState(ui);
675+
updateStartRecordingButtonState(m_perfRecord, ui);
676676
}
677677

678678
void RecordPage::onWorkingDirectoryNameChanged(const QString& folderPath)
@@ -688,7 +688,7 @@ void RecordPage::onWorkingDirectoryNameChanged(const QString& folderPath)
688688
} else {
689689
setError({});
690690
}
691-
updateStartRecordingButtonState(ui);
691+
updateStartRecordingButtonState(m_perfRecord, ui);
692692
}
693693

694694
void RecordPage::onViewPerfRecordResultsButtonClicked()
@@ -714,7 +714,7 @@ void RecordPage::onOutputFileNameChanged(const QString& /*filePath*/)
714714
} else {
715715
setError({});
716716
}
717-
updateStartRecordingButtonState(ui);
717+
updateStartRecordingButtonState(m_perfRecord, ui);
718718
}
719719

720720
void RecordPage::onOutputFileNameSelected(const QString& filePath)
@@ -746,7 +746,7 @@ void RecordPage::updateProcessesFinished()
746746

747747
if (selectedRecordType(ui) == AttachToProcess) {
748748
// only update the state when we show the attach app page
749-
updateStartRecordingButtonState(ui);
749+
updateStartRecordingButtonState(m_perfRecord, ui);
750750
QTimer::singleShot(1000, this, &RecordPage::updateProcesses);
751751
}
752752
}
@@ -773,23 +773,23 @@ void RecordPage::updateRecordType()
773773
m_perfOutput->setInputVisible(recordType == LaunchApplication);
774774
m_perfOutput->clear();
775775
ui->elevatePrivilegesCheckBox->setEnabled(recordType != ProfileSystem);
776-
ui->sampleCpuCheckBox->setEnabled(recordType != ProfileSystem && PerfRecord::canSampleCpu());
776+
ui->sampleCpuCheckBox->setEnabled(recordType != ProfileSystem && m_perfRecord->canSampleCpu());
777777
if (recordType == ProfileSystem) {
778778
ui->elevatePrivilegesCheckBox->setChecked(true);
779-
ui->sampleCpuCheckBox->setChecked(true && PerfRecord::canSampleCpu());
779+
ui->sampleCpuCheckBox->setChecked(true && m_perfRecord->canSampleCpu());
780780
}
781781

782782
if (recordType == AttachToProcess) {
783783
updateProcesses();
784784
}
785785

786-
updateStartRecordingButtonState(ui);
786+
updateStartRecordingButtonState(m_perfRecord, ui);
787787
}
788788

789789
void RecordPage::updateOffCpuCheckboxState()
790790
{
791791
const bool enableOffCpuProfiling =
792-
(ui->elevatePrivilegesCheckBox->isChecked() || PerfRecord::canProfileOffCpu()) && PerfRecord::canSwitchEvents();
792+
(ui->elevatePrivilegesCheckBox->isChecked() || m_perfRecord->canProfileOffCpu()) && m_perfRecord->canSwitchEvents();
793793

794794
if (enableOffCpuProfiling == ui->offCpuCheckBox->isEnabled()) {
795795
return;

tests/integrationtests/tst_perfparser.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ class TestPerfParser : public QObject
175175
private slots:
176176
void initTestCase()
177177
{
178-
if (!PerfRecord::isPerfInstalled()) {
178+
PerfRecord record;
179+
if (!record.isPerfInstalled()) {
179180
QSKIP("perf is not available, cannot run integration tests.");
180181
}
181182

@@ -222,10 +223,12 @@ private slots:
222223
{
223224
QTest::addColumn<QStringList>("otherOptions");
224225

226+
PerfRecord record;
227+
225228
QTest::addRow("normal") << QStringList();
226-
if (PerfRecord::canUseAio())
229+
if (record.canUseAio())
227230
QTest::addRow("aio") << QStringList("--aio");
228-
if (PerfRecord::canCompress())
231+
if (record.canCompress())
229232
QTest::addRow("zstd") << QStringList("-z");
230233
}
231234

@@ -501,7 +504,8 @@ private slots:
501504

502505
void testOffCpu()
503506
{
504-
if (!PerfRecord::canProfileOffCpu()) {
507+
PerfRecord record;
508+
if (!record.canProfileOffCpu()) {
505509
QSKIP("cannot access sched_switch trace points. execute the following to run this test:\n"
506510
" sudo mount -o remount,mode=755 /sys/kernel/debug{,/tracing} with mode=755");
507511
}
@@ -547,7 +551,9 @@ private slots:
547551
QSKIP("no sleep command available");
548552
}
549553

550-
if (!PerfRecord::canProfileOffCpu()) {
554+
PerfRecord record;
555+
556+
if (!record.canProfileOffCpu()) {
551557
QSKIP("cannot access sched_switch trace points. execute the following to run this test:\n"
552558
" sudo mount -o remount,mode=755 /sys/kernel/debug{,/tracing} with mode=755");
553559
}
@@ -574,8 +580,9 @@ private slots:
574580

575581
void testSampleCpu()
576582
{
583+
PerfRecord record;
577584
QStringList perfOptions = {"--call-graph", "dwarf", "--sample-cpu", "-e", "cycles"};
578-
if (PerfRecord::canProfileOffCpu()) {
585+
if (record.canProfileOffCpu()) {
579586
perfOptions += PerfRecord::offCpuProfilingOptions();
580587
}
581588

@@ -595,7 +602,7 @@ private slots:
595602
QCOMPARE(m_eventData.threads.size(), numThreads + 1);
596603
QCOMPARE(m_eventData.cpus.size(), numThreads);
597604

598-
if (PerfRecord::canProfileOffCpu()) {
605+
if (record.canProfileOffCpu()) {
599606
QCOMPARE(m_bottomUpData.costs.numTypes(), 3);
600607
QCOMPARE(m_bottomUpData.costs.typeName(0), QStringLiteral("cycles"));
601608
QCOMPARE(m_bottomUpData.costs.typeName(1), QStringLiteral("sched:sched_switch"));

0 commit comments

Comments
 (0)