2014-02-15 13:19:35 +00:00
|
|
|
#include "JProfiler.h"
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "settings/SettingsObject.h"
|
2015-07-10 00:11:06 +01:00
|
|
|
#include "launch/LaunchTask.h"
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "BaseInstance.h"
|
2014-02-15 13:19:35 +00:00
|
|
|
|
2015-04-06 19:52:59 +01:00
|
|
|
class JProfiler : public BaseProfiler
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
Q_OBJECT
|
2015-04-06 19:52:59 +01:00
|
|
|
public:
|
2018-07-15 13:51:05 +01:00
|
|
|
JProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0);
|
2015-04-06 19:52:59 +01:00
|
|
|
|
|
|
|
private slots:
|
2018-07-15 13:51:05 +01:00
|
|
|
void profilerStarted();
|
|
|
|
void profilerFinished(int exit, QProcess::ExitStatus status);
|
2015-04-06 19:52:59 +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
|
|
|
|
|
|
|
private:
|
2018-07-15 13:51:05 +01:00
|
|
|
int listeningPort = 0;
|
2015-04-06 19:52:59 +01:00
|
|
|
};
|
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
JProfiler::JProfiler(SettingsObjectPtr settings, InstancePtr instance,
|
2018-07-15 13:51:05 +01:00
|
|
|
QObject *parent)
|
|
|
|
: BaseProfiler(settings, instance, parent)
|
2014-02-15 13:19:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-06 19:52:59 +01:00
|
|
|
void JProfiler::profilerStarted()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
emit readyToLaunch(tr("Listening on port: %1").arg(listeningPort));
|
2015-04-06 19:52:59 +01:00
|
|
|
}
|
|
|
|
|
2023-07-01 07:51:15 +01:00
|
|
|
void JProfiler::profilerFinished([[maybe_unused]] int exit, QProcess::ExitStatus status)
|
2015-04-06 19:52:59 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
if (status == QProcess::CrashExit)
|
|
|
|
{
|
|
|
|
emit abortLaunch(tr("Profiler aborted"));
|
|
|
|
}
|
|
|
|
if (m_profilerProcess)
|
|
|
|
{
|
|
|
|
m_profilerProcess->deleteLater();
|
|
|
|
m_profilerProcess = 0;
|
|
|
|
}
|
2015-04-06 19:52:59 +01:00
|
|
|
}
|
|
|
|
|
2019-04-07 22:59:04 +01:00
|
|
|
void JProfiler::beginProfilingImpl(shared_qobject_ptr<LaunchTask> process)
|
2014-02-15 13:19:35 +00:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
listeningPort = globalSettings->get("JProfilerPort").toInt();
|
|
|
|
QProcess *profiler = new QProcess(this);
|
|
|
|
QStringList profilerArgs =
|
|
|
|
{
|
|
|
|
"-d", QString::number(process->pid()),
|
|
|
|
"--gui",
|
|
|
|
"-p", QString::number(listeningPort)
|
|
|
|
};
|
|
|
|
auto basePath = globalSettings->get("JProfilerPath").toString();
|
2015-04-06 19:52:59 +01:00
|
|
|
|
2014-11-02 19:16:29 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2018-07-15 13:51:05 +01:00
|
|
|
QString profilerProgram = QDir(basePath).absoluteFilePath("bin/jpenable.exe");
|
2014-11-02 19:16:29 +00:00
|
|
|
#else
|
2018-07-15 13:51:05 +01:00
|
|
|
QString profilerProgram = QDir(basePath).absoluteFilePath("bin/jpenable");
|
2014-11-02 19:16:29 +00:00
|
|
|
#endif
|
2015-04-06 19:52:59 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
profiler->setArguments(profilerArgs);
|
|
|
|
profiler->setProgram(profilerProgram);
|
2015-04-06 19:52:59 +01:00
|
|
|
|
2023-04-18 01:51:34 +01:00
|
|
|
connect(profiler, &QProcess::started, this, &JProfiler::profilerStarted);
|
|
|
|
connect(profiler, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &JProfiler::profilerFinished);
|
2015-04-06 19:52:59 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
m_profilerProcess = profiler;
|
|
|
|
profiler->start();
|
2014-02-15 13:19:35 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
void JProfilerFactory::registerSettings(SettingsObjectPtr settings)
|
2014-02-15 13:19:35 +00:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
settings->registerSetting("JProfilerPath");
|
|
|
|
settings->registerSetting("JProfilerPort", 42042);
|
|
|
|
globalSettings = settings;
|
2014-02-15 13:19:35 +00:00
|
|
|
}
|
|
|
|
|
2014-03-30 19:11:05 +01:00
|
|
|
BaseExternalTool *JProfilerFactory::createTool(InstancePtr instance, QObject *parent)
|
2014-02-15 13:19:35 +00:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
return new JProfiler(globalSettings, instance, parent);
|
2014-02-15 13:19:35 +00:00
|
|
|
}
|
|
|
|
|
2014-02-15 21:26:44 +00:00
|
|
|
bool JProfilerFactory::check(QString *error)
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
return check(globalSettings->get("JProfilerPath").toString(), error);
|
2014-02-15 21:26:44 +00:00
|
|
|
}
|
|
|
|
|
2014-02-15 13:19:35 +00:00
|
|
|
bool JProfilerFactory::check(const QString &path, QString *error)
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
if (path.isEmpty())
|
|
|
|
{
|
|
|
|
*error = QObject::tr("Empty path");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QDir dir(path);
|
|
|
|
if (!dir.exists())
|
|
|
|
{
|
|
|
|
*error = QObject::tr("Path does not exist");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!dir.exists("bin") || !(dir.exists("bin/jprofiler") || dir.exists("bin/jprofiler.exe")) || !dir.exists("bin/agent.jar"))
|
|
|
|
{
|
|
|
|
*error = QObject::tr("Invalid JProfiler install");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2014-02-15 13:19:35 +00:00
|
|
|
}
|
2015-04-06 19:52:59 +01:00
|
|
|
|
|
|
|
#include "JProfiler.moc"
|