Skip to content

Commit f5e6378

Browse files
committed
integrate RecordHost in PerfRecord
There is some logic left from the time before RecordHost. This patch removes these fragments
1 parent 2a896ef commit f5e6378

File tree

6 files changed

+39
-37
lines changed

6 files changed

+39
-37
lines changed

src/perfrecord.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <csignal>
2222
#include <unistd.h>
2323

24+
#include <KShell>
2425
#include <kwindowsystem_version.h>
2526
#if KWINDOWSYSTEM_VERSION >= QT_VERSION_CHECK(5, 101, 0)
2627
#include <KX11Extras>
@@ -174,27 +175,11 @@ void PerfRecord::record(const QStringList& perfOptions, const QString& outputPat
174175
runPerf(actuallyElevatePrivileges(elevatePrivileges), options, outputPath, {});
175176
}
176177

177-
void PerfRecord::record(const QStringList& perfOptions, const QString& outputPath, bool elevatePrivileges,
178-
const QString& exePath, const QStringList& exeOptions, const QString& workingDirectory)
178+
void PerfRecord::record(const QStringList& perfOptions, const QString& outputPath, bool elevatePrivileges)
179179
{
180-
QFileInfo exeFileInfo(exePath);
181-
182-
if (!exeFileInfo.exists()) {
183-
exeFileInfo.setFile(QStandardPaths::findExecutable(exePath));
184-
}
185-
186-
if (!exeFileInfo.exists()) {
187-
emit recordingFailed(tr("File '%1' does not exist.").arg(exePath));
188-
return;
189-
}
190-
if (!exeFileInfo.isFile()) {
191-
emit recordingFailed(tr("'%1' is not a file.").arg(exePath));
192-
return;
193-
}
194-
if (!exeFileInfo.isExecutable()) {
195-
emit recordingFailed(tr("File '%1' is not executable.").arg(exePath));
196-
return;
197-
}
180+
auto exePath = m_host->clientApplication();
181+
auto exeOptions = m_host->clientApplicationArguments();
182+
auto workingDirectory = m_host->currentWorkingDirectory();
198183

199184
QStringList options = perfOptions;
200185
if (actuallyElevatePrivileges(elevatePrivileges)) {
@@ -211,7 +196,7 @@ void PerfRecord::record(const QStringList& perfOptions, const QString& outputPat
211196

212197
m_perfControlFifo.requestStart();
213198
} else {
214-
options.append(exeFileInfo.absoluteFilePath());
199+
options.append(exePath);
215200
options += exeOptions;
216201
runPerf(false, options, outputPath, workingDirectory);
217202
}

src/perfrecord.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class PerfRecord : public QObject
2424
explicit PerfRecord(const RecordHost* host, QObject* parent = nullptr);
2525
~PerfRecord();
2626

27-
void record(const QStringList& perfOptions, const QString& outputPath, bool elevatePrivileges,
28-
const QString& exePath, const QStringList& exeOptions, const QString& workingDirectory = QString());
27+
void record(const QStringList& perfOptions, const QString& outputPath, bool elevatePrivileges);
28+
2929
void record(const QStringList& perfOptions, const QString& outputPath, bool elevatePrivileges,
3030
const QStringList& pids);
3131
void recordSystem(const QStringList& perfOptions, const QString& outputPath);
@@ -55,4 +55,6 @@ class PerfRecord : public QObject
5555

5656
bool runPerf(bool elevatePrivileges, const QStringList& perfOptions, const QString& outputPath,
5757
const QString& workingDirectory = QString());
58+
59+
bool runRemotePerf(const QStringList& perfOptions, const QString& outputPath, const QString& workingDirectory = {});
5860
};

src/recordhost.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ void RecordHost::setClientApplication(const QString& clientApplication)
327327
}
328328
}
329329

330-
void RecordHost::setClientApplicationArguments(const QString& arguments)
330+
void RecordHost::setClientApplicationArguments(const QStringList& arguments)
331331
{
332332
Q_ASSERT(QThread::currentThread() == thread());
333333

src/recordhost.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ class RecordHost : public QObject
6161
}
6262
void setClientApplication(const QString& clientApplication);
6363

64-
QString clientApplicationArguments() const
64+
QStringList clientApplicationArguments() const
6565
{
6666
return m_clientApplicationArguments;
6767
}
68-
void setClientApplicationArguments(const QString& arguments);
68+
void setClientApplicationArguments(const QStringList& arguments);
6969

