Skip to content

Commit ee18c2e

Browse files
committed
remove static functions from PerfRecord
1 parent 423e141 commit ee18c2e

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

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

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

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

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

423-
if (!PerfRecord::canSampleCpu()) {
423+
if (!m_perfRecord->canSampleCpu()) {
424424
ui->sampleCpuCheckBox->hide();
425425
ui->sampleCpuLabel->hide();
426426
}
427-
if (!PerfRecord::canSwitchEvents()) {
427+
if (!m_perfRecord->canSwitchEvents()) {
428428
ui->offCpuCheckBox->hide();
429429
ui->offCpuLabel->hide();
430430
}
431-
if (!PerfRecord::canUseAio()) {
431+
if (!m_perfRecord->canUseAio()) {
432432
ui->useAioCheckBox->hide();
433433
ui->useAioLabel->hide();
434434
}
435-
if (!PerfRecord::canCompress()) {
435+
if (!m_perfRecord->canCompress()) {
436436
ui->compressionComboBox->hide();
437437
ui->compressionLabel->hide();
438438
} else {
@@ -505,24 +505,24 @@ void RecordPage::onStartRecordingButtonClicked(bool checked)
505505
perfOptions += KShell::splitArgs(customOptions);
506506

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

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

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

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

@@ -654,7 +654,7 @@ void RecordPage::onApplicationNameChanged(const QString& filePath)
654654

655655
m_multiConfig->setConfig(applicationConfig(ui->applicationName->text()));
656656
}
657-
updateStartRecordingButtonState(ui);
657+
updateStartRecordingButtonState(m_perfRecord, ui);
658658
}
659659

660660
void RecordPage::onWorkingDirectoryNameChanged(const QString& folderPath)
@@ -670,7 +670,7 @@ void RecordPage::onWorkingDirectoryNameChanged(const QString& folderPath)
670670
} else {
671671
setError({});
672672
}
673-
updateStartRecordingButtonState(ui);
673+
updateStartRecordingButtonState(m_perfRecord, ui);
674674
}
675675

676676
void RecordPage::onViewPerfRecordResultsButtonClicked()
@@ -696,7 +696,7 @@ void RecordPage::onOutputFileNameChanged(const QString& /*filePath*/)
696696
} else {
697697
setError({});
698698
}
699-
updateStartRecordingButtonState(ui);
699+
updateStartRecordingButtonState(m_perfRecord, ui);
700700
}
701701

702702
void RecordPage::onOutputFileNameSelected(const QString& filePath)
@@ -728,7 +728,7 @@ void RecordPage::updateProcessesFinished()
728728

729729
if (selectedRecordType(ui) == AttachToProcess) {
730730
// only update the state when we show the attach app page
731-
updateStartRecordingButtonState(ui);
731+
updateStartRecordingButtonState(m_perfRecord, ui);
732732
QTimer::singleShot(1000, this, &RecordPage::updateProcesses);
733733
}
734734
}
@@ -755,23 +755,23 @@ void RecordPage::updateRecordType()
755755
m_perfOutput->setInputVisible(recordType == LaunchApplication);
756756
m_perfOutput->clear();
757757
ui->elevatePrivilegesCheckBox->setEnabled(recordType != ProfileSystem);
758-
ui->sampleCpuCheckBox->setEnabled(recordType != ProfileSystem && PerfRecord::canSampleCpu());
758+
ui->sampleCpuCheckBox->setEnabled(recordType != ProfileSystem && m_perfRecord->canSampleCpu());
759759
if (recordType == ProfileSystem) {
760760
ui->elevatePrivilegesCheckBox->setChecked(true);
761-
ui->sampleCpuCheckBox->setChecked(true && PerfRecord::canSampleCpu());
761+
ui->sampleCpuCheckBox->setChecked(true && m_perfRecord->canSampleCpu());
762762
}
763763

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

768-
updateStartRecordingButtonState(ui);
768+
updateStartRecordingButtonState(m_perfRecord, ui);
769769
}
770770

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

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

tests/integrationtests/tst_perfparser.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ class TestPerfParser : public QObject
157157
private slots:
158158
void initTestCase()
159159
{
160-
if (!PerfRecord::isPerfInstalled()) {
160+
PerfRecord record;
161+
if (!record.isPerfInstalled()) {
161162
QSKIP("perf is not available, cannot run integration tests.");
162163
}
163164
}
@@ -201,10 +202,12 @@ private slots:
201202
{
202203
QTest::addColumn<QStringList>("otherOptions");
203204

205+
PerfRecord record;
206+
204207
QTest::addRow("normal") << QStringList();
205-
if (PerfRecord::canUseAio())
208+
if (record.canUseAio())
206209
QTest::addRow("aio") << QStringList("--aio");
207-
if (PerfRecord::canCompress())
210+
if (record.canCompress())
208211
QTest::addRow("zstd") << QStringList("-z");
209212
}
210213

@@ -480,7 +483,8 @@ private slots:
480483

481484
void testOffCpu()
482485
{
483-
if (!PerfRecord::canProfileOffCpu()) {
486+
PerfRecord record;
487+
if (!record.canProfileOffCpu()) {
484488
QSKIP("cannot access sched_switch trace points. execute the following to run this test:\n"
485489
" sudo mount -o remount,mode=755 /sys/kernel/debug{,/tracing} with mode=755");
486490
}
@@ -526,7 +530,9 @@ private slots:
526530
QSKIP("no sleep command available");
527531
}
528532

529-
if (!PerfRecord::canProfileOffCpu()) {
533+
PerfRecord record;
534+
535+
if (!record.canProfileOffCpu()) {
530536
QSKIP("cannot access sched_switch trace points. execute the following to run this test:\n"
531537
" sudo mount -o remount,mode=755 /sys/kernel/debug{,/tracing} with mode=755");
532538
}
@@ -553,8 +559,9 @@ private slots:
553559

554560
void testSampleCpu()
555561
{
562+
PerfRecord record;
556563
QStringList perfOptions = {"--call-graph", "dwarf", "--sample-cpu", "-e", "cycles"};
557-
if (PerfRecord::canProfileOffCpu()) {
564+
if (record.canProfileOffCpu()) {
558565
perfOptions += PerfRecord::offCpuProfilingOptions();
559566
}
560567

@@ -574,7 +581,7 @@ private slots:
574581
QCOMPARE(m_eventData.threads.size(), numThreads + 1);
575582
QCOMPARE(m_eventData.cpus.size(), numThreads);
576583

577-
if (PerfRecord::canProfileOffCpu()) {
584+
if (record.canProfileOffCpu()) {
578585
QCOMPARE(m_bottomUpData.costs.numTypes(), 3);
579586
QCOMPARE(m_bottomUpData.costs.typeName(0), QStringLiteral("cycles"));
580587
QCOMPARE(m_bottomUpData.costs.typeName(1), QStringLiteral("sched:sched_switch"));

0 commit comments

Comments
 (0)