@@ -28,21 +28,6 @@ PerfRecordSSH::~PerfRecordSSH() = default;
2828void 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
8974QString 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
9681bool 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
11490bool 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
159135bool 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
179155void 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 ();
0 commit comments