2014-02-15 13:19:35 +00:00
|
|
|
#include "JProfiler.h"
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "settings/SettingsObject.h"
|
|
|
|
#include "BaseProcess.h"
|
|
|
|
#include "BaseInstance.h"
|
2014-02-15 13:19:35 +00:00
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
JProfiler::JProfiler(SettingsObjectPtr settings, InstancePtr instance,
|
|
|
|
QObject *parent)
|
|
|
|
: BaseProfiler(settings, instance, parent)
|
2014-02-15 13:19:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
void JProfiler::beginProfilingImpl(BaseProcess *process)
|
2014-02-15 13:19:35 +00:00
|
|
|
{
|
2015-02-09 00:51:14 +00:00
|
|
|
int port = globalSettings->get("JProfilerPort").toInt();
|
2014-02-15 13:19:35 +00:00
|
|
|
QProcess *profiler = new QProcess(this);
|
2014-02-15 17:15:41 +00:00
|
|
|
profiler->setArguments(QStringList() << "-d" << QString::number(pid(process)) << "--gui"
|
2014-02-15 13:19:35 +00:00
|
|
|
<< "-p" << QString::number(port));
|
2015-02-09 00:51:14 +00:00
|
|
|
profiler->setProgram(QDir(globalSettings->get("JProfilerPath").toString())
|
2014-11-02 19:16:29 +00:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
.absoluteFilePath("bin/jpenable.exe"));
|
|
|
|
#else
|
2014-02-15 13:19:35 +00:00
|
|
|
.absoluteFilePath("bin/jpenable"));
|
2014-11-02 19:16:29 +00:00
|
|
|
#endif
|
2014-02-15 13:19:35 +00:00
|
|
|
connect(profiler, &QProcess::started, [this, port]()
|
|
|
|
{ emit readyToLaunch(tr("Listening on port: %1").arg(port)); });
|
2014-02-16 07:54:52 +00:00
|
|
|
connect(profiler,
|
|
|
|
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
|
|
|
[this](int exit, QProcess::ExitStatus status)
|
|
|
|
{
|
2014-02-16 08:30:38 +00:00
|
|
|
if (status == QProcess::CrashExit)
|
2014-02-16 07:54:52 +00:00
|
|
|
{
|
|
|
|
emit abortLaunch(tr("Profiler aborted"));
|
|
|
|
}
|
2014-02-16 08:30:38 +00:00
|
|
|
if (m_profilerProcess)
|
|
|
|
{
|
|
|
|
m_profilerProcess->deleteLater();
|
|
|
|
m_profilerProcess = 0;
|
|
|
|
}
|
2014-02-16 07:54:52 +00:00
|
|
|
});
|
2014-02-15 13:19:35 +00:00
|
|
|
profiler->start();
|
2014-02-16 08:30:38 +00:00
|
|
|
m_profilerProcess = profiler;
|
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
|
|
|
{
|
|
|
|
settings->registerSetting("JProfilerPath");
|
|
|
|
settings->registerSetting("JProfilerPort", 42042);
|
2015-02-09 00:51:14 +00:00
|
|
|
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
|
|
|
{
|
2015-02-09 00:51:14 +00: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)
|
|
|
|
{
|
2015-02-09 00:51:14 +00: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)
|
|
|
|
{
|
2014-02-15 21:26:44 +00:00
|
|
|
if (path.isEmpty())
|
|
|
|
{
|
|
|
|
*error = QObject::tr("Empty path");
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-15 13:19:35 +00:00
|
|
|
QDir dir(path);
|
|
|
|
if (!dir.exists())
|
|
|
|
{
|
|
|
|
*error = QObject::tr("Path does not exist");
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-02 19:16:29 +00:00
|
|
|
if (!dir.exists("bin") || !(dir.exists("bin/jprofiler") || dir.exists("bin/jprofiler.exe")) || !dir.exists("bin/agent.jar"))
|
2014-02-15 13:19:35 +00:00
|
|
|
{
|
|
|
|
*error = QObject::tr("Invalid JProfiler install");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|