16
16
#include < csignal>
17
17
18
18
#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"
41
20
42
21
PerfRecordSSH::PerfRecordSSH (QObject* parent)
43
22
: PerfRecord(parent)
44
23
{
45
- m_hostname = QStringLiteral (" user@localhost" );
46
24
}
47
25
48
26
PerfRecordSSH::~PerfRecordSSH () = default ;
@@ -102,7 +80,9 @@ QString PerfRecordSSH::currentUsername()
102
80
103
81
bool PerfRecordSSH::canTrace (const QString& path)
104
82
{
105
- if (m_hostname.isEmpty ())
83
+ Q_UNUSED (path);
84
+
85
+ if (m_deviceName.isEmpty ())
106
86
return false ;
107
87
108
88
// assume best case
@@ -111,7 +91,7 @@ bool PerfRecordSSH::canTrace(const QString& path)
111
91
112
92
bool PerfRecordSSH::canProfileOffCpu ()
113
93
{
114
- if (m_hostname .isEmpty ())
94
+ if (m_deviceName .isEmpty ())
115
95
return false ;
116
96
return canTrace (QStringLiteral (" events/sched/sched_switch" ));
117
97
}
@@ -142,16 +122,16 @@ QString perfBuildOptions(const QString& hostname)
142
122
143
123
bool PerfRecordSSH::canSampleCpu ()
144
124
{
145
- if (m_hostname .isEmpty ())
125
+ if (m_deviceName .isEmpty ())
146
126
return false ;
147
- return perfRecordHelp (m_hostname ).contains (QLatin1String (" --sample-cpu" ));
127
+ return perfRecordHelp (m_deviceName ).contains (QLatin1String (" --sample-cpu" ));
148
128
}
149
129
150
130
bool PerfRecordSSH::canSwitchEvents ()
151
131
{
152
- if (m_hostname .isEmpty ())
132
+ if (m_deviceName .isEmpty ())
153
133
return false ;
154
- return perfRecordHelp (m_hostname ).contains (QLatin1String (" --switch-events" ));
134
+ return perfRecordHelp (m_deviceName ).contains (QLatin1String (" --switch-events" ));
155
135
}
156
136
157
137
bool PerfRecordSSH::canUseAio ()
@@ -162,16 +142,16 @@ bool PerfRecordSSH::canUseAio()
162
142
163
143
bool PerfRecordSSH::canCompress ()
164
144
{
165
- if (m_hostname .isEmpty ())
145
+ if (m_deviceName .isEmpty ())
166
146
return false ;
167
- return Zstd_FOUND && perfBuildOptions (m_hostname ).contains (QLatin1String (" zstd: [ on ]" ));
147
+ return Zstd_FOUND && perfBuildOptions (m_deviceName ).contains (QLatin1String (" zstd: [ on ]" ));
168
148
}
169
149
170
150
bool PerfRecordSSH::isPerfInstalled ()
171
151
{
172
- if (m_hostname .isEmpty ())
152
+ if (m_deviceName .isEmpty ())
173
153
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 ;
175
155
}
176
156
177
157
void PerfRecordSSH::startRecording (const QStringList& perfOptions, const QString& outputPath,
@@ -199,18 +179,15 @@ void PerfRecordSSH::startRecording(const QStringList& perfOptions, const QString
199
179
return ;
200
180
}
201
181
182
+ qRegisterMetaType<QProcess::ExitStatus>(" QProcess::ExitStatus" );
183
+
202
184
QStringList perfCommand = {QStringLiteral (" record" ), QStringLiteral (" -o" ), QStringLiteral (" -" )};
203
185
perfCommand += perfOptions;
204
186
perfCommand += recordOptions;
205
-
206
187
m_outputFile = new QFile (outputPath);
207
188
m_outputFile->open (QIODevice::WriteOnly);
208
189
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);
214
191
215
192
emit recordingStarted (QLatin1String (" perf" ), perfCommand);
216
193
0 commit comments