@@ -72,24 +72,22 @@ bool PerfRecord::runPerf(bool elevatePrivileges, const QStringList& perfOptions,
72
72
m_perfRecordProcess->kill ();
73
73
m_perfRecordProcess->deleteLater ();
74
74
}
75
- m_perfRecordProcess = new QProcess (this );
76
- m_perfRecordProcess->setProcessChannelMode (QProcess::MergedChannels);
77
75
78
- const auto outputFileInfo = QFileInfo (outputPath);
79
- const auto folderPath = outputFileInfo.dir ().path ();
80
- const auto folderInfo = QFileInfo (folderPath);
81
- if (!folderInfo.exists ()) {
82
- emit recordingFailed (tr (" Folder '%1' does not exist." ).arg (folderPath));
83
- return false ;
84
- }
85
- if (!folderInfo.isDir ()) {
86
- emit recordingFailed (tr (" '%1' is not a folder." ).arg (folderPath));
87
- return false ;
88
- }
89
- if (!folderInfo.isWritable ()) {
90
- emit recordingFailed (tr (" Folder '%1' is not writable." ).arg (folderPath));
91
- return false ;
76
+ m_outputPath = outputPath;
77
+ m_userTerminated = false ;
78
+
79
+ if (m_host->isLocal ()) {
80
+ return runPerfLocal (elevatePrivileges, perfOptions, outputPath, workingDirectory);
81
+ } else {
82
+ return runPerfRemote (perfOptions, outputPath, workingDirectory);
92
83
}
84
+ }
85
+
86
+ bool PerfRecord::runPerfLocal (bool elevatePrivileges, const QStringList& perfOptions, const QString& outputPath,
87
+ const QString& workingDirectory)
88
+ {
89
+ m_perfRecordProcess = new QProcess (this );
90
+ m_perfRecordProcess->setProcessChannelMode (QProcess::MergedChannels);
93
91
94
92
connect (m_perfRecordProcess.data (), static_cast <void (QProcess::*)(int , QProcess::ExitStatus)>(&QProcess::finished),
95
93
this , [this ](int exitCode, QProcess::ExitStatus exitStatus) {
@@ -123,9 +121,6 @@ bool PerfRecord::runPerf(bool elevatePrivileges, const QStringList& perfOptions,
123
121
emit recordingOutput (output);
124
122
});
125
123
126
- m_outputPath = outputPath;
127
- m_userTerminated = false ;
128
-
129
124
if (!workingDirectory.isEmpty ()) {
130
125
m_perfRecordProcess->setWorkingDirectory (workingDirectory);
131
126
}
@@ -162,6 +157,61 @@ bool PerfRecord::runPerf(bool elevatePrivileges, const QStringList& perfOptions,
162
157
return true ;
163
158
}
164
159
160
+ bool PerfRecord::runPerfRemote (const QStringList& perfOptions, const QString& outputPath,
161
+ const QString& workingDirectory)
162
+ {
163
+ m_perfRecordProcess = m_host->remoteDevice ().runPerf (workingDirectory, perfOptions);
164
+
165
+ auto output = new QFile (outputPath, m_perfRecordProcess);
166
+ if (!output->open (QIODevice::WriteOnly)) {
167
+ emit recordingFailed (QStringLiteral (" Failed to create output file: %1" ).arg (outputPath));
168
+ return false ;
169
+ }
170
+
171
+ connect (m_perfRecordProcess.data (), &QProcess::readyReadStandardOutput, m_perfRecordProcess,
172
+ [process = m_perfRecordProcess, output] {
173
+ auto data = process->readAllStandardOutput ();
174
+ qDebug () << data;
175
+ output->write (data);
176
+ });
177
+ connect (m_perfRecordProcess.data (), &QProcess::readyReadStandardError, m_perfRecordProcess,
178
+ [this ] { emit recordingOutput (QString::fromUtf8 (m_perfRecordProcess->readAllStandardError ())); });
179
+
180
+ connect (m_perfRecordProcess.data (), static_cast <void (QProcess::*)(int , QProcess::ExitStatus)>(&QProcess::finished),
181
+ this , [this , output](int exitCode, QProcess::ExitStatus exitStatus) {
182
+ Q_UNUSED (exitStatus)
183
+
184
+ output->close ();
185
+ output->deleteLater ();
186
+
187
+ const auto outputFileInfo = QFileInfo (m_outputPath);
188
+ qDebug () << exitCode << EXIT_SUCCESS << outputFileInfo.exists () << outputFileInfo.size ();
189
+ if ((exitCode == EXIT_SUCCESS || (exitCode == SIGTERM && m_userTerminated) || outputFileInfo.size () > 0 )
190
+ && outputFileInfo.exists ()) {
191
+ if (exitCode != EXIT_SUCCESS && !m_userTerminated) {
192
+ emit debuggeeCrashed ();
193
+ }
194
+ emit recordingFinished (m_outputPath);
195
+ } else {
196
+ emit recordingFailed (tr (" Failed to record perf data, error code %1." ).arg (exitCode));
197
+ }
198
+ m_userTerminated = false ;
199
+ });
200
+
201
+ connect (m_perfRecordProcess.data (), &QProcess::errorOccurred, this , [this ](QProcess::ProcessError error) {
202
+ Q_UNUSED (error)
203
+ if (!m_userTerminated) {
204
+ emit recordingFailed (m_perfRecordProcess->errorString ());
205
+ }
206
+ });
207
+
208
+ connect (m_perfRecordProcess.data (), &QProcess::started, this ,
209
+ [this ] { emit recordingStarted (m_perfRecordProcess->program (), m_perfRecordProcess->arguments ()); });
210
+
211
+ m_perfRecordProcess->start ();
212
+ return true ;
213
+ }
214
+
165
215
void PerfRecord::record (const QStringList& perfOptions, const QString& outputPath, bool elevatePrivileges,
166
216
const QStringList& pids)
167
217
{
0 commit comments