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 ;
@@ -102,7 +80,9 @@ QString PerfRecordSSH::currentUsername()
10280
10381bool PerfRecordSSH::canTrace (const QString& path)
10482{
105- if (m_hostname.isEmpty ())
83+ Q_UNUSED (path);
84+
85+ if (m_deviceName.isEmpty ())
10686 return false ;
10787
10888 // assume best case
@@ -111,7 +91,7 @@ bool PerfRecordSSH::canTrace(const QString& path)
11191
11292bool PerfRecordSSH::canProfileOffCpu ()
11393{
114- if (m_hostname .isEmpty ())
94+ if (m_deviceName .isEmpty ())
11595 return false ;
11696 return canTrace (QStringLiteral (" events/sched/sched_switch" ));
11797}
@@ -142,16 +122,16 @@ QString perfBuildOptions(const QString& hostname)
142122
143123bool PerfRecordSSH::canSampleCpu ()
144124{
145- if (m_hostname .isEmpty ())
125+ if (m_deviceName .isEmpty ())
146126 return false ;
147- return perfRecordHelp (m_hostname ).contains (QLatin1String (" --sample-cpu" ));
127+ return perfRecordHelp (m_deviceName ).contains (QLatin1String (" --sample-cpu" ));
148128}
149129
150130bool PerfRecordSSH::canSwitchEvents ()
151131{
152- if (m_hostname .isEmpty ())
132+ if (m_deviceName .isEmpty ())
153133 return false ;
154- return perfRecordHelp (m_hostname ).contains (QLatin1String (" --switch-events" ));
134+ return perfRecordHelp (m_deviceName ).contains (QLatin1String (" --switch-events" ));
155135}
156136
157137bool PerfRecordSSH::canUseAio ()
@@ -162,16 +142,16 @@ bool PerfRecordSSH::canUseAio()
162142
163143bool PerfRecordSSH::canCompress ()
164144{
165- if (m_hostname .isEmpty ())
145+ if (m_deviceName .isEmpty ())
166146 return false ;
167- return Zstd_FOUND && perfBuildOptions (m_hostname ).contains (QLatin1String (" zstd: [ on ]" ));
147+ return Zstd_FOUND && perfBuildOptions (m_deviceName ).contains (QLatin1String (" zstd: [ on ]" ));
168148}
169149
170150bool PerfRecordSSH::isPerfInstalled ()
171151{
172- if (m_hostname .isEmpty ())
152+ if (m_deviceName .isEmpty ())
173153 return false ;
174- return sshExitCode (m_hostname , {QLatin1String (" command" ), QLatin1String (" -v" ), QLatin1String (" perf" )}) != 0 ;
154+ return sshExitCode (m_deviceName , {QLatin1String (" command" ), QLatin1String (" -v" ), QLatin1String (" perf" )}) != 0 ;
175155}
176156
177157void PerfRecordSSH::startRecording (const QStringList& perfOptions, const QString& outputPath,
@@ -199,18 +179,15 @@ void PerfRecordSSH::startRecording(const QStringList& perfOptions, const QString
199179 return ;
200180 }
201181
182+ qRegisterMetaType<QProcess::ExitStatus>(" QProcess::ExitStatus" );
183+
202184 QStringList perfCommand = {QStringLiteral (" record" ), QStringLiteral (" -o" ), QStringLiteral (" -" )};
203185 perfCommand += perfOptions;
204186 perfCommand += recordOptions;
205-
206187 m_outputFile = new QFile (outputPath);
207188 m_outputFile->open (QIODevice::WriteOnly);
208189
209- m_recordProcess = new QProcess (this );
210- m_recordProcess->setProgram (QStandardPaths::findExecutable (QLatin1String (" ssh" )));
211- m_recordProcess->setArguments ({m_hostname, QLatin1String (" perf " ) + perfCommand.join (QLatin1Char (' ' ))});
212- m_recordProcess->start ();
213- m_recordProcess->waitForStarted ();
190+ m_recordProcess = createSshProcess (m_deviceName, perfCommand);
214191
215192 emit recordingStarted (QLatin1String (" perf" ), perfCommand);
216193
0 commit comments