summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorJan Dalheimer <jan@dalheimer.de>2014-02-15 14:19:35 +0100
committerJan Dalheimer <jan@dalheimer.de>2014-02-15 14:19:35 +0100
commitefa8e26a3f3f7ba5e536cd10e86303b4fe1baba0 (patch)
tree4fcd3e9f210c92dbeac9f820f2ab1fd2d6dd9e58 /logic
parent5cf599673db88b39100ffca78e10bbe5e10200d7 (diff)
downloadMultiMC-efa8e26a3f3f7ba5e536cd10e86303b4fe1baba0.tar
MultiMC-efa8e26a3f3f7ba5e536cd10e86303b4fe1baba0.tar.gz
MultiMC-efa8e26a3f3f7ba5e536cd10e86303b4fe1baba0.tar.lz
MultiMC-efa8e26a3f3f7ba5e536cd10e86303b4fe1baba0.tar.xz
MultiMC-efa8e26a3f3f7ba5e536cd10e86303b4fe1baba0.zip
Profiler support. Currently JProfiler and JVisualVM are implemented.
Diffstat (limited to 'logic')
-rw-r--r--logic/OneSixInstance.cpp1
-rw-r--r--logic/profiler/BaseProfiler.cpp19
-rw-r--r--logic/profiler/BaseProfiler.h39
-rw-r--r--logic/profiler/JProfiler.cpp56
-rw-r--r--logic/profiler/JProfiler.h21
-rw-r--r--logic/profiler/JVisualVM.cpp46
-rw-r--r--logic/profiler/JVisualVM.h21
7 files changed, 202 insertions, 1 deletions
diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp
index ae172f21..d987b693 100644
--- a/logic/OneSixInstance.cpp
+++ b/logic/OneSixInstance.cpp
@@ -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);
diff --git a/logic/profiler/BaseProfiler.cpp b/logic/profiler/BaseProfiler.cpp
new file mode 100644
index 00000000..788e9614
--- /dev/null
+++ b/logic/profiler/BaseProfiler.cpp
@@ -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()
+{
+}
diff --git a/logic/profiler/BaseProfiler.h b/logic/profiler/BaseProfiler.h
new file mode 100644
index 00000000..2986c8e1
--- /dev/null
+++ b/logic/profiler/BaseProfiler.h
@@ -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;
+};
diff --git a/logic/profiler/JProfiler.cpp b/logic/profiler/JProfiler.cpp
new file mode 100644
index 00000000..b9cf19a0
--- /dev/null
+++ b/logic/profiler/JProfiler.cpp
@@ -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;
+}
diff --git a/logic/profiler/JProfiler.h b/logic/profiler/JProfiler.h
new file mode 100644
index 00000000..9fa3591a
--- /dev/null
+++ b/logic/profiler/JProfiler.h
@@ -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;
+};
diff --git a/logic/profiler/JVisualVM.cpp b/logic/profiler/JVisualVM.cpp
new file mode 100644
index 00000000..31cc51b1
--- /dev/null
+++ b/logic/profiler/JVisualVM.cpp
@@ -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;
+}
diff --git a/logic/profiler/JVisualVM.h b/logic/profiler/JVisualVM.h
new file mode 100644
index 00000000..e72b75d9
--- /dev/null
+++ b/logic/profiler/JVisualVM.h
@@ -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;
+};