Profiler support. Currently JProfiler and JVisualVM are implemented.
This commit is contained in:
		@@ -228,7 +228,6 @@ MinecraftProcess *OneSixInstance::prepareForLaunch(AuthSessionPtr session)
 | 
			
		||||
		launchScript += "ext " + finfo.absoluteFilePath() + "\n";
 | 
			
		||||
	}
 | 
			
		||||
	launchScript += "natives " + natives_dir.absolutePath() + "\n";
 | 
			
		||||
	launchScript += "launch onesix\n";
 | 
			
		||||
 | 
			
		||||
	// create the process and set its parameters
 | 
			
		||||
	MinecraftProcess *proc = new MinecraftProcess(this);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										19
									
								
								logic/profiler/BaseProfiler.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								logic/profiler/BaseProfiler.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
#include "BaseProfiler.h"
 | 
			
		||||
 | 
			
		||||
BaseProfiler::BaseProfiler(OneSixInstance *instance, QObject *parent)
 | 
			
		||||
	: QObject(parent), m_instance(instance)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BaseProfiler::~BaseProfiler()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BaseProfiler::beginProfiling(MinecraftProcess *process)
 | 
			
		||||
{
 | 
			
		||||
	beginProfilingImpl(process);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BaseProfilerFactory::~BaseProfilerFactory()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										39
									
								
								logic/profiler/BaseProfiler.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								logic/profiler/BaseProfiler.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <QObject>
 | 
			
		||||
 | 
			
		||||
class OneSixInstance;
 | 
			
		||||
class SettingsObject;
 | 
			
		||||
class MinecraftProcess;
 | 
			
		||||
 | 
			
		||||
class BaseProfiler : public QObject
 | 
			
		||||
{
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
	explicit BaseProfiler(OneSixInstance *instance, QObject *parent = 0);
 | 
			
		||||
	virtual ~BaseProfiler();
 | 
			
		||||
 | 
			
		||||
public
 | 
			
		||||
slots:
 | 
			
		||||
	void beginProfiling(MinecraftProcess *process);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	OneSixInstance *m_instance;
 | 
			
		||||
 | 
			
		||||
	virtual void beginProfilingImpl(MinecraftProcess *process) = 0;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
	void readyToLaunch(const QString &message);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class BaseProfilerFactory
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	virtual ~BaseProfilerFactory();
 | 
			
		||||
 | 
			
		||||
	virtual void registerSettings(SettingsObject *settings) = 0;
 | 
			
		||||
 | 
			
		||||
	virtual BaseProfiler *createProfiler(OneSixInstance *instance, QObject *parent = 0) = 0;
 | 
			
		||||
 | 
			
		||||
	virtual bool check(const QString &path, QString *error) = 0;
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										56
									
								
								logic/profiler/JProfiler.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								logic/profiler/JProfiler.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
			
		||||
#include "JProfiler.h"
 | 
			
		||||
 | 
			
		||||
#include <QDir>
 | 
			
		||||
#include <QMessageBox>
 | 
			
		||||
 | 
			
		||||
#include "settingsobject.h"
 | 
			
		||||
#include "logic/MinecraftProcess.h"
 | 
			
		||||
#include "logic/OneSixInstance.h"
 | 
			
		||||
#include "MultiMC.h"
 | 
			
		||||
 | 
			
		||||
JProfiler::JProfiler(OneSixInstance *instance, QObject *parent) : BaseProfiler(instance, parent)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void JProfiler::beginProfilingImpl(MinecraftProcess *process)
 | 
			
		||||
{
 | 
			
		||||
	int port = MMC->settings()->get("JProfilerPort").toInt();
 | 
			
		||||
	QProcess *profiler = new QProcess(this);
 | 
			
		||||
	profiler->setArguments(QStringList() << "-d" << QString::number(process->pid()) << "--gui"
 | 
			
		||||
										 << "-p" << QString::number(port));
 | 
			
		||||
	profiler->setProgram(QDir(MMC->settings()->get("JProfilerPath").toString())
 | 
			
		||||
							 .absoluteFilePath("bin/jpenable"));
 | 
			
		||||
	connect(profiler, &QProcess::started, [this, port]()
 | 
			
		||||
	{ emit readyToLaunch(tr("Listening on port: %1").arg(port)); });
 | 
			
		||||
	connect(profiler, SIGNAL(finished(int)), profiler, SLOT(deleteLater()));
 | 
			
		||||
	profiler->start();
 | 
			
		||||
	QMessageBox::information(0, tr("JProfiler"),
 | 
			
		||||
							 tr("JProfiler started and listening on port %1").arg(port));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void JProfilerFactory::registerSettings(SettingsObject *settings)
 | 
			
		||||
{
 | 
			
		||||
	settings->registerSetting("JProfilerPath");
 | 
			
		||||
	settings->registerSetting("JProfilerPort", 42042);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BaseProfiler *JProfilerFactory::createProfiler(OneSixInstance *instance, QObject *parent)
 | 
			
		||||
{
 | 
			
		||||
	return new JProfiler(instance, parent);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool JProfilerFactory::check(const QString &path, QString *error)
 | 
			
		||||
{
 | 
			
		||||
	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/agent.jar"))
 | 
			
		||||
	{
 | 
			
		||||
		*error = QObject::tr("Invalid JProfiler install");
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										21
									
								
								logic/profiler/JProfiler.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								logic/profiler/JProfiler.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "BaseProfiler.h"
 | 
			
		||||
 | 
			
		||||
class JProfiler : public BaseProfiler
 | 
			
		||||
{
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
	JProfiler(OneSixInstance *instance, QObject *parent = 0);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	void beginProfilingImpl(MinecraftProcess *process);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class JProfilerFactory : public BaseProfilerFactory
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	void registerSettings(SettingsObject *settings) override;
 | 
			
		||||
	BaseProfiler *createProfiler(OneSixInstance *instance, QObject *parent = 0) override;
 | 
			
		||||
	bool check(const QString &path, QString *error) override;
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										46
									
								
								logic/profiler/JVisualVM.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								logic/profiler/JVisualVM.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
#include "JVisualVM.h"
 | 
			
		||||
 | 
			
		||||
#include <QDir>
 | 
			
		||||
#include <QStandardPaths>
 | 
			
		||||
 | 
			
		||||
#include "settingsobject.h"
 | 
			
		||||
#include "logic/MinecraftProcess.h"
 | 
			
		||||
#include "logic/OneSixInstance.h"
 | 
			
		||||
 | 
			
		||||
JVisualVM::JVisualVM(OneSixInstance *instance, QObject *parent) : BaseProfiler(instance, parent)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void JVisualVM::beginProfilingImpl(MinecraftProcess *process)
 | 
			
		||||
{
 | 
			
		||||
	QProcess *profiler = new QProcess(this);
 | 
			
		||||
	profiler->setArguments(QStringList() << "--jdkhome"
 | 
			
		||||
										 << m_instance->settings().get("JavaPath").toString()
 | 
			
		||||
										 << "--openpid" << QString::number(process->pid()));
 | 
			
		||||
	profiler->setProgram("jvisualvm");
 | 
			
		||||
	connect(profiler, &QProcess::started, [this]()
 | 
			
		||||
	{ emit readyToLaunch(tr("JVisualVM started")); });
 | 
			
		||||
	connect(profiler, SIGNAL(finished(int)), profiler, SLOT(deleteLater()));
 | 
			
		||||
	profiler->start();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void JVisualVMFactory::registerSettings(SettingsObject *settings)
 | 
			
		||||
{
 | 
			
		||||
	settings->registerSetting("JVisualVMPath");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BaseProfiler *JVisualVMFactory::createProfiler(OneSixInstance *instance, QObject *parent)
 | 
			
		||||
{
 | 
			
		||||
	return new JVisualVM(instance, parent);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool JVisualVMFactory::check(const QString &path, QString *error)
 | 
			
		||||
{
 | 
			
		||||
	QString resolved = QStandardPaths::findExecutable(path);
 | 
			
		||||
	if (resolved.isEmpty() && !QDir::isAbsolutePath(path))
 | 
			
		||||
	{
 | 
			
		||||
		*error = QObject::tr("Invalid path to JVisualVM");
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										21
									
								
								logic/profiler/JVisualVM.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								logic/profiler/JVisualVM.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "BaseProfiler.h"
 | 
			
		||||
 | 
			
		||||
class JVisualVM : public BaseProfiler
 | 
			
		||||
{
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
	JVisualVM(OneSixInstance *instance, QObject *parent = 0);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	void beginProfilingImpl(MinecraftProcess *process);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class JVisualVMFactory : public BaseProfilerFactory
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	void registerSettings(SettingsObject *settings) override;
 | 
			
		||||
	BaseProfiler *createProfiler(OneSixInstance *instance, QObject *parent = 0) override;
 | 
			
		||||
	bool check(const QString &path, QString *error) override;
 | 
			
		||||
};
 | 
			
		||||
		Reference in New Issue
	
	Block a user