1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "perfprofilerruncontrol.h"
#include "perfdatareader.h"
#include "perfprofilertool.h"
#include "perfprofilertr.h"
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/environmentkitaspect.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runcontrol.h>
#include <projectexplorer/target.h>
#include <remotelinux/remotelinux_constants.h>
#include <utils/qtcprocess.h>
#include <QAction>
#include <QMessageBox>
#include <QTcpServer>
using namespace ProjectExplorer;
using namespace Utils;
namespace PerfProfiler::Internal {
class PerfParserWorker final : public RunWorker
{
public:
explicit PerfParserWorker(RunControl *runControl)
: RunWorker(runControl)
{
setId("PerfParser");
auto tool = PerfProfilerTool::instance();
m_reader.setTraceManager(&traceManager());
m_reader.triggerRecordingStateChange(tool->isRecording());
connect(tool, &PerfProfilerTool::recordingChanged,
&m_reader, &PerfDataReader::triggerRecordingStateChange);
connect(&m_reader, &PerfDataReader::updateTimestamps,
tool, &PerfProfilerTool::updateTime);
connect(&m_reader, &PerfDataReader::starting,
tool, &PerfProfilerTool::startLoading);
connect(&m_reader, &PerfDataReader::started, tool, &PerfProfilerTool::onReaderStarted);
connect(&m_reader, &PerfDataReader::finishing, this, [tool] {
// Temporarily disable buttons.
tool->setToolActionsEnabled(false);
});
connect(&m_reader, &PerfDataReader::finished, tool, &PerfProfilerTool::onReaderFinished);
connect(&m_reader, &PerfDataReader::processStarted, this, &RunWorker::reportStarted);
connect(&m_reader, &PerfDataReader::processFinished, this, &RunWorker::reportStopped);
connect(&m_reader, &PerfDataReader::processFailed, this, &RunWorker::reportFailure);
}
void start() final
{
CommandLine cmd{findPerfParser()};
m_reader.addTargetArguments(&cmd, runControl());
if (runControl()->usesPerfChannel()) { // The channel is only used with qdb currently.
const QUrl url = runControl()->perfChannel();
QTC_CHECK(url.isValid());
cmd.addArgs({"--host", url.host(), "--port", QString::number(url.port())});
}
appendMessage("PerfParser args: " + cmd.arguments(), NormalMessageFormat);
m_reader.createParser(cmd);
m_reader.startParser();
}
void stop() final
{
m_reader.stopParser();
}
PerfDataReader *reader() { return &m_reader;}
private:
PerfDataReader m_reader;
};
// Factories
class PerfRecordWorkerFactory final : public RunWorkerFactory
{
public:
PerfRecordWorkerFactory()
{
setProducer([](RunControl *runControl) {
auto runner = new ProcessRunner(runControl);
runner->setStartModifier([runner, runControl] {
const Store perfArgs = runControl->settingsData(PerfProfiler::Constants::PerfSettingsId);
const QString recordArgs = perfArgs[Constants::PerfRecordArgsId].toString();
CommandLine cmd({runControl->device()->filePath("perf"), {"record"}});
cmd.addArgs(recordArgs, CommandLine::Raw);
cmd.addArgs({"-o", "-", "--"});
cmd.addCommandLineAsArgs(runControl->commandLine(), CommandLine::Raw);
runner->setCommandLine(cmd);
runner->setWorkingDirectory(runControl->workingDirectory());
runner->setEnvironment(runControl->environment());
runControl->appendMessage("Starting Perf: " + cmd.toUserOutput(), NormalMessageFormat);
});
return runner;
});
addSupportedRunMode("PerfRecorder");
addSupportForLocalRunConfigs();
addSupportedDeviceType(RemoteLinux::Constants::GenericLinuxOsType);
addSupportedDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE);
addSupportedDeviceType("DockerDeviceType");
}
};
class PerfProfilerRunWorkerFactory final : public RunWorkerFactory
{
public:
PerfProfilerRunWorkerFactory()
{
setProducer([](RunControl *runControl) -> RunWorker * {
PerfParserWorker *perfParserWorker = new PerfParserWorker(runControl);
// There are currently two RunWorkerFactories reacting to that:
// PerfRecordRunnerFactory above for the generic case and
// QdbPerfProfilerWorkerFactory in boot2qt.
ProcessRunner *perfRecordWorker
= qobject_cast<ProcessRunner *>(runControl->createWorker("PerfRecorder"));
QTC_ASSERT(perfRecordWorker, return nullptr);
perfRecordWorker->suppressDefaultStdOutHandling();
perfParserWorker->addStartDependency(perfRecordWorker);
perfParserWorker->addStopDependency(perfRecordWorker);
perfRecordWorker->addStopDependency(perfParserWorker);
PerfProfilerTool::instance()->onWorkerCreation(runControl);
auto tool = PerfProfilerTool::instance();
QObject::connect(tool->stopAction(), &QAction::triggered,
runControl, &RunControl::initiateStop);
QObject::connect(runControl, &RunControl::started, PerfProfilerTool::instance(),
&PerfProfilerTool::onRunControlStarted);
QObject::connect(runControl, &RunControl::stopped, PerfProfilerTool::instance(),
&PerfProfilerTool::onRunControlFinished);
PerfDataReader *reader = perfParserWorker->reader();
QObject::connect(perfRecordWorker, &ProcessRunner::stdOutData,
perfParserWorker, [perfParserWorker, reader](const QByteArray &data) {
if (reader->feedParser(data))
return;
perfParserWorker->appendMessage(Tr::tr("Failed to transfer Perf data to perfparser."),
ErrorMessageFormat);
perfParserWorker->initiateStop();
});
return perfParserWorker;
});
addSupportedRunMode(ProjectExplorer::Constants::PERFPROFILER_RUN_MODE);
}
};
void setupPerfProfilerRunWorker()
{
static PerfProfilerRunWorkerFactory thePerfProfilerRunWorkerFactory;
static PerfRecordWorkerFactory thePerfRecordWorkerFactory;
}
} // PerfProfiler::Internal
|