2014-02-15 18:49:35 +05:30
|
|
|
#include "JProfiler.h"
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "settings/SettingsObject.h"
|
|
|
|
#include "BaseProcess.h"
|
|
|
|
#include "BaseInstance.h"
|
2014-02-15 18:49:35 +05:30
|
|
|
|
2015-04-07 00:22:59 +05:30
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2015-02-09 06:21:14 +05:30
|
|
|
JProfiler::JProfiler(SettingsObjectPtr settings, InstancePtr instance,
|
|
|
|
QObject *parent)
|
|
|
|
: BaseProfiler(settings, instance, parent)
|
2014-02-15 18:49:35 +05:30
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-07 00:22:59 +05:30
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 03:01:07 +05:30
|
|
|
void JProfiler::beginProfilingImpl(BaseProcess *process)
|
2014-02-15 18:49:35 +05:30
|
|
|
{
|
2015-04-07 00:22:59 +05:30
|
|
|
listeningPort = globalSettings->get("JProfilerPort").toInt();
|
2014-02-15 18:49:35 +05:30
|
|
|
QProcess *profiler = new QProcess(this);
|
2015-04-07 00:22:59 +05:30
|
|
|
QStringList profilerArgs =
|
|
|
|
{
|
|
|
|
"-d", QString::number(pid(process)),
|
|
|
|
"--gui",
|
|
|
|
"-p", QString::number(listeningPort)
|
|
|
|
};
|
|
|
|
auto basePath = globalSettings->get("JProfilerPath").toString();
|
|
|
|
|
2014-11-03 00:46:29 +05:30
|
|
|
#ifdef Q_OS_WIN
|
2015-04-07 00:22:59 +05:30
|
|
|
QString profilerProgram = QDir(basePath).absoluteFilePath("bin/jpenable.exe");
|
2014-11-03 00:46:29 +05:30
|
|
|
#else
|
2015-04-07 00:22:59 +05:30
|
|
|
QString profilerProgram = QDir(basePath).absoluteFilePath("bin/jpenable");
|
2014-11-03 00:46:29 +05:30
|
|
|
#endif
|
2015-04-07 00:22:59 +05:30
|
|
|
|
|
|
|
profiler->setArguments(profilerArgs);
|
|
|
|
profiler->setProgram(profilerProgram);
|
|
|
|
|
|
|
|
connect(profiler, SIGNAL(started()), SLOT(profilerStarted()));
|
|
|
|
connect(profiler, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(profilerFinished(int,QProcess::ExitStatus)));
|
|
|
|
|
2014-02-16 14:00:38 +05:30
|
|
|
m_profilerProcess = profiler;
|
2015-04-07 00:22:59 +05:30
|
|
|
profiler->start();
|
2014-02-15 18:49:35 +05:30
|
|
|
}
|
|
|
|
|
2015-02-09 06:21:14 +05:30
|
|
|
void JProfilerFactory::registerSettings(SettingsObjectPtr settings)
|
2014-02-15 18:49:35 +05:30
|
|
|
{
|
|
|
|
settings->registerSetting("JProfilerPath");
|
|
|
|
settings->registerSetting("JProfilerPort", 42042);
|
2015-02-09 06:21:14 +05:30
|
|
|
globalSettings = settings;
|
2014-02-15 18:49:35 +05:30
|
|
|
}
|
|
|
|
|
2014-03-30 23:41:05 +05:30
|
|
|
BaseExternalTool *JProfilerFactory::createTool(InstancePtr instance, QObject *parent)
|
2014-02-15 18:49:35 +05:30
|
|
|
{
|
2015-02-09 06:21:14 +05:30
|
|
|
return new JProfiler(globalSettings, instance, parent);
|
2014-02-15 18:49:35 +05:30
|
|
|
}
|
|
|
|
|
2014-02-16 02:56:44 +05:30
|
|
|
bool JProfilerFactory::check(QString *error)
|
|
|
|
{
|
2015-02-09 06:21:14 +05:30
|
|
|
return check(globalSettings->get("JProfilerPath").toString(), error);
|
2014-02-16 02:56:44 +05:30
|
|
|
}
|
|
|
|
|
2014-02-15 18:49:35 +05:30
|
|
|
bool JProfilerFactory::check(const QString &path, QString *error)
|
|
|
|
{
|
2014-02-16 02:56:44 +05:30
|
|
|
if (path.isEmpty())
|
|
|
|
{
|
|
|
|
*error = QObject::tr("Empty path");
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-15 18:49:35 +05:30
|
|
|
QDir dir(path);
|
|
|
|
if (!dir.exists())
|
|
|
|
{
|
|
|
|
*error = QObject::tr("Path does not exist");
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-03 00:46:29 +05:30
|
|
|
if (!dir.exists("bin") || !(dir.exists("bin/jprofiler") || dir.exists("bin/jprofiler.exe")) || !dir.exists("bin/agent.jar"))
|
2014-02-15 18:49:35 +05:30
|
|
|
{
|
|
|
|
*error = QObject::tr("Invalid JProfiler install");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-07 00:22:59 +05:30
|
|
|
|
|
|
|
#include "JProfiler.moc"
|