36
36
#include < csignal>
37
37
38
38
#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"
61
40
62
41
PerfRecordSSH::PerfRecordSSH (QObject* parent)
63
42
: PerfRecord(parent)
64
43
{
65
- m_hostname = QStringLiteral (" user@localhost" );
66
44
}
67
45
68
46
PerfRecordSSH::~PerfRecordSSH () = default ;
69
47
70
48
void PerfRecordSSH::record (const QStringList& perfOptions, const QString& outputPath, bool /* elevatePrivileges*/ ,
71
49
const QString& exePath, const QStringList& exeOptions, const QString& workingDirectory)
72
50
{
73
- int exitCode = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -e" ), exePath});
51
+ int exitCode = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -e" ), exePath});
74
52
if (exitCode) {
75
53
emit recordingFailed (tr (" File '%1' does not exist." ).arg (exePath));
76
54
}
77
55
78
- exitCode = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -f" ), exePath});
56
+ exitCode = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -f" ), exePath});
79
57
if (exitCode) {
80
58
emit recordingFailed (tr (" '%1' is not a file." ).arg (exePath));
81
59
}
82
60
83
- exitCode = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -x" ), exePath});
61
+ exitCode = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -x" ), exePath});
84
62
if (exitCode) {
85
63
emit recordingFailed (tr (" File '%1' is not executable." ).arg (exePath));
86
64
}
@@ -130,32 +108,32 @@ void PerfRecordSSH::sendInput(const QByteArray& input)
130
108
131
109
QString PerfRecordSSH::currentUsername ()
132
110
{
133
- if (m_hostname .isEmpty ())
111
+ if (m_deviceName .isEmpty ())
134
112
return {};
135
- return sshOutput (m_hostname , {QLatin1String (" echo" ), QLatin1String (" $USERNAME" )}).simplified ();
113
+ return sshOutput (m_deviceName , {QLatin1String (" echo" ), QLatin1String (" $USERNAME" )}).simplified ();
136
114
}
137
115
138
116
bool PerfRecordSSH::canTrace (const QString& path)
139
117
{
140
- if (m_hostname .isEmpty ())
118
+ if (m_deviceName .isEmpty ())
141
119
return false ;
142
120
143
121
// 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 ;
146
124
147
125
if (!isDir || !isReadable) {
148
126
return false ;
149
127
}
150
128
151
129
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" )});
153
131
return paranoid.trimmed () == QLatin1String (" -1" );
154
132
}
155
133
156
134
bool PerfRecordSSH::canProfileOffCpu ()
157
135
{
158
- if (m_hostname .isEmpty ())
136
+ if (m_deviceName .isEmpty ())
159
137
return false ;
160
138
return canTrace (QStringLiteral (" events/sched/sched_switch" ));
161
139
}
@@ -186,16 +164,16 @@ static QString perfBuildOptions(const QString& hostname)
186
164
187
165
bool PerfRecordSSH::canSampleCpu ()
188
166
{
189
- if (m_hostname .isEmpty ())
167
+ if (m_deviceName .isEmpty ())
190
168
return false ;
191
- return perfRecordHelp (m_hostname ).contains (QLatin1String (" --sample-cpu" ));
169
+ return perfRecordHelp (m_deviceName ).contains (QLatin1String (" --sample-cpu" ));
192
170
}
193
171
194
172
bool PerfRecordSSH::canSwitchEvents ()
195
173
{
196
- if (m_hostname .isEmpty ())
174
+ if (m_deviceName .isEmpty ())
197
175
return false ;
198
- return perfRecordHelp (m_hostname ).contains (QLatin1String (" --switch-events" ));
176
+ return perfRecordHelp (m_deviceName ).contains (QLatin1String (" --switch-events" ));
199
177
}
200
178
201
179
bool PerfRecordSSH::canUseAio ()
@@ -206,16 +184,16 @@ bool PerfRecordSSH::canUseAio()
206
184
207
185
bool PerfRecordSSH::canCompress ()
208
186
{
209
- if (m_hostname .isEmpty ())
187
+ if (m_deviceName .isEmpty ())
210
188
return false ;
211
- return Zstd_FOUND && perfBuildOptions (m_hostname ).contains (QLatin1String (" zstd: [ on ]" ));
189
+ return Zstd_FOUND && perfBuildOptions (m_deviceName ).contains (QLatin1String (" zstd: [ on ]" ));
212
190
}
213
191
214
192
bool PerfRecordSSH::isPerfInstalled ()
215
193
{
216
- if (m_hostname .isEmpty ())
194
+ if (m_deviceName .isEmpty ())
217
195
return false ;
218
- return sshExitCode (m_hostname , {QLatin1String (" perf" )}) != 127 ;
196
+ return sshExitCode (m_deviceName , {QLatin1String (" perf" )}) != 127 ;
219
197
}
220
198
221
199
void PerfRecordSSH::startRecording (const QStringList& perfOptions, const QString& outputPath,
@@ -250,12 +228,13 @@ void PerfRecordSSH::startRecording(const QStringList& perfOptions, const QString
250
228
251
229
m_recordProcess = new QProcess (this );
252
230
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 ());
254
235
m_recordProcess->start ();
255
236
m_recordProcess->waitForStarted ();
256
237
257
- qDebug () << m_recordProcess->arguments ().join (QLatin1Char (' ' ));
258
-
259
238
emit recordingStarted (QLatin1String (" perf" ), perfCommand);
260
239
261
240
connect (m_recordProcess, &QProcess::readyReadStandardOutput, this ,
0 commit comments