pollymc/api/logic/tools/JProfiler.cpp

117 lines
3.0 KiB
C++
Raw Normal View History

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