diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-04-06 20:52:59 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-04-13 00:04:08 +0200 |
commit | 58840ac10cc7aac866d61cbcece3c3b9be1af8b4 (patch) | |
tree | 4641c42e20d33728bdc03fa7b4769084fae201e5 /logic/tools/JProfiler.cpp | |
parent | 3d3725f08820ee129c8edc5395687e5edd997537 (diff) | |
download | MultiMC-58840ac10cc7aac866d61cbcece3c3b9be1af8b4.tar MultiMC-58840ac10cc7aac866d61cbcece3c3b9be1af8b4.tar.gz MultiMC-58840ac10cc7aac866d61cbcece3c3b9be1af8b4.tar.lz MultiMC-58840ac10cc7aac866d61cbcece3c3b9be1af8b4.tar.xz MultiMC-58840ac10cc7aac866d61cbcece3c3b9be1af8b4.zip |
NOISSUE fix profilers
Diffstat (limited to 'logic/tools/JProfiler.cpp')
-rw-r--r-- | logic/tools/JProfiler.cpp | 79 |
1 files changed, 56 insertions, 23 deletions
diff --git a/logic/tools/JProfiler.cpp b/logic/tools/JProfiler.cpp index d53ec615..2522f2b3 100644 --- a/logic/tools/JProfiler.cpp +++ b/logic/tools/JProfiler.cpp @@ -7,42 +7,73 @@ #include "BaseProcess.h" #include "BaseInstance.h" +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(BaseProcess *process); + +private: + int listeningPort = 0; +}; + JProfiler::JProfiler(SettingsObjectPtr settings, InstancePtr instance, QObject *parent) : BaseProfiler(settings, instance, parent) { } +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(BaseProcess *process) { - int port = globalSettings->get("JProfilerPort").toInt(); + listeningPort = globalSettings->get("JProfilerPort").toInt(); QProcess *profiler = new QProcess(this); - profiler->setArguments(QStringList() << "-d" << QString::number(pid(process)) << "--gui" - << "-p" << QString::number(port)); - profiler->setProgram(QDir(globalSettings->get("JProfilerPath").toString()) + QStringList profilerArgs = + { + "-d", QString::number(pid(process)), + "--gui", + "-p", QString::number(listeningPort) + }; + auto basePath = globalSettings->get("JProfilerPath").toString(); + #ifdef Q_OS_WIN - .absoluteFilePath("bin/jpenable.exe")); + QString profilerProgram = QDir(basePath).absoluteFilePath("bin/jpenable.exe"); #else - .absoluteFilePath("bin/jpenable")); + QString profilerProgram = QDir(basePath).absoluteFilePath("bin/jpenable"); #endif - connect(profiler, &QProcess::started, [this, port]() - { emit readyToLaunch(tr("Listening on port: %1").arg(port)); }); - connect(profiler, - static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), - [this](int exit, QProcess::ExitStatus status) - { - if (status == QProcess::CrashExit) - { - emit abortLaunch(tr("Profiler aborted")); - } - if (m_profilerProcess) - { - m_profilerProcess->deleteLater(); - m_profilerProcess = 0; - } - }); - profiler->start(); + + profiler->setArguments(profilerArgs); + profiler->setProgram(profilerProgram); + + connect(profiler, SIGNAL(started()), SLOT(profilerStarted())); + connect(profiler, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(profilerFinished(int,QProcess::ExitStatus))); + m_profilerProcess = profiler; + profiler->start(); } void JProfilerFactory::registerSettings(SettingsObjectPtr settings) @@ -82,3 +113,5 @@ bool JProfilerFactory::check(const QString &path, QString *error) } return true; } + +#include "JProfiler.moc" |