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 ;
49
27
50
28
void PerfRecordSSH::record (const QStringList& perfOptions, const QString& outputPath, bool /* elevatePrivileges*/ ,
51
29
const QString& exePath, const QStringList& exeOptions, const QString& workingDirectory)
52
30
{
53
- int exitCode = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -e" ), exePath});
31
+ int exitCode = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -e" ), exePath});
54
32
if (exitCode) {
55
33
emit recordingFailed (tr (" File '%1' does not exist." ).arg (exePath));
56
34
}
57
35
58
- exitCode = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -f" ), exePath});
36
+ exitCode = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -f" ), exePath});
59
37
if (exitCode) {
60
38
emit recordingFailed (tr (" '%1' is not a file." ).arg (exePath));
61
39
}
62
40
63
- exitCode = sshExitCode (m_hostname , {QLatin1String (" test" ), QLatin1String (" -x" ), exePath});
41
+ exitCode = sshExitCode (m_deviceName , {QLatin1String (" test" ), QLatin1String (" -x" ), exePath});
64
42
if (exitCode) {
65
43
emit recordingFailed (tr (" File '%1' is not executable." ).arg (exePath));
66
44
}
@@ -110,32 +88,32 @@ void PerfRecordSSH::sendInput(const QByteArray& input)
110
88
111
89
QString PerfRecordSSH::currentUsername ()
112
90
{
113
- if (m_hostname .isEmpty ())
91
+ if (m_deviceName .isEmpty ())
114
92
return {};
115
- return sshOutput (m_hostname , {QLatin1String (" echo" ), QLatin1String (" $USERNAME" )}).simplified ();
93
+ return sshOutput (m_deviceName , {QLatin1String (" echo" ), QLatin1String (" $USERNAME" )}).simplified ();
116
94
}
117
95
118
96
bool PerfRecordSSH::canTrace (const QString& path)
119
97
{
120
- if (m_hostname .isEmpty ())
98
+ if (m_deviceName .isEmpty ())
121
99
return false ;
122
100
123
101
// 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 ;
126
104
127
105
if (!isDir || !isReadable) {
128
106
return false ;
129
107
}
130
108
131
109
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" )});
133
111
return paranoid.trimmed () == QLatin1String (" -1" );
134
112
}
135
113
136
114
bool PerfRecordSSH::canProfileOffCpu ()
137
115
{
138
- if (m_hostname .isEmpty ())
116
+ if (m_deviceName .isEmpty ())
139
117
return false ;
140
118
return canTrace (QStringLiteral (" events/sched/sched_switch" ));
141
119
}
@@ -166,16 +144,16 @@ static QString perfBuildOptions(const QString& hostname)
166
144
167
145
bool PerfRecordSSH::canSampleCpu ()
168
146
{
169
- if (m_hostname .isEmpty ())
147
+ if (m_deviceName .isEmpty ())
170
148
return false ;
171
- return perfRecordHelp (m_hostname ).contains (QLatin1String (" --sample-cpu" ));
149
+ return perfRecordHelp (m_deviceName ).contains (QLatin1String (" --sample-cpu" ));
172
150
}
173
151
174
152
bool PerfRecordSSH::canSwitchEvents ()
175
153
{
176
- if (m_hostname .isEmpty ())
154
+ if (m_deviceName .isEmpty ())
177
155
return false ;
178
- return perfRecordHelp (m_hostname ).contains (QLatin1String (" --switch-events" ));
156
+ return perfRecordHelp (m_deviceName ).contains (QLatin1String (" --switch-events" ));
179
157
}
180
158
181
159
bool PerfRecordSSH::canUseAio ()
@@ -186,16 +164,16 @@ bool PerfRecordSSH::canUseAio()
186
164
187
165
bool PerfRecordSSH::canCompress ()
188
166
{
189
- if (m_hostname .isEmpty ())
167
+ if (m_deviceName .isEmpty ())
190
168
return false ;
191
- return Zstd_FOUND && perfBuildOptions (m_hostname ).contains (QLatin1String (" zstd: [ on ]" ));
169
+ return Zstd_FOUND && perfBuildOptions (m_deviceName ).contains (QLatin1String (" zstd: [ on ]" ));
192
170
}
193
171
194
172
bool PerfRecordSSH::isPerfInstalled ()
195
173
{
196
- if (m_hostname .isEmpty ())
174
+ if (m_deviceName .isEmpty ())
197
175
return false ;
198
- return sshExitCode (m_hostname , {QLatin1String (" perf" )}) != 127 ;
176
+ return sshExitCode (m_deviceName , {QLatin1String (" perf" )}) != 127 ;
199
177
}
200
178
201
179
void PerfRecordSSH::startRecording (const QStringList& perfOptions, const QString& outputPath,
@@ -230,12 +208,13 @@ void PerfRecordSSH::startRecording(const QStringList& perfOptions, const QString
230
208
231
209
m_recordProcess = new QProcess (this );
232
210
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 ());
234
215
m_recordProcess->start ();
235
216
m_recordProcess->waitForStarted ();
236
217
237
- qDebug () << m_recordProcess->arguments ().join (QLatin1Char (' ' ));
238
-
239
218
emit recordingStarted (QLatin1String (" perf" ), perfCommand);
240
219
241
220
connect (m_recordProcess, &QProcess::readyReadStandardOutput, this ,
0 commit comments