2018-10-18 11:57:19 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "perftracepointdialog.h"
|
|
|
|
|
#include "ui_perftracepointdialog.h"
|
|
|
|
|
|
2019-01-28 10:05:38 +01:00
|
|
|
#include <projectexplorer/devicesupport/devicemanager.h>
|
2018-10-18 11:57:19 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
2019-03-13 08:06:08 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
#include <projectexplorer/runcontrol.h>
|
2018-10-18 11:57:19 +02:00
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
|
2019-03-13 08:06:08 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2022-02-28 12:25:26 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2019-03-13 08:06:08 +01:00
|
|
|
|
2018-10-18 11:57:19 +02:00
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
2021-08-10 16:19:02 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
2018-10-18 11:57:19 +02:00
|
|
|
namespace PerfProfiler {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
PerfTracePointDialog::PerfTracePointDialog() :
|
|
|
|
|
m_ui(new Ui::PerfTracePointDialog)
|
|
|
|
|
{
|
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
|
2019-11-21 16:32:50 +01:00
|
|
|
if (const Target *target = SessionManager::startupTarget()) {
|
|
|
|
|
const Kit *kit = target->kit();
|
|
|
|
|
QTC_ASSERT(kit, return);
|
2018-10-18 11:57:19 +02:00
|
|
|
|
2019-11-21 16:32:50 +01:00
|
|
|
m_device = DeviceKitAspect::device(kit);
|
|
|
|
|
if (!m_device) {
|
|
|
|
|
m_ui->textEdit->setPlainText(tr("Error: No device available for active target."));
|
|
|
|
|
return;
|
2019-01-28 10:05:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
2018-10-18 11:57:19 +02:00
|
|
|
|
2019-01-28 10:05:38 +01:00
|
|
|
if (!m_device) {
|
|
|
|
|
// There should at least be a desktop device.
|
2021-07-05 16:16:12 +02:00
|
|
|
m_device = DeviceManager::defaultDesktopDevice();
|
2019-01-28 10:05:38 +01:00
|
|
|
QTC_ASSERT(m_device, return);
|
|
|
|
|
}
|
2018-10-18 11:57:19 +02:00
|
|
|
|
|
|
|
|
QFile file(":/perfprofiler/tracepoints.sh");
|
2019-01-07 14:36:50 +01:00
|
|
|
if (file.open(QIODevice::ReadOnly)) {
|
|
|
|
|
m_ui->textEdit->setPlainText(QString::fromUtf8(file.readAll()));
|
|
|
|
|
} else {
|
|
|
|
|
m_ui->textEdit->setPlainText(tr("Error: Failed to load trace point script %1: %2.")
|
|
|
|
|
.arg(file.fileName()).arg(file.errorString()));
|
|
|
|
|
}
|
2018-10-18 11:57:19 +02:00
|
|
|
|
|
|
|
|
m_ui->privilegesChooser->setCurrentText(m_device->type() == Constants::DESKTOP_DEVICE_TYPE
|
|
|
|
|
? QLatin1String("pkexec") : QLatin1String("n.a."));
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-22 16:51:38 +01:00
|
|
|
PerfTracePointDialog::~PerfTracePointDialog() = default;
|
2018-10-18 11:57:19 +02:00
|
|
|
|
|
|
|
|
void PerfTracePointDialog::runScript()
|
|
|
|
|
{
|
2019-03-07 12:20:52 +01:00
|
|
|
m_ui->label->setText(tr("Executing script..."));
|
2018-10-18 11:57:19 +02:00
|
|
|
m_ui->textEdit->setReadOnly(true);
|
|
|
|
|
m_ui->privilegesChooser->setEnabled(false);
|
|
|
|
|
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
|
|
|
|
|
2022-04-29 17:08:17 +02:00
|
|
|
m_process.reset(new QtcProcess(this));
|
2022-02-28 11:00:01 +01:00
|
|
|
m_process->setWriteData(m_ui->textEdit->toPlainText().toUtf8());
|
|
|
|
|
m_ui->textEdit->clear();
|
2018-10-18 11:57:19 +02:00
|
|
|
|
|
|
|
|
const QString elevate = m_ui->privilegesChooser->currentText();
|
2021-08-10 09:19:30 +02:00
|
|
|
if (elevate != QLatin1String("n.a."))
|
2022-05-10 15:33:33 +02:00
|
|
|
m_process->setCommand({m_device->filePath(elevate), {"sh"}});
|
2021-08-10 09:19:30 +02:00
|
|
|
else
|
2022-05-10 15:33:33 +02:00
|
|
|
m_process->setCommand({m_device->filePath("sh"), {}});
|
2018-10-18 11:57:19 +02:00
|
|
|
|
2022-04-21 23:51:46 +02:00
|
|
|
connect(m_process.get(), &QtcProcess::done, this, &PerfTracePointDialog::handleProcessDone);
|
2022-02-11 17:38:16 +01:00
|
|
|
m_process->start();
|
2018-10-18 11:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-21 23:51:46 +02:00
|
|
|
void PerfTracePointDialog::handleProcessDone()
|
2018-10-18 11:57:19 +02:00
|
|
|
{
|
2022-04-21 23:51:46 +02:00
|
|
|
const QProcess::ProcessError error = m_process->error();
|
|
|
|
|
QString message;
|
|
|
|
|
if (error == QProcess::FailedToStart) {
|
|
|
|
|
message = tr("Failed to run trace point script: %1").arg(error);
|
|
|
|
|
} else if ((m_process->exitStatus() == QProcess::CrashExit) || (m_process->exitCode() != 0)) {
|
|
|
|
|
message = tr("Failed to create trace points.");
|
2018-10-18 11:57:19 +02:00
|
|
|
} else {
|
2022-04-21 23:51:46 +02:00
|
|
|
message = tr("Created trace points for: %1").arg(QString::fromUtf8(
|
|
|
|
|
m_process->readAllStandardOutput().trimmed().replace('\n', ", ")));
|
2018-10-18 11:57:19 +02:00
|
|
|
}
|
2022-04-21 23:51:46 +02:00
|
|
|
m_ui->label->setText(message);
|
2018-10-18 11:57:19 +02:00
|
|
|
m_ui->textEdit->setHtml(QString::fromUtf8(m_process->readAllStandardError()));
|
|
|
|
|
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
|
|
|
|
m_ui->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PerfTracePointDialog::accept()
|
|
|
|
|
{
|
|
|
|
|
if (m_process) {
|
|
|
|
|
QTC_CHECK(m_process->state() == QProcess::NotRunning);
|
|
|
|
|
QDialog::accept();
|
|
|
|
|
} else {
|
|
|
|
|
runScript();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PerfTracePointDialog::reject()
|
|
|
|
|
{
|
|
|
|
|
if (m_process)
|
|
|
|
|
m_process->kill();
|
|
|
|
|
else
|
|
|
|
|
QDialog::reject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace PerfProfiler
|