Skip to content

Commit b42ef40

Browse files
committed
some fixes
1 parent 9a5c9e9 commit b42ef40

File tree

9 files changed

+117
-127
lines changed

9 files changed

+117
-127
lines changed

src/perfrecordssh.cpp

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,6 @@ PerfRecordSSH::~PerfRecordSSH() = default;
2828
void PerfRecordSSH::record(const QStringList& perfOptions, const QString& outputPath, bool /*elevatePrivileges*/,
2929
const QString& exePath, const QStringList& exeOptions, const QString& workingDirectory)
3030
{
31-
int exitCode = sshExitCode(m_deviceName, {QLatin1String("test"), QLatin1String("-e"), exePath});
32-
if (exitCode) {
33-
emit recordingFailed(tr("File '%1' does not exist.").arg(exePath));
34-
}
35-
36-
exitCode = sshExitCode(m_deviceName, {QLatin1String("test"), QLatin1String("-f"), exePath});
37-
if (exitCode) {
38-
emit recordingFailed(tr("'%1' is not a file.").arg(exePath));
39-
}
40-
41-
exitCode = sshExitCode(m_deviceName, {QLatin1String("test"), QLatin1String("-x"), exePath});
42-
if (exitCode) {
43-
emit recordingFailed(tr("File '%1' is not executable.").arg(exePath));
44-
}
45-
4631
QStringList recordOptions = {exePath};
4732
recordOptions += exeOptions;
4833

@@ -88,27 +73,18 @@ void PerfRecordSSH::sendInput(const QByteArray& input)
8873

8974
QString PerfRecordSSH::currentUsername()
9075
{
91-
if (m_deviceName.isEmpty())
92-
return {};
93-
return sshOutput(m_deviceName, {QLatin1String("echo"), QLatin1String("$USERNAME")}).simplified();
76+
// this is only used to automatically check the elevate privileges checkbox if the user is root
77+
// since we currently do not support privilege elevation over ssh returning an empty string is fine
78+
return {};
9479
}
9580

9681
bool PerfRecordSSH::canTrace(const QString& path)
9782
{
9883
if (m_deviceName.isEmpty())
9984
return false;
10085

101-
// exit code == 0 -> true
102-
bool isDir = sshExitCode(m_deviceName, {QLatin1String("test"), QLatin1String("-d"), path}) == 0;
103-
bool isReadable = sshExitCode(m_deviceName, {QLatin1String("test"), QLatin1String("-r"), path}) == 0;
104-
105-
if (!isDir || !isReadable) {
106-
return false;
107-
}
108-
109-
QString paranoid =
110-
sshOutput(m_deviceName, {QLatin1String("cat"), QLatin1String("/proc/sys/kernel/perf_event_paranoid")});
111-
return paranoid.trimmed() == QLatin1String("-1");
86+
// assume best case
87+
return true;
11288
}
11389

11490
bool PerfRecordSSH::canProfileOffCpu()
@@ -118,9 +94,9 @@ bool PerfRecordSSH::canProfileOffCpu()
11894
return canTrace(QStringLiteral("events/sched/sched_switch"));
11995
}
12096

