2014-02-15 13:19:35 +00:00
|
|
|
#include "JVisualVM.h"
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "BaseInstance.h"
|
2023-08-14 17:16:53 +01:00
|
|
|
#include "launch/LaunchTask.h"
|
|
|
|
#include "settings/SettingsObject.h"
|
2014-02-15 13:19:35 +00:00
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
class JVisualVM : public BaseProfiler {
|
2015-04-06 19:52:59 +01:00
|
|
|
Q_OBJECT
|
2023-08-14 17:16:53 +01:00
|
|
|
public:
|
|
|
|
JVisualVM(SettingsObjectPtr settings, InstancePtr instance, QObject* parent = 0);
|
2015-04-06 19:52:59 +01:00
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
private slots:
|
2015-04-06 19:52:59 +01:00
|
|
|
void profilerStarted();
|
|
|
|
void profilerFinished(int exit, QProcess::ExitStatus status);
|
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
protected:
|
2019-04-07 22:59:04 +01:00
|
|
|
void beginProfilingImpl(shared_qobject_ptr<LaunchTask> process);
|
2015-04-06 19:52:59 +01:00
|
|
|
};
|
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
JVisualVM::JVisualVM(SettingsObjectPtr settings, InstancePtr instance, QObject* parent) : BaseProfiler(settings, instance, parent) {}
|
2014-02-15 13:19:35 +00:00
|
|
|
|
2015-04-06 19:52:59 +01:00
|
|
|
void JVisualVM::profilerStarted()
|
|
|
|
{
|
|
|
|
emit readyToLaunch(tr("JVisualVM started"));
|
|
|
|
}
|
|
|
|
|
2023-07-01 07:51:15 +01:00
|
|
|
void JVisualVM::profilerFinished([[maybe_unused]] int exit, QProcess::ExitStatus status)
|
2015-04-06 19:52:59 +01:00
|
|
|
{
|
2023-08-14 17:16:53 +01:00
|
|
|
if (status == QProcess::CrashExit) {
|
2015-04-06 19:52:59 +01:00
|
|
|
emit abortLaunch(tr("Profiler aborted"));
|
|
|
|
}
|
2023-08-14 17:16:53 +01:00
|
|
|
if (m_profilerProcess) {
|
2015-04-06 19:52:59 +01:00
|
|
|
m_profilerProcess->deleteLater();
|
|
|
|
m_profilerProcess = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-07 22:59:04 +01:00
|
|
|
void JVisualVM::beginProfilingImpl(shared_qobject_ptr<LaunchTask> process)
|
2014-02-15 13:19:35 +00:00
|
|
|
{
|
2023-08-14 17:16:53 +01:00
|
|
|
QProcess* profiler = new QProcess(this);
|
|
|
|
QStringList profilerArgs = { "--openpid", QString::number(process->pid()) };
|
2015-04-06 19:52:59 +01:00
|
|
|
auto programPath = globalSettings->get("JVisualVMPath").toString();
|
|
|
|
|
|
|
|
profiler->setArguments(profilerArgs);
|
|
|
|
profiler->setProgram(programPath);
|
|
|
|
|
2023-04-18 01:51:34 +01:00
|
|
|
connect(profiler, &QProcess::started, this, &JVisualVM::profilerStarted);
|
2023-08-14 17:16:53 +01:00
|
|
|
connect(profiler, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &JVisualVM::profilerFinished);
|
2015-04-06 19:52:59 +01:00
|
|
|
|
2014-02-15 13:19:35 +00:00
|
|
|
profiler->start();
|
2014-02-16 07:54:52 +00:00
|
|
|
m_profilerProcess = profiler;
|
2014-02-15 13:19:35 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
void JVisualVMFactory::registerSettings(SettingsObjectPtr settings)
|
2014-02-15 13:19:35 +00:00
|
|
|
{
|
2014-02-16 11:00:38 +00:00
|
|
|
QString defaultValue = QStandardPaths::findExecutable("jvisualvm");
|
2023-08-14 17:16:53 +01:00
|
|
|
if (defaultValue.isNull()) {
|
2014-02-16 11:00:38 +00:00
|
|
|
defaultValue = QStandardPaths::findExecutable("visualvm");
|
|
|
|
}
|
|
|
|
settings->registerSetting("JVisualVMPath", defaultValue);
|
2015-02-09 00:51:14 +00:00
|
|
|
globalSettings = settings;
|
2014-02-15 13:19:35 +00:00
|
|
|
}
|
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
BaseExternalTool* JVisualVMFactory::createTool(InstancePtr instance, QObject* parent)
|
2014-02-15 13:19:35 +00:00
|
|
|
{
|
2015-02-09 00:51:14 +00:00
|
|
|
return new JVisualVM(globalSettings, instance, parent);
|
2014-02-15 13:19:35 +00:00
|
|
|
}
|
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
bool JVisualVMFactory::check(QString* error)
|
2014-02-15 21:26:44 +00:00
|
|
|
{
|
2015-02-09 00:51:14 +00:00
|
|
|
return check(globalSettings->get("JVisualVMPath").toString(), error);
|
2014-02-15 21:26:44 +00:00
|
|
|
}
|
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
bool JVisualVMFactory::check(const QString& path, QString* error)
|
2014-02-15 13:19:35 +00:00
|
|
|
{
|
2023-08-14 17:16:53 +01:00
|
|
|
if (path.isEmpty()) {
|
2014-02-15 21:26:44 +00:00
|
|
|
*error = QObject::tr("Empty path");
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-06 00:51:22 +00:00
|
|
|
QFileInfo finfo(path);
|
2023-08-14 17:16:53 +01:00
|
|
|
if (!finfo.isExecutable() || !finfo.fileName().contains("visualvm")) {
|
2014-02-15 13:19:35 +00:00
|
|
|
*error = QObject::tr("Invalid path to JVisualVM");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-06 19:52:59 +01:00
|
|
|
|
|
|
|
#include "JVisualVM.moc"
|