2014-02-15 18:49:35 +05:30
|
|
|
#include "JProfiler.h"
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
2014-07-01 05:18:09 +05:30
|
|
|
#include "logic/settings/SettingsObject.h"
|
2015-01-28 03:01:07 +05:30
|
|
|
#include "logic/BaseProcess.h"
|
2014-02-16 02:56:44 +05:30
|
|
|
#include "logic/BaseInstance.h"
|
2014-02-15 18:49:35 +05:30
|
|
|
#include "MultiMC.h"
|
|
|
|
|
2014-03-30 23:41:05 +05:30
|
|
|
JProfiler::JProfiler(InstancePtr instance, QObject *parent) : BaseProfiler(instance, parent)
|
2014-02-15 18:49:35 +05:30
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-28 03:01:07 +05:30
|
|
|
void JProfiler::beginProfilingImpl(BaseProcess *process)
|
2014-02-15 18:49:35 +05:30
|
|
|
{
|
|
|
|
int port = MMC->settings()->get("JProfilerPort").toInt();
|
|
|
|
QProcess *profiler = new QProcess(this);
|
2014-02-15 22:45:41 +05:30
|
|
|
profiler->setArguments(QStringList() << "-d" << QString::number(pid(process)) << "--gui"
|
2014-02-15 18:49:35 +05:30
|
|
|
<< "-p" << QString::number(port));
|
|
|
|
profiler->setProgram(QDir(MMC->settings()->get("JProfilerPath").toString())
|
2014-11-03 00:46:29 +05:30
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
.absoluteFilePath("bin/jpenable.exe"));
|
|
|
|
#else
|
2014-02-15 18:49:35 +05:30
|
|
|
.absoluteFilePath("bin/jpenable"));
|
2014-11-03 00:46:29 +05:30
|
|
|
#endif
|
2014-02-15 18:49:35 +05:30
|
|
|
connect(profiler, &QProcess::started, [this, port]()
|
|
|
|
{ emit readyToLaunch(tr("Listening on port: %1").arg(port)); });
|
2014-02-16 13:24:52 +05:30
|
|
|
connect(profiler,
|
|
|
|
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
|
|
|
[this](int exit, QProcess::ExitStatus status)
|
|
|
|
{
|
2014-02-16 14:00:38 +05:30
|
|
|
if (status == QProcess::CrashExit)
|
2014-02-16 13:24:52 +05:30
|
|
|
{
|
|
|
|
emit abortLaunch(tr("Profiler aborted"));
|
|
|
|
}
|
2014-02-16 14:00:38 +05:30
|
|
|
if (m_profilerProcess)
|
|
|
|
{
|
|
|
|
m_profilerProcess->deleteLater();
|
|
|
|
m_profilerProcess = 0;
|
|
|
|
}
|
2014-02-16 13:24:52 +05:30
|
|
|
});
|
2014-02-15 18:49:35 +05:30
|
|
|
profiler->start();
|
2014-02-16 14:00:38 +05:30
|
|
|
m_profilerProcess = profiler;
|
2014-02-15 18:49:35 +05:30
|
|
|
}
|
|
|
|
|
2014-09-06 21:46:56 +05:30
|
|
|
void JProfilerFactory::registerSettings(std::shared_ptr<SettingsObject> settings)
|
2014-02-15 18:49:35 +05:30
|
|
|
{
|
|
|
|
settings->registerSetting("JProfilerPath");
|
|
|
|
settings->registerSetting("JProfilerPort", 42042);
|
|
|
|
}
|
|
|
|
|
2014-03-30 23:41:05 +05:30
|
|
|
BaseExternalTool *JProfilerFactory::createTool(InstancePtr instance, QObject *parent)
|
2014-02-15 18:49:35 +05:30
|
|
|
{
|
|
|
|
return new JProfiler(instance, parent);
|
|
|
|
}
|
|
|
|
|
2014-02-16 02:56:44 +05:30
|
|
|
bool JProfilerFactory::check(QString *error)
|
|
|
|
{
|
|
|
|
return check(MMC->settings()->get("JProfilerPath").toString(), error);
|
|
|
|
}
|
|
|
|
|
2014-02-15 18:49:35 +05:30
|
|
|
bool JProfilerFactory::check(const QString &path, QString *error)
|
|
|
|
{
|
2014-02-16 02:56:44 +05:30
|
|
|
if (path.isEmpty())
|
|
|
|
{
|
|
|
|
*error = QObject::tr("Empty path");
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-15 18:49:35 +05:30
|
|
|
QDir dir(path);
|
|
|
|
if (!dir.exists())
|
|
|
|
{
|
|
|
|
*error = QObject::tr("Path does not exist");
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-03 00:46:29 +05:30
|
|
|
if (!dir.exists("bin") || !(dir.exists("bin/jprofiler") || dir.exists("bin/jprofiler.exe")) || !dir.exists("bin/agent.jar"))
|
2014-02-15 18:49:35 +05:30
|
|
|
{
|
|
|
|
*error = QObject::tr("Invalid JProfiler install");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|