Skip to content

Commit 504eb21

Browse files
committed
remove static functions from PerfRecord
1 parent 76e9feb commit 504eb21

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
@@ -30,19 +30,19 @@ class PerfRecord : public QObject
3030
void stopRecording();
3131
void sendInput(const QByteArray& input);
3232

33-
static QString sudoUtil();
34-
static QString currentUsername();
33+
virtual QString sudoUtil();
34+
virtual QString currentUsername();
3535

36-
static bool canTrace(const QString& path);
37-
static bool canProfileOffCpu();
38-
static bool canSampleCpu();
39-
static bool canSwitchEvents();
40-
static bool canUseAio();
41-
static bool canCompress();
36+
virtual bool canTrace(const QString& path);
37+
virtual bool canProfileOffCpu();
38+
virtual bool canSampleCpu();
39+
virtual bool canSwitchEvents();
40+
virtual bool canUseAio();
41+
virtual bool canCompress();
4242

4343
static QStringList offCpuProfilingOptions();
4444

45-
static bool isPerfInstalled();
45+
virtual bool isPerfInstalled();
4646

4747
signals:
4848
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
@@ -72,9 +72,9 @@ RecordType selectedRecordType(const QScopedPointer<Ui::RecordPage>& ui)
7272
return ui->recordTypeComboBox->currentData().value<RecordType>();
7373
}
7474

75-
void updateStartRecordingButtonState(const QScopedPointer<Ui::RecordPage>& ui)
75+
void updateStartRecordingButtonState(PerfRecord* record, const QScopedPointer<Ui::RecordPage>& ui)
7676
{
77-
if (!PerfRecord::isPerfInstalled()) {
77+
if (!record->isPerfInstalled()) {
7878
ui->startRecordingButton->setEnabled(false);
7979
ui->applicationRecordErrorMessage->setText(QObject::tr("Please install perf before trying to record."));
8080
ui->applicationRecordErrorMessage->setVisible(true);
@@ -361,7 +361,7 @@ RecordPage::RecordPage(QWidget* parent)
361361
ui->processesTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
362362
ui->processesTableView->setSelectionMode(QAbstractItemView::MultiSelection);
363363
connect(ui->processesTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
364-
[this]() { updateStartRecordingButtonState(ui); });
364+
[this]() { updateStartRecordingButtonState(m_perfRecord, ui); });
365365

366366
ResultsUtil::connectFilter(ui->processesFilterBox, m_processProxyModel);
367367

@@ -387,7 +387,7 @@ RecordPage::RecordPage(QWidget* parent)
387387
ui->sampleCpuCheckBox->setChecked(config().readEntry(QStringLiteral("sampleCpu"), true));
388388
ui->mmapPagesSpinBox->setValue(config().readEntry(QStringLiteral("mmapPages"), 0));
389389
ui->mmapPagesUnitComboBox->setCurrentIndex(config().readEntry(QStringLiteral("mmapPagesUnit"), 2));
390-
ui->useAioCheckBox->setChecked(config().readEntry(QStringLiteral("useAio"), PerfRecord::canUseAio()));
390+
ui->useAioCheckBox->setChecked(config().readEntry(QStringLiteral("useAio"), m_perfRecord->canUseAio()));
391391

392392
const auto callGraph = config().readEntry("callGraph", ui->callGraphComboBox->currentData());
393393
const auto callGraphIdx = ui->callGraphComboBox->findData(callGraph);
@@ -419,19 +419,19 @@ RecordPage::RecordPage(QWidget* parent)
419419
}
420420
});
421421

