1616#include < csignal>
1717
1818#include " hotspot-config.h"
19-
20- QString sshOutput (const QString& hostname, const QStringList& command)
21- {
22- QProcess ssh;
23- ssh.setProgram (QStandardPaths::findExecutable (QLatin1String (" ssh" )));
24- const auto arguments = QStringList ({hostname}) + command;
25- ssh.setArguments (arguments);
26- ssh.start ();
27- ssh.waitForFinished ();
28- return QString::fromUtf8 (ssh.readAll ());
29- }
30-
31- int sshExitCode (const QString& hostname, const QStringList& command)
32- {
33- QProcess ssh;
34- ssh.setProgram (QStandardPaths::findExecutable (QLatin1String (" ssh" )));
35- const auto arguments = QStringList ({hostname}) + command;
36- ssh.setArguments (arguments);
37- ssh.start ();
38- ssh.waitForFinished ();
39- return ssh.exitCode ();
40- }
19+ #include " ssh.h"
4120
4221PerfRecordSSH::PerfRecordSSH (QObject* parent)
4322 : PerfRecord(parent)
4423{
45- m_hostname = QStringLiteral (" user@localhost" );
4624}
4725
4826PerfRecordSSH::~PerfRecordSSH () = default ;
4927
5028void PerfRecordSSH::record (const QStringList& perfOptions, const QString& outputPath, bool /* elevatePrivileges*/ ,
5129 const QString& exePath, const QStringList& exeOptions, const QString& workingDirectory)
5230{
53- int exitCode = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -e" ), exePath});
31+ int exitCode = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -e" ), exePath});
5432 if (exitCode) {
5533 emit recordingFailed (tr (" File '%1' does not exist." ).arg (exePath));
5634 }
5735
58- exitCode = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -f" ), exePath});
36+ exitCode = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -f" ), exePath});
5937 if (exitCode) {
6038 emit recordingFailed (tr (" '%1' is not a file." ).arg (exePath));
6139 }
6240
63- exitCode = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -x" ), exePath});
41+ exitCode = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -x" ), exePath});
6442 if (exitCode) {
6543 emit recordingFailed (tr (" File '%1' is not executable." ).arg (exePath));
6644 }
@@ -110,32 +88,32 @@ void PerfRecordSSH::sendInput(const QByteArray& input)
11088
11189QString PerfRecordSSH::currentUsername ()
11290{
113- if (m_hostname .isEmpty ())
91+ if (m_deviceName .isEmpty ())
11492 return {};
115- return sshOutput (m_hostname , {QLatin1String (" echo" ), QLatin1String (" $USERNAME" )}).simplified ();
93+ return sshOutput (m_deviceName , {QLatin1String (" echo" ), QLatin1String (" $USERNAME" )}).simplified ();
11694}
11795
11896bool PerfRecordSSH::canTrace (const QString& path)
11997{
120- if (m_hostname .isEmpty ())
98+ if (m_deviceName .isEmpty ())
12199 return false ;
122100
123101 // exit code == 0 -> true
124- bool isDir = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -d" ), path}) == 0 ;
125- bool isReadable = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -r" ), path}) == 0 ;
102+ bool isDir = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -d" ), path}) == 0 ;
103+ bool isReadable = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -r" ), path}) == 0 ;
126104
127105 if (!isDir || !isReadable) {
128106 return false ;
129107 }
130108
131109 QString paranoid =
132- sshOutput (m_hostname , {QLatin1String (" cat" ), QLatin1String (" /proc/sys/kernel/perf_event_paranoid" )});
110+ sshOutput (m_deviceName , {QLatin1String (" cat" ), QLatin1String (" /proc/sys/kernel/perf_event_paranoid" )});
133111 return paranoid.trimmed () == QLatin1String (" -1" );
134112}
135113
136114bool PerfRecordSSH::canProfileOffCpu ()
137115{
138- if (m_hostname .isEmpty ())
116+ if (m_deviceName .isEmpty ())
139117 return false ;
140118 return canTrace (QStringLiteral (" events/sched/sched_switch" ));
141119}
@@ -166,16 +144,16 @@ static QString perfBuildOptions(const QString& hostname)
166144
167145bool PerfRecordSSH::canSampleCpu ()
168146{
169- if (m_hostname .isEmpty ())
147+ if (m_deviceName .isEmpty ())
170148 return false ;
171- return perfRecordHelp (m_hostname ).contains (QLatin1String (" --sample-cpu" ));
149+ return perfRecordHelp (m_deviceName ).contains (QLatin1String (" --sample-cpu" ));
172150}
173151
174152bool PerfRecordSSH::canSwitchEvents ()
175153{
176- if (m_hostname .isEmpty ())
154+ if (m_deviceName .isEmpty ())
177155 return false ;
178- return perfRecordHelp (m_hostname ).contains (QLatin1String (" --switch-events" ));
156+ return perfRecordHelp (m_deviceName ).contains (QLatin1String (" --switch-events" ));
179157}
180158
181159bool PerfRecordSSH::canUseAio ()
@@ -186,16 +164,16 @@ bool PerfRecordSSH::canUseAio()
186164
187165bool PerfRecordSSH::canCompress ()
188166{
189- if (m_hostname .isEmpty ())
167+ if (m_deviceName .isEmpty ())
190168 return false ;
191- return Zstd_FOUND && perfBuildOptions (m_hostname ).contains (QLatin1String (" zstd: [ on ]" ));
169+ return Zstd_FOUND && perfBuildOptions (m_deviceName ).contains (QLatin1String (" zstd: [ on ]" ));
192170}
193171
194172bool PerfRecordSSH::isPerfInstalled ()
195173{
196- if (m_hostname .isEmpty ())
174+ if (m_deviceName .isEmpty ())
197175 return false ;
198- return sshExitCode (m_hostname , {QLatin1String (" perf" )}) != 127 ;
176+ return sshExitCode (m_deviceName , {QLatin1String (" perf" )}) != 127 ;
199177}
200178
201179void PerfRecordSSH::startRecording (const QStringList& perfOptions, const QString& outputPath,
@@ -230,12 +208,13 @@ void PerfRecordSSH::startRecording(const QStringList& perfOptions, const QString
230208
231209 m_recordProcess = new QProcess (this );
232210 m_recordProcess->setProgram (QStandardPaths::findExecutable (QLatin1String (" ssh" )));
233- m_recordProcess->setArguments ({m_hostname, QLatin1String (" perf " ) + perfCommand.join (QLatin1Char (' ' ))});
211+ const auto arguments =
212+ assembleSSHArguments (m_deviceName, {QLatin1String (" perf " ) + perfCommand.join (QLatin1Char (' ' ))});
213+ m_recordProcess->setArguments (arguments);
214+ m_recordProcess->setProcessEnvironment (sshEnvironment ());
234215 m_recordProcess->start ();
235216 m_recordProcess->waitForStarted ();
236217
237- qDebug () << m_recordProcess->arguments ().join (QLatin1Char (' ' ));
238-
239218 emit recordingStarted (QLatin1String (" perf" ), perfCommand);
240219
241220 connect (m_recordProcess, &QProcess::readyReadStandardOutput, this ,
0 commit comments