PrismLauncher/launcher/tools/JProfiler.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
3.0 KiB
C++
Raw Normal View History

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