3636#include < csignal>
3737
3838#include " hotspot-config.h"
39-
40- QString sshOutput (const QString& hostname, const QStringList& command)
41- {
42- QProcess ssh;
43- ssh.setProgram (QStandardPaths::findExecutable (QLatin1String (" ssh" )));
44- const auto arguments = QStringList ({hostname}) + command;
45- ssh.setArguments (arguments);
46- ssh.start ();
47- ssh.waitForFinished ();
48- return QString::fromUtf8 (ssh.readAll ());
49- }
50-
51- int sshExitCode (const QString& hostname, const QStringList& command)
52- {
53- QProcess ssh;
54- ssh.setProgram (QStandardPaths::findExecutable (QLatin1String (" ssh" )));
55- const auto arguments = QStringList ({hostname}) + command;
56- ssh.setArguments (arguments);
57- ssh.start ();
58- ssh.waitForFinished ();
59- return ssh.exitCode ();
60- }
39+ #include " ssh.h"
6140
6241PerfRecordSSH::PerfRecordSSH (QObject* parent)
6342 : PerfRecord(parent)
6443{
65- m_hostname = QStringLiteral (" user@localhost" );
6644}
6745
6846PerfRecordSSH::~PerfRecordSSH () = default ;
6947
7048void PerfRecordSSH::record (const QStringList& perfOptions, const QString& outputPath, bool /* elevatePrivileges*/ ,
7149 const QString& exePath, const QStringList& exeOptions, const QString& workingDirectory)
7250{
73- int exitCode = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -e" ), exePath});
51+ int exitCode = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -e" ), exePath});
7452 if (exitCode) {
7553 emit recordingFailed (tr (" File '%1' does not exist." ).arg (exePath));
7654 }
7755
78- exitCode = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -f" ), exePath});
56+ exitCode = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -f" ), exePath});
7957 if (exitCode) {
8058 emit recordingFailed (tr (" '%1' is not a file." ).arg (exePath));
8159 }
8260
83- exitCode = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -x" ), exePath});
61+ exitCode = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -x" ), exePath});
8462 if (exitCode) {
8563 emit recordingFailed (tr (" File '%1' is not executable." ).arg (exePath));
8664 }
@@ -130,32 +108,32 @@ void PerfRecordSSH::sendInput(const QByteArray& input)
130108
131109QString PerfRecordSSH::currentUsername ()
132110{
133- if (m_hostname .isEmpty ())
111+ if (m_deviceName .isEmpty ())
134112 return {};
135- return sshOutput (m_hostname , {QLatin1String (" echo" ), QLatin1String (" $USERNAME" )}).simplified ();
113+ return sshOutput (m_deviceName , {QLatin1String (" echo" ), QLatin1String (" $USERNAME" )}).simplified ();
136114}
137115
138116bool PerfRecordSSH::canTrace (const QString& path)
139117{
140- if (m_hostname .isEmpty ())
118+ if (m_deviceName .isEmpty ())
141119 return false ;
142120
143121 // exit code == 0 -> true
144- bool isDir = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -d" ), path}) == 0 ;
145- bool isReadable = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -r" ), path}) == 0 ;
122+ bool isDir = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -d" ), path}) == 0 ;
123+ bool isReadable = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -r" ), path}) == 0 ;
146124
147125 if (!isDir || !isReadable) {
148126 return false ;
149127 }
150128
151129 QString paranoid =
152- sshOutput (m_hostname , {QLatin1String (" cat" ), QLatin1String (" /proc/sys/kernel/perf_event_paranoid" )});
130+ sshOutput (m_deviceName , {QLatin1String (" cat" ), QLatin1String (" /proc/sys/kernel/perf_event_paranoid" )});
153131 return paranoid.trimmed () == QLatin1String (" -1" );
154132}
155133
156134bool PerfRecordSSH::canProfileOffCpu ()
157135{
158- if (m_hostname .isEmpty ())
136+ if (m_deviceName .isEmpty ())
159137 return false ;
160138 return canTrace (QStringLiteral (" events/sched/sched_switch" ));
161139}
@@ -186,16 +164,16 @@ static QString perfBuildOptions(const QString& hostname)
186164
187165bool PerfRecordSSH::canSampleCpu ()
188166{
189- if (m_hostname .isEmpty ())
167+ if (m_deviceName .isEmpty ())
190168 return false ;
191- return perfRecordHelp (m_hostname ).contains (QLatin1String (" --sample-cpu" ));
169+ return perfRecordHelp (m_deviceName ).contains (QLatin1String (" --sample-cpu" ));
192170}
193171
194172bool PerfRecordSSH::canSwitchEvents ()
195173{
196- if (m_hostname .isEmpty ())
174+ if (m_deviceName .isEmpty ())
197175 return false ;
198- return perfRecordHelp (m_hostname ).contains (QLatin1String (" --switch-events" ));
176+ return perfRecordHelp (m_deviceName ).contains (QLatin1String (" --switch-events" ));
199177}
200178
201179bool PerfRecordSSH::canUseAio ()
@@ -206,16 +184,16 @@ bool PerfRecordSSH::canUseAio()
206184
207185bool PerfRecordSSH::canCompress ()
208186{
209- if (m_hostname .isEmpty ())
187+ if (m_deviceName .isEmpty ())
210188 return false ;
211- return Zstd_FOUND && perfBuildOptions (m_hostname ).contains (QLatin1String (" zstd: [ on ]" ));
189+ return Zstd_FOUND && perfBuildOptions (m_deviceName ).contains (QLatin1String (" zstd: [ on ]" ));
212190}
213191
214192bool PerfRecordSSH::isPerfInstalled ()
215193{
216- if (m_hostname .isEmpty ())
194+ if (m_deviceName .isEmpty ())
217195 return false ;
218- return sshExitCode (m_hostname , {QLatin1String (" perf" )}) != 127 ;
196+ return sshExitCode (m_deviceName , {QLatin1String (" perf" )}) != 127 ;
219197}
220198
221199void PerfRecordSSH::startRecording (const QStringList& perfOptions, const QString& outputPath,
@@ -250,12 +228,13 @@ void PerfRecordSSH::startRecording(const QStringList& perfOptions, const QString
250228
251229 m_recordProcess = new QProcess (this );
252230 m_recordProcess->setProgram (QStandardPaths::findExecutable (QLatin1String (" ssh" )));
253- m_recordProcess->setArguments ({m_hostname, QLatin1String (" perf " ) + perfCommand.join (QLatin1Char (' ' ))});
231+ const auto arguments =
232+ assembleSSHArguments (m_deviceName, {QLatin1String (" perf " ) + perfCommand.join (QLatin1Char (' ' ))});
233+ m_recordProcess->setArguments (arguments);
234+ m_recordProcess->setProcessEnvironment (sshEnvironment ());
254235 m_recordProcess->start ();
255236 m_recordProcess->waitForStarted ();
256237
257- qDebug () << m_recordProcess->arguments ().join (QLatin1Char (' ' ));
258-
259238 emit recordingStarted (QLatin1String (" perf" ), perfCommand);
260239
261240 connect (m_recordProcess, &QProcess::readyReadStandardOutput, this ,
0 commit comments