422-
if (!PerfRecord::canSampleCpu()) {
422+
if (!m_perfRecord->canSampleCpu()) {
423423
ui->sampleCpuCheckBox->hide();
424424
ui->sampleCpuLabel->hide();
425425
}
426-
if (!PerfRecord::canSwitchEvents()) {
426+
if (!m_perfRecord->canSwitchEvents()) {
427427
ui->offCpuCheckBox->hide();
428428
ui->offCpuLabel->hide();
429429
}
430-
if (!PerfRecord::canUseAio()) {
430+
if (!m_perfRecord->canUseAio()) {
431431
ui->useAioCheckBox->hide();
432432
ui->useAioLabel->hide();
433433
}
434-
if (!PerfRecord::canCompress()) {
434+
if (!m_perfRecord->canCompress()) {
435435
ui->compressionComboBox->hide();
436436
ui->compressionLabel->hide();
437437
} else {
@@ -504,24 +504,24 @@ void RecordPage::onStartRecordingButtonClicked(bool checked)
504504
perfOptions += KShell::splitArgs(customOptions);
505505

506506
const bool offCpuProfilingEnabled = ui->offCpuCheckBox->isChecked();
507-
if (offCpuProfilingEnabled && PerfRecord::canSwitchEvents()) {
507+
if (offCpuProfilingEnabled && m_perfRecord->canSwitchEvents()) {
508508
if (eventType.isEmpty()) {
509509
// TODO: use clock event in VM context
510510
perfOptions += QStringLiteral("--event");
511511
perfOptions += QStringLiteral("cycles");
512512
}
513-
perfOptions += PerfRecord::offCpuProfilingOptions();
513+
perfOptions += m_perfRecord->offCpuProfilingOptions();
514514
}
515515
config().writeEntry(QStringLiteral("offCpuProfiling"), offCpuProfilingEnabled);
516516

517517
const bool useAioEnabled = ui->useAioCheckBox->isChecked();
518-
if (useAioEnabled && PerfRecord::canUseAio()) {
518+
if (useAioEnabled && m_perfRecord->canUseAio()) {
519519
perfOptions += QStringLiteral("--aio");
520520
}
521521
config().writeEntry(QStringLiteral("useAio"), useAioEnabled);
522522

523523
const auto compressionLevel = ui->compressionComboBox->currentData().toInt();
524-
if (PerfRecord::canCompress() && compressionLevel >= 0) {
524+
if (m_perfRecord->canCompress() && compressionLevel >= 0) {
525525
if (compressionLevel == 0)
526526
perfOptions += QStringLiteral("-z");
527527
else
@@ -532,7 +532,7 @@ void RecordPage::onStartRecordingButtonClicked(bool checked)
532532
const bool elevatePrivileges = ui->elevatePrivilegesCheckBox->isChecked();
533533

534534
const bool sampleCpuEnabled = ui->sampleCpuCheckBox->isChecked();
535-
if (sampleCpuEnabled && PerfRecord::canSampleCpu()) {
535+
if (sampleCpuEnabled && m_perfRecord->canSampleCpu()) {
536536
perfOptions += QStringLiteral("--sample-cpu");
537537
}
538538

@@ -653,7 +653,7 @@ void RecordPage::onApplicationNameChanged(const QString& filePath)
653653

654654
m_multiConfig->setConfig(applicationConfig(ui->applicationName->text()));
655655
}
656-
updateStartRecordingButtonState(ui);
656+
updateStartRecordingButtonState(m_perfRecord, ui);
657657
}
658658

659659
void RecordPage::onWorkingDirectoryNameChanged(const QString& folderPath)
@@ -669,7 +669,7 @@ void RecordPage::onWorkingDirectoryNameChanged(const QString& folderPath)
669669
} else {
670670
setError({});
671671
}
672-
updateStartRecordingButtonState(ui);
672+
updateStartRecordingButtonState(m_perfRecord, ui);
673673
}
674674

675675
void RecordPage::onViewPerfRecordResultsButtonClicked()
@@ -695,7 +695,7 @@ void RecordPage::onOutputFileNameChanged(const QString& /*filePath*/)
695695
} else {
696696
setError({});
697697
}
698-
updateStartRecordingButtonState(ui);
698+
updateStartRecordingButtonState(m_perfRecord, ui);
699699
}
700700

701701
void RecordPage::onOutputFileNameSelected(const QString& filePath)
@@ -727,7 +727,7 @@ void RecordPage::updateProcessesFinished()
727727

728728
if (selectedRecordType(ui) == AttachToProcess) {
729729
// only update the state when we show the attach app page
730-
updateStartRecordingButtonState(ui);
730+
updateStartRecordingButtonState(m_perfRecord, ui);
731731
QTimer::singleShot(1000, this, &RecordPage::updateProcesses);
732732
}
733733
}
@@ -754,23 +754,23 @@ void RecordPage::updateRecordType()
754754
m_perfOutput->setInputVisible(recordType == LaunchApplication);
755755
m_perfOutput->clear();
756756
ui->elevatePrivilegesCheckBox->setEnabled(recordType != ProfileSystem);
757-
ui->sampleCpuCheckBox->setEnabled(recordType != ProfileSystem && PerfRecord::canSampleCpu());
757+
ui->sampleCpuCheckBox->setEnabled(recordType != ProfileSystem && m_perfRecord->canSampleCpu());
758758
if (recordType == ProfileSystem) {
759759
ui->elevatePrivilegesCheckBox->setChecked(true);
760-
ui->sampleCpuCheckBox->setChecked(true && PerfRecord::canSampleCpu());
760+
ui->sampleCpuCheckBox->setChecked(true && m_perfRecord->canSampleCpu());
761761
}
762762

763763
if (recordType == AttachToProcess) {
764764
updateProcesses();
765765
}
766766

767-
updateStartRecordingButtonState(ui);
767+
updateStartRecordingButtonState(m_perfRecord, ui);
768768
}
769769

770770
void RecordPage::updateOffCpuCheckboxState()
771771
{
772772
const bool enableOffCpuProfiling =
773-
(ui->elevatePrivilegesCheckBox->isChecked() || PerfRecord::canProfileOffCpu()) && PerfRecord::canSwitchEvents();
773+
(ui->elevatePrivilegesCheckBox->isChecked() || m_perfRecord->canProfileOffCpu()) && m_perfRecord->canSwitchEvents();
774774

775775
if (enableOffCpuProfiling == ui->offCpuCheckBox->isEnabled()) {
776776
return;

tests/integrationtests/tst_perfparser.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ class TestPerfParser : public QObject
156156
private slots:
157157
void initTestCase()
158158
{
159-
if (!PerfRecord::isPerfInstalled()) {
159+
PerfRecord record;
160+
if (!record.isPerfInstalled()) {
160161
QSKIP("perf is not available, cannot run integration tests.");
161162
}
162163

@@ -203,10 +204,12 @@ private slots:
203204
{
204205
QTest::addColumn<QStringList>("otherOptions");
205206

207+
PerfRecord record;
208+
206209
QTest::addRow("normal") << QStringList();
207-
if (PerfRecord::canUseAio())
210+
if (record.canUseAio())
208211
QTest::addRow("aio") << QStringList("--aio");
209-
if (PerfRecord::canCompress())
212+
if (record.canCompress())
210213
QTest::addRow("zstd") << QStringList("-z");
211214
}
212215

@@ -482,7 +485,8 @@ private slots:
482485

483486
void testOffCpu()
484487
{
485-
if (!PerfRecord::canProfileOffCpu()) {
488+
PerfRecord record;
489+
if (!record.canProfileOffCpu()) {
486490
QSKIP("cannot access sched_switch trace points. execute the following to run this test:\n"
487491
" sudo mount -o remount,mode=755 /sys/kernel/debug{,/tracing} with mode=755");
488492
}
@@ -528,7 +532,9 @@ private slots:
528532
QSKIP("no sleep command available");
529533
}
530534

531-
if (!PerfRecord::canProfileOffCpu()) {
535+
PerfRecord record;
536+
537+
if (!record.canProfileOffCpu()) {
532538
QSKIP("cannot access sched_switch trace points. execute the following to run this test:\n"
533539
" sudo mount -o remount,mode=755 /sys/kernel/debug{,/tracing} with mode=755");
534540
}
@@ -555,8 +561,9 @@ private slots:
555561

556562
void testSampleCpu()
557563
{
564+
PerfRecord record;
558565
QStringList perfOptions = {"--call-graph", "dwarf", "--sample-cpu", "-e", "cycles"};
559-
if (PerfRecord::canProfileOffCpu()) {
566+
if (record.canProfileOffCpu()) {
560567
perfOptions += PerfRecord::offCpuProfilingOptions();
561568
}
562569

@@ -576,7 +583,7 @@ private slots:
576583
QCOMPARE(m_eventData.threads.size(), numThreads + 1);
577584
QCOMPARE(m_eventData.cpus.size(), numThreads);
578585

579-
if (PerfRecord::canProfileOffCpu()) {
586+
if (record.canProfileOffCpu()) {
580587
QCOMPARE(m_bottomUpData.costs.numTypes(), 3);
581588
QCOMPARE(m_bottomUpData.costs.typeName(0), QStringLiteral("cycles"));
582589
QCOMPARE(m_bottomUpData.costs.typeName(1), QStringLiteral("sched:sched_switch"));

0 commit comments

Comments
 (0)