121-
static QString perfRecordHelp(const QString& hostname)
97+
QString perfRecordHelp(const QString& hostname)
12298
{
123-
static const QString recordHelp = [hostname]() {
99+
const QString recordHelp = [hostname]() {
124100
static QString help =
125101
sshOutput(hostname, {QLatin1String("perf"), QLatin1String("record"), QLatin1String("--help")});
126102
if (help.isEmpty()) {
@@ -132,9 +108,9 @@ static QString perfRecordHelp(const QString& hostname)
132108
return recordHelp;
133109
}
134110

135-
static QString perfBuildOptions(const QString& hostname)
111+
QString perfBuildOptions(const QString& hostname)
136112
{
137-
static const QString buildOptionsHelper = [hostname]() {
113+
const QString buildOptionsHelper = [hostname]() {
138114
static QString buildOptions =
139115
sshOutput(hostname, {QLatin1String("perf"), QLatin1String("version"), QLatin1String("--build-options")});
140116
return buildOptions;
@@ -158,7 +134,7 @@ bool PerfRecordSSH::canSwitchEvents()
158134

159135
bool PerfRecordSSH::canUseAio()
160136
{
161-
// somehow this doesn't work with ssh
137+
// perf reports "error: Illegal seek" when trying to use aio and streaming data
162138
return false;
163139
}
164140

@@ -173,7 +149,7 @@ bool PerfRecordSSH::isPerfInstalled()
173149
{
174150
if (m_deviceName.isEmpty())
175151
return false;
176-
return sshExitCode(m_deviceName, {QLatin1String("perf")}) != 127;
152+
return sshExitCode(m_deviceName, {QLatin1String("command"), QLatin1String("-v"), QLatin1String("perf")}) != 0;
177153
}
178154

179155
void PerfRecordSSH::startRecording(const QStringList& perfOptions, const QString& outputPath,
@@ -199,32 +175,26 @@ void PerfRecordSSH::startRecording(const QStringList& perfOptions, const QString
199175
return;
200176
}
201177

178+
qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
179+
202180
QStringList perfCommand = {QStringLiteral("record"), QStringLiteral("-o"), QStringLiteral("-")};
203181
perfCommand += perfOptions;
204182
perfCommand += recordOptions;
205-
206183
m_outputFile = new QFile(outputPath);
207184
m_outputFile->open(QIODevice::WriteOnly);
208185

209-
m_recordProcess = new QProcess(this);
210-
m_recordProcess->setProgram(QStandardPaths::findExecutable(QLatin1String("ssh")));
211-
const auto arguments =
212-
assembleSSHArguments(m_deviceName, {QLatin1String("perf ") + perfCommand.join(QLatin1Char(' '))});
213-
m_recordProcess->setArguments(arguments);
214-
m_recordProcess->setProcessEnvironment(sshEnvironment());
215-
m_recordProcess->start();
216-
m_recordProcess->waitForStarted();
186+
m_recordProcess = createSshProcess(m_deviceName, perfCommand);
217187

218188
emit recordingStarted(QLatin1String("perf"), perfCommand);
219189

220-
connect(m_recordProcess, &QProcess::readyReadStandardOutput, this,
190+
connect(m_recordProcess.get(), &QProcess::readyReadStandardOutput, this,
221191
[this] { m_outputFile->write(m_recordProcess->readAllStandardOutput()); });
222192

223-
connect(m_recordProcess, &QProcess::readyReadStandardError, this,
193+
connect(m_recordProcess.get(), &QProcess::readyReadStandardError, this,
224194
[this] { emit recordingOutput(QString::fromUtf8(m_recordProcess->readAllStandardError())); });
225195

226-
connect(m_recordProcess, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this,
227-
[this](int exitCode, QProcess::ExitStatus exitStatus) {
196+
connect(m_recordProcess.get(), static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
197+
this, [this](int exitCode, QProcess::ExitStatus exitStatus) {
228198
Q_UNUSED(exitStatus)
229199

230200
m_outputFile->close();

src/perfrecordssh.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99

1010
#include "perfrecord.h"
11+
#include <QProcess>
1112

1213
class QFile;
1314

@@ -53,7 +54,7 @@ class PerfRecordSSH : public PerfRecord
5354
void startRecording(const QStringList& perfOptions, const QString& outputPath, const QStringList& recordOptions,
5455
const QString& workingDirectory);
5556

56-
QProcess* m_recordProcess = nullptr;
57+
std::unique_ptr<QProcess> m_recordProcess = nullptr;
5758
QFile* m_outputFile;
5859
QString m_deviceName;
5960
bool m_userTerminated = false;

src/recordpage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ void RecordPage::stopRecording()
702702

703703
void RecordPage::onApplicationNameChanged(const QString& filePath)
704704
{
705-
QFileInfo application(KShell::tildeExpand(filePath));
705+
/*QFileInfo application(KShell::tildeExpand(filePath));
706706
if (!application.exists()) {
707707
application.setFile(QStandardPaths::findExecutable(filePath));
708708
}
@@ -721,7 +721,7 @@ void RecordPage::onApplicationNameChanged(const QString& filePath)
721721
setError({});
722722
723723
m_multiConfig->setConfig(applicationConfig(ui->applicationName->text()));
724-
}
724+
}*/
725725
updateStartRecordingButtonState(m_perfRecord, ui);
726726
}
727727

src/settings.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ void Settings::loadFromFile()
223223
});
224224

225225
const auto askpass = QStandardPaths::findExecutable(QLatin1String("ksshaskpass"));
226-
setSshaskpassPath(sharedConfig->group("SSH").readEntry("sshaskpass", askpass));
226+
setSshaskPassPath(sharedConfig->group("SSH").readEntry("sshaskpass", askpass));
227227
}
228228

229-
void Settings::setSshaskpassPath(const QString& sshaskpath)
229+
void Settings::setSshaskPassPath(const QString& sshaskpath)
230230
{
231-
m_sshaskpassPath = sshaskpath;
232-
emit sshaskpassChanged(m_sshaskpassPath);
231+
m_sshaskPassPath = sshaskpath;
232+
emit sshaskPassChanged(m_sshaskPassPath);
233233
}

src/settings.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ class Settings : public QObject
138138
return m_lastUsedEnvironment;
139139
}
140140

141-
QString sshaskpassPath() const
141+
QString sshaskPassPath() const
142142
{
143-
return m_sshaskpassPath;
143+
return m_sshaskPassPath;
144144
}
145145

146146
void loadFromFile();
@@ -162,7 +162,7 @@ class Settings : public QObject
162162
void objdumpChanged(const QString& objdump);
163163
void callgraphChanged();
164164
void lastUsedEnvironmentChanged(const QString& envName);
165-
void sshaskpassChanged(const QString& path);
165+
void sshaskPassChanged(const QString& path);
166166

167167
public slots:
168168
void setPrettifySymbols(bool prettifySymbols);
@@ -183,7 +183,7 @@ public slots:
183183
void setCallgraphColors(const QColor& active, const QColor& inactive);
184184
void setCostAggregation(CostAggregation costAggregation);
185185
void setLastUsedEnvironment(const QString& envName);
186-
void setSshaskpassPath(const QString& sshaskpath);
186+
void setSshaskPassPath(const QString& sshaskpath);
187187

188188
private:
189189
Settings() = default;
@@ -205,7 +205,7 @@ public slots:
205205
QString m_appPath;
206206
QString m_arch;
207207
QString m_objdump;
208-
QString m_sshaskpassPath;
208+
QString m_sshaskPassPath;
209209

210210
QString m_lastUsedEnvironment;
211211

src/settingsdialog.cpp

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ void SettingsDialog::addCallgraphPage()
303303

304304
void SettingsDialog::addSshPage()
305305
{
306-
const auto sshPath = QStandardPaths::findExecutable(QLatin1String("ssh"));
306+
const auto sshPath = QStandardPaths::findExecutable(QStringLiteral("ssh"));
307307

308308
// only show page if ssh is installed
309309
if (sshPath.isEmpty()) {
@@ -320,7 +320,7 @@ void SettingsDialog::addSshPage()
320320
auto deviceConfig = config()->group("devices");
321321

322322
auto saveFunction = [this](KConfigGroup group) {
323-
group.writeEntry("hostname", sshPage->ipLineEdit->text());
323+
group.writeEntry("hostname", sshPage->hostnameLineEdit->text());
324324
group.writeEntry("username", sshPage->usernameLineEdit->text());
325325
group.writeEntry("sshoptions", sshPage->sshOptionsLineEdit->text());
326326
};
@@ -330,7 +330,7 @@ void SettingsDialog::addSshPage()
330330
const auto username = group.readEntry("username");
331331
const auto sshOptions = group.readEntry("sshoptions");
332332

333-
sshPage->ipLineEdit->setText(hostname);
333+
sshPage->hostnameLineEdit->setText(hostname);
334334
sshPage->usernameLineEdit->setText(username);
335335
sshPage->sshOptionsLineEdit->setText(sshOptions);
336336
};
@@ -348,37 +348,26 @@ void SettingsDialog::addSshPage()
348348
sshPage->groupBox->layout()->replaceWidget(sshPage->multiConfigWidget, devices);
349349

350350
Settings* settings = Settings::instance();
351-
sshPage->sshaskpassLineEdit->setText(settings->sshaskpassPath());
351+
sshPage->sshaskpassLineEdit->setText(settings->sshaskPassPath());
352352

353-
connect(settings, &Settings::sshaskpassChanged, this,
353+
connect(settings, &Settings::sshaskPassChanged, this,
354354
[this](const QString& path) { sshPage->sshaskpassLineEdit->setText(path); });
355355

356356
connect(sshPage->testButton, &QPushButton::pressed, this, [this, devices] {
357-
auto ssh = new QProcess(this);
358-
ssh->setProgram(QStandardPaths::findExecutable(QLatin1String("ssh")));
359-
360-
const auto hostname =
361-
QStringLiteral("%1@%2").arg(sshPage->usernameLineEdit->text(), sshPage->ipLineEdit->text());
362-
QStringList arguments = {hostname};
363-
const auto sshOptions = sshPage->sshOptionsLineEdit->text();
364-
if (!sshOptions.isEmpty()) {
365-
arguments.append(sshOptions.split(QLatin1Char(' ')));
366-
}
367-
arguments.append(QLatin1String("perf"));
368-
369-
ssh->setArguments(arguments);
370-
ssh->setProcessEnvironment(sshEnvironment());
371-
ssh->start();
357+
auto ssh = createSshProcess(sshPage->hostnameLineEdit->text(), sshPage->usernameLineEdit->text(),
358+
sshPage->sshOptionsLineEdit->text(), QStringList({QStringLiteral("perf")}));
372359

373-
connect(ssh, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this,
374-
[this, ssh, devices, hostname](int exitCode, QProcess::ExitStatus exitStatus) {
360+
connect(ssh.get(), static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this,
361+
[this, &ssh, devices](int exitCode, QProcess::ExitStatus exitStatus) {
375362
Q_UNUSED(exitStatus);
376363

377364
auto showError = [this](const QString& errorText) {
378365
sshPage->errorMessageWidget->setText(errorText);
379366
sshPage->errorMessageWidget->show();
380367
};
381368

369+
const auto hostname = sshPage->hostnameLineEdit->text();
370+
382371
if (exitCode == 255) {
383372
showError(tr("Failed to connect to %1").arg(hostname));
384373
} else if (exitCode == 127) {
@@ -391,26 +380,17 @@ void SettingsDialog::addSshPage()
391380
showError(tr("Error: %1").arg(QString::fromUtf8(ssh->readAllStandardError())));
392381
}
393382
});
383+
384+
ssh->start();
394385
});
395386

396387
connect(sshPage->copyKeyButton, &QPushButton::pressed, this, [this, devices] {
397-
auto sshCopyId = new QProcess(this);
398-
sshCopyId->setProgram(QStandardPaths::findExecutable(QLatin1String("ssh-copy-id")));
399-
400-
const auto hostname =
401-
QStringLiteral("%1@%2").arg(sshPage->usernameLineEdit->text(), sshPage->ipLineEdit->text());
402-
QStringList arguments = {hostname};
403-
const auto sshOptions = sshPage->sshOptionsLineEdit->text();
404-
if (!sshOptions.isEmpty()) {
405-
arguments.append(sshOptions.split(QLatin1Char(' ')));
406-
}
407-
408-
sshCopyId->setArguments(arguments);
409-
sshCopyId->setProcessEnvironment(sshEnvironment());
410-
sshCopyId->start();
388+
auto sshCopyId = createSshProcess(sshPage->hostnameLineEdit->text(), sshPage->usernameLineEdit->text(),
389+
sshPage->sshOptionsLineEdit->text(), QStringList({QStringLiteral("perf")}),
390+
QLatin1String("ssh-copy-id"));
411391

412-
connect(sshCopyId, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this,
413-
[this, sshCopyId, hostname](int exitCode, QProcess::ExitStatus exitStatus) {
392+
connect(sshCopyId.get(), static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this,
393+
[this, &sshCopyId](int exitCode, QProcess::ExitStatus exitStatus) {
414394
Q_UNUSED(exitStatus);
415395
if (exitCode == 1) {
416396
sshPage->errorMessageWidget->setText(QString::fromUtf8(sshCopyId->readAllStandardError()));
@@ -420,6 +400,8 @@ void SettingsDialog::addSshPage()
420400
sshPage->successMessageWidget->show();
421401
}
422402
});
403+
404+
sshCopyId->start();
423405
});
424406

425407
sshPage->errorMessageWidget->setVisible(false);

0 commit comments

Comments
 (0)