7070
QString outputFileName() const
7171
{
@@ -111,7 +111,7 @@ class RecordHost : public QObject
111111
void hostChanged();
112112
void currentWorkingDirectoryChanged(const QString& cwd); // Maybe QUrl
113113
void clientApplicationChanged(const QString& clientApplication);
114-
void clientApplicationArgumentsChanged(const QString& arguments);
114+
void clientApplicationArgumentsChanged(const QStringList& arguments);
115115
void perfCapabilitiesChanged(RecordHost::PerfCapabilities perfCapabilities);
116116
void isPerfInstalledChanged(bool isInstalled);
117117
void outputFileNameChanged(const QString& outputFileName);
@@ -126,7 +126,7 @@ class RecordHost : public QObject
126126
QString m_error;
127127
QString m_cwd;
128128
QString m_clientApplication;
129-
QString m_clientApplicationArguments;
129+
QStringList m_clientApplicationArguments;
130130
QString m_outputFileName;
131131
PerfCapabilities m_perfCapabilities;
132132
JobTracker m_checkPerfCapabilitiesJob;

src/recordpage.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ RecordPage::RecordPage(QWidget* parent)
204204

205205
connect(ui->applicationParametersBox, &QLineEdit::editingFinished, this, [this] {
206206
ui->multiConfig->saveCurrentConfig();
207-
m_recordHost->setClientApplicationArguments(ui->applicationParametersBox->text());
207+
m_recordHost->setClientApplicationArguments(KShell::splitArgs(ui->applicationParametersBox->text()));
208208
});
209209

210210
ui->compressionComboBox->addItem(tr("Disabled"), -1);
@@ -620,14 +620,27 @@ void RecordPage::onStartRecordingButtonClicked(bool checked)
620620
switch (recordType) {
621621
case RecordType::LaunchApplication: {
622622
const auto applicationName = m_recordHost->clientApplication();
623-
const auto appParameters = ui->applicationParametersBox->text();
623+
const auto appParameters = m_recordHost->clientApplicationArguments();
624624
auto workingDir = m_recordHost->currentWorkingDirectory();
625625
if (workingDir.isEmpty()) {
626626
workingDir = ui->workingDirectory->placeholderText();
627627
}
628-
rememberApplication(applicationName, appParameters, workingDir, ui->applicationName->comboBox());
629-
m_perfRecord->record(perfOptions, outputFile, elevatePrivileges, applicationName,
630-
KShell::splitArgs(appParameters), workingDir);
628+
rememberApplication(applicationName, appParameters.join(QLatin1Char(' ')), workingDir,
629+
ui->applicationName->comboBox());
630+
m_perfRecord->record(perfOptions, outputFile, elevatePrivileges);
631+
break;
632+
}
633+
case RecordType::LaunchRemoteApplication: {
634+
// TODO: network record
635+
const auto applicationName = m_recordHost->clientApplication();
636+
const auto appParameters = m_recordHost->clientApplicationArguments();
637+
auto workingDir = m_recordHost->currentWorkingDirectory();
638+
if (workingDir.isEmpty()) {
639+
workingDir = ui->workingDirectory->placeholderText();
640+
}
641+
rememberApplication(applicationName, appParameters.join(QLatin1Char(' ')), workingDir,
642+
ui->applicationName->comboBox());
643+
m_perfRecord->record(perfOptions, outputFile, elevatePrivileges);
631644
break;
632645
}
633646
case RecordType::AttachToProcess: {

tests/integrationtests/tst_perfparser.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include "perfparser.h"
2020
#include "perfrecord.h"
2121
#include "recordhost.h"
22-
#include "unistd.h"
23-
#include "util.h"
2422

2523
#include "../testutils.h"
2624
#include <hotspot-config.h>
@@ -429,7 +427,9 @@ private slots:
429427
QSignalSpy recordingFinishedSpy(&perf, &PerfRecord::recordingFinished);
430428
QSignalSpy recordingFailedSpy(&perf, &PerfRecord::recordingFailed);
431429

432-
perf.record({QStringLiteral("--no-buildid-cache")}, tempFile.fileName(), false, exePath, exeOptions);
430+
host.setClientApplication(exePath);
431+
host.setClientApplicationArguments(exeOptions);
432+
perf.record({QStringLiteral("--no-buildid-cache")}, tempFile.fileName(), false);
433433
perf.sendInput(QByteArrayLiteral("some input\n"));
434434
QVERIFY(recordingFinishedSpy.wait());
435435

@@ -735,11 +735,13 @@ private slots:
735735
QSignalSpy recordingFinishedSpy(&perf, &PerfRecord::recordingFinished);
736736
QSignalSpy recordingFailedSpy(&perf, &PerfRecord::recordingFailed);
737737

738+
host.setClientApplication(exePath);
739+
host.setClientApplicationArguments(exeOptions);
738740
// always add `-c 1000000`, as perf's frequency mode is too unreliable for testing purposes
739741
perf.record(
740742
perfOptions
741743
+ QStringList {QStringLiteral("-c"), QStringLiteral("1000000"), QStringLiteral("--no-buildid-cache")},
742-
fileName, false, exePath, exeOptions);
744+
fileName, false);
743745

744746
VERIFY_OR_THROW(recordingFinishedSpy.wait(10000));
745747

0 commit comments

Comments
 (0)