pollymc/logic/tools/JProfiler.cpp

118 lines
2.8 KiB
C++
Raw Normal View History

#include "JProfiler.h"
#include <QDir>
#include <QMessageBox>
2015-02-09 06:21:14 +05:30
#include "settings/SettingsObject.h"
#include "BaseLauncher.h"
2015-02-09 06:21:14 +05:30
#include "BaseInstance.h"
2015-04-07 00:22:59 +05:30
class JProfiler : public BaseProfiler
{
Q_OBJECT
public:
JProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject *parent = 0);
private slots:
void profilerStarted();
void profilerFinished(int exit, QProcess::ExitStatus status);
protected:
void beginProfilingImpl(std::shared_ptr<BaseLauncher> process);
2015-04-07 00:22:59 +05:30
private:
int listeningPort = 0;
};
2015-02-09 06:21:14 +05:30
JProfiler::JProfiler(SettingsObjectPtr settings, InstancePtr instance,
QObject *parent)
: BaseProfiler(settings, instance, parent)
{
}
2015-04-07 00:22:59 +05:30
void JProfiler::profilerStarted()
{
emit readyToLaunch(tr("Listening on port: %1").arg(listeningPort));
}
void JProfiler::profilerFinished(int exit, QProcess::ExitStatus status)
{
if (status == QProcess::CrashExit)
{
emit abortLaunch(tr("Profiler aborted"));
}
if (m_profilerProcess)
{
m_profilerProcess->deleteLater();
m_profilerProcess = 0;
}
}
void JProfiler::beginProfilingImpl(std::shared_ptr<BaseLauncher> process)
{
2015-04-07 00:22:59 +05:30
listeningPort = globalSettings->get("JProfilerPort").toInt();
QProcess *profiler = new QProcess(this);
2015-04-07 00:22:59 +05:30
QStringList profilerArgs =
{
"-d", QString::number(process->pid()),
2015-04-07 00:22:59 +05:30
"--gui",
"-p", QString::number(listeningPort)
};
auto basePath = globalSettings->get("JProfilerPath").toString();
#ifdef Q_OS_WIN
2015-04-07 00:22:59 +05:30
QString profilerProgram = QDir(basePath).absoluteFilePath("bin/jpenable.exe");
#else
2015-04-07 00:22:59 +05:30
QString profilerProgram = QDir(basePath).absoluteFilePath("bin/jpenable");
#endif
2015-04-07 00:22:59 +05:30
profiler->setArguments(profilerArgs);
profiler->setProgram(profilerProgram);
connect(profiler, SIGNAL(started()), SLOT(profilerStarted()));
connect(profiler, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(profilerFinished(int,QProcess::ExitStatus)));
2014-02-16 14:00:38 +05:30
m_profilerProcess = profiler;
2015-04-07 00:22:59 +05:30
profiler->start();
}
2015-02-09 06:21:14 +05:30
void JProfilerFactory::registerSettings(SettingsObjectPtr settings)
{
settings->registerSetting("JProfilerPath");
settings->registerSetting("JProfilerPort", 42042);
2015-02-09 06:21:14 +05:30
globalSettings = settings;
}
2014-03-30 23:41:05 +05:30
BaseExternalTool *JProfilerFactory::createTool(InstancePtr instance, QObject *parent)
{
2015-02-09 06:21:14 +05:30
return new JProfiler(globalSettings, instance, parent);
}
bool JProfilerFactory::check(QString *error)
{
2015-02-09 06:21:14 +05:30
return check(globalSettings->get("JProfilerPath").toString(), error);
}
bool JProfilerFactory::check(const QString &path, QString *error)
{
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;
}
2015-04-07 00:22:59 +05:30
#include "JProfiler.moc"