Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ set(
set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/applications)
set(ICON_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/icons)

option(ICEMON_DEVELOPER_BUILD "Enable Icemon developer mode" OFF)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config-icemon.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config-icemon.h
Expand Down
2 changes: 2 additions & 0 deletions config-icemon.h.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#define ICEMON_VERSION_STRING "@ICEMON_VERSION_STRING@"

#cmakedefine01 ICEMON_DEVELOPER_BUILD

#cmakedefine01 ICECC_HAVE_LOGGING_H
#cmakedefine01 ICECC_TEST_USE_OLD_MSG_API
8 changes: 4 additions & 4 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ set_package_properties(pandoc PROPERTIES
)

if (pandoc_FOUND)
add_custom_target(manpage)
add_custom_command(
TARGET manpage
OUTPUT icemon.1
COMMAND ${pandoc_EXECUTABLE} -s -t man ${CMAKE_CURRENT_SOURCE_DIR}/icemon.md
-o ${CMAKE_CURRENT_BINARY_DIR}/icemon.1
-o icemon.1
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/icemon.md
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/icemon.1)
)
add_custom_target(manpage ALL DEPENDS icemon.1)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/icemon.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
Expand Down
70 changes: 41 additions & 29 deletions src/fakemonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
#include <QTimer>
#include <QRandomGenerator>

#include <icecc/comm.h>

namespace {
// counter variable
int JOB_ID = 0;

const int MAX_JOB_COUNT = 10;
const int MAX_HOST_COUNT = 40;
const int MAX_HOST_COUNT = 20;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider constexpr?

const int MAX_JOB_COUNT = 32;
const int MAX_TOTAL_JOB_COUNT = MAX_HOST_COUNT * MAX_JOB_COUNT / 2;
const int MAX_JOB_SIZE = 1024 * 1024 * 24;

const QStringList JOB_FILENAMES(QStringList()
Expand All @@ -54,7 +53,7 @@ const QStringList HOST_NAMES(QStringList()

QString randomPlatform()
{
static const QStringList hostNames = {QStringLiteral("Linux 2.6"), QStringLiteral("Linux 3.2"), QStringLiteral("Linux 3.6")};
static const QStringList hostNames = {QStringLiteral("x86_64"), QStringLiteral("arm64")};
return hostNames[QRandomGenerator::global()->generate() % hostNames.size()];
}
}
Expand All @@ -63,11 +62,11 @@ FakeMonitor::FakeMonitor(HostInfoManager *manager, QObject *parent)
: Monitor(manager, parent)
, m_updateTimer(new QTimer(this))
{
m_updateTimer->setInterval(200);
m_updateTimer->setInterval(500);
m_updateTimer->start();
connect(m_updateTimer, &QTimer::timeout, this, &FakeMonitor::update);

setSchedulerState(Online);
setSchedulerState(SchedulerState::Online);

for (HostId i = 0; i < MAX_HOST_COUNT; ++i) {
createHostInfo(i + 1);
Expand All @@ -76,43 +75,56 @@ FakeMonitor::FakeMonitor(HostInfoManager *manager, QObject *parent)

void FakeMonitor::createHostInfo(HostId id)
{
// Set some servers as not accepting remote jobs
const float speed = (QRandomGenerator::global()->generate() % 5) * 100.0;

HostInfo info(id);
info.setIp(QStringLiteral("1.0.0.%1").arg(id));
info.setMaxJobs(5);
info.setMaxJobs(MAX_JOB_COUNT);
info.setName(HOST_NAMES[id % HOST_NAMES.length()] + QString::number(id));
info.setColor(info.createColor(info.name()));
info.setOffline(false);
info.setNoRemote(false);
info.setNoRemote(qFuzzyIsNull(speed));
info.setPlatform(randomPlatform());
info.setProtocol(PROTOCOL_VERSION);
info.setProtocol(0);
info.setFeatures(id % 2 == 0 ? QStringLiteral("env_xz") : QStringLiteral("env_zstd"));
info.setServerLoad(1.0);
info.setServerSpeed(10);
info.setServerSpeed(speed);
hostInfoManager()->checkNode(info);
}

void FakeMonitor::update()
{
// create job
const int clientId = (JOB_ID % MAX_HOST_COUNT) + 1;
const QString fileName = JOB_FILENAMES[JOB_ID % JOB_FILENAMES.length()];
Job job(JOB_ID++, clientId, fileName);
time_t rawtime;
time(&rawtime);
job.startTime = rawtime;
job.state = Job::Compiling;
job.in_compressed = QRandomGenerator::global()->generate() % MAX_JOB_SIZE * 0.75; // random factor
job.in_uncompressed = QRandomGenerator::global()->generate() % MAX_JOB_SIZE;
job.in_compressed = QRandomGenerator::global()->generate() % MAX_JOB_SIZE ;
job.in_uncompressed = QRandomGenerator::global()->generate() % MAX_JOB_SIZE * 0.75; // random factor
job.real_msec = 200;
const int serverId = ((JOB_ID + 1) % MAX_HOST_COUNT) + 1;
job.server = serverId;
emit jobUpdated(job);
m_activeJobs << job;
// create jobs
for (int i = 0; i < 10; ++i) {
const int jobId = JOB_ID++;

const int clientId = (jobId % MAX_HOST_COUNT) + 1;
const QString fileName = JOB_FILENAMES[jobId % JOB_FILENAMES.length()];
const auto hostInfo = hostInfoManager()->find(clientId);
assert(hostInfo);
if (qFuzzyIsNull(hostInfo->serverSpeed())) {
continue;
}

Job job(jobId, clientId, fileName);
time_t rawtime;
time(&rawtime);
job.startTime = rawtime;
job.state = Job::Compiling;
job.in_compressed = QRandomGenerator::global()->generate() % MAX_JOB_SIZE * 0.75; // random factor
job.in_uncompressed = QRandomGenerator::global()->generate() % MAX_JOB_SIZE;
job.in_compressed = QRandomGenerator::global()->generate() % MAX_JOB_SIZE ;
job.in_uncompressed = QRandomGenerator::global()->generate() % MAX_JOB_SIZE * 0.75; // random factor
job.real_msec = 200;
const int serverId = ((jobId + 1) % MAX_HOST_COUNT) + 1;
job.server = serverId;
emit jobUpdated(job);
m_activeJobs << job;
}

// clean up old jobs
if (m_activeJobs.size() > MAX_JOB_COUNT) {
if (m_activeJobs.size() > MAX_TOTAL_JOB_COUNT) {
Job job = m_activeJobs.first();
m_activeJobs.removeFirst();
job.state = Job::Finished;
Expand Down
10 changes: 0 additions & 10 deletions src/hostinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,3 @@ HostInfoManager::HostMap HostInfoManager::hostMap() const
{
return mHostMap;
}

void HostInfoManager::setSchedulerName(const QString &schedulerName)
{
mSchedulerName = schedulerName;
}

void HostInfoManager::setNetworkName(const QString &networkName)
{
mNetworkName = networkName;
}
7 changes: 0 additions & 7 deletions src/hostinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,11 @@ class HostInfoManager
QColor hostColor(unsigned int id) const;
unsigned int maxJobs(unsigned int id) const;

QString schedulerName() const { return mSchedulerName; }
void setSchedulerName(const QString &schedulerName);
QString networkName() const { return mNetworkName; }
void setNetworkName(const QString &networkName);

signals:
void hostMapChanged();

private:
HostMap mHostMap;
QString mSchedulerName;
QString mNetworkName;
};

#endif
Expand Down
28 changes: 13 additions & 15 deletions src/icecreammonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void IcecreamMonitor::checkScheduler(bool deleteit)
m_fd_type = QSocketNotifier::Exception;
delete m_discover;
m_discover = nullptr;
setSchedulerState(Offline);
setSchedulerState(SchedulerState::Offline);
} else if (m_scheduler) {
return;
}
Expand All @@ -90,13 +90,13 @@ void IcecreamMonitor::checkScheduler(bool deleteit)
void IcecreamMonitor::registerNotify(int fd, QSocketNotifier::Type type, const char *slot)
{
if (m_fd_notify) {
// Reuse, but the slot will change.
m_fd_notify->disconnect(this);

if(m_fd_notify->socket() != fd || m_fd_notify->type() != type) {
m_fd_notify->disconnect(this);
m_fd_notify->deleteLater();
m_fd_notify = nullptr;
}
// Reuse, but the slot will change.
m_fd_notify->disconnect(this);
}
if (!m_fd_notify) {
m_fd_notify = new QSocketNotifier(fd, type, this);
Expand All @@ -111,12 +111,12 @@ void IcecreamMonitor::slotCheckScheduler()
return;
}

const string hostname = currentSchedname().isEmpty() ? "" : currentSchedname().data();
const string hostname = currentSchedname().toStdString();
list<string> names;
const uint port = currentSchedport();

if (!currentNetname().isEmpty()) {
names.push_front(currentNetname().data());
names.push_front(currentNetname().toStdString());
} else {
names.push_front("ICECREAM");
}
Expand All @@ -125,16 +125,14 @@ void IcecreamMonitor::slotCheckScheduler()
names.push_front(""); // try $USE_SCHEDULER
}
for (auto it = names.begin(); it != names.end(); ++it) {
setCurrentNetname(QByteArray::fromStdString(*it));
setCurrentNetname(QString::fromStdString(*it));
if (!m_discover
|| ((m_scheduler = m_discover->try_get_scheduler()) == NULL && m_discover->timed_out())) {
delete m_discover;
m_discover = new DiscoverSched(currentNetname().toStdString(), 2, hostname, port);
}

if (m_scheduler) {
hostInfoManager()->setSchedulerName(QString::fromLatin1(m_discover->schedulerName().data()));
hostInfoManager()->setNetworkName(QString::fromLatin1(m_discover->networkName().data()));
m_scheduler->setBulkTransfer();
delete m_discover;
m_discover = nullptr;
Expand All @@ -145,7 +143,7 @@ void IcecreamMonitor::slotCheckScheduler()
checkScheduler(true);
QTimer::singleShot(0, this, &IcecreamMonitor::slotCheckScheduler);
} else {
setSchedulerState(Online);
setSchedulerState(SchedulerState::Online);
}
return;
}
Expand All @@ -165,7 +163,7 @@ void IcecreamMonitor::slotCheckScheduler()
}
}

setSchedulerState(Offline);
setSchedulerState(SchedulerState::Offline);
}

void IcecreamMonitor::msgReceived()
Expand All @@ -181,7 +179,7 @@ bool IcecreamMonitor::handle_activity()
std::unique_ptr<Msg> m(m_scheduler->get_msg());
if (!m) {
checkScheduler(true);
setSchedulerState(Offline);
setSchedulerState(SchedulerState::Offline);
return false;
}

Expand Down Expand Up @@ -255,7 +253,7 @@ void IcecreamMonitor::handle_local_done(Msg *_m)
return;
}

JobList::iterator it = m_rememberedJobs.find(m->job_id);
auto it = m_rememberedJobs.find(m->job_id);
if (it == m_rememberedJobs.end()) {
// we started in between
return;
Expand Down Expand Up @@ -308,7 +306,7 @@ void IcecreamMonitor::handle_job_begin(Msg *_m)
return;
}

JobList::iterator it = m_rememberedJobs.find(m->job_id);
auto it = m_rememberedJobs.find(m->job_id);
if (it == m_rememberedJobs.end()) {
// we started in between
return;
Expand All @@ -334,7 +332,7 @@ void IcecreamMonitor::handle_job_done(Msg *_m)
return;
}

JobList::iterator it = m_rememberedJobs.find(m->job_id);
auto it = m_rememberedJobs.find(m->job_id);
if (it == m_rememberedJobs.end()) {
// we started in between
return;
Expand Down
2 changes: 1 addition & 1 deletion src/icecreammonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IcecreamMonitor
Q_OBJECT

public:
IcecreamMonitor(HostInfoManager *, QObject *parent);
IcecreamMonitor(HostInfoManager *, QObject *parent = nullptr);
~IcecreamMonitor() override;

QList<Job> jobHistory() const override;
Expand Down
41 changes: 30 additions & 11 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@
#include <QApplication>
#include <QCommandLineParser>

#include "hostinfo.h"
#include "mainwindow.h"
#include "fakemonitor.h"
#include "icecreammonitor.h"
#include "version.h"

#include "config-icemon.h"

int main(int argc, char **argv)
{
QApplication app(argc, argv);
Expand All @@ -51,29 +56,43 @@ int main(int argc, char **argv)
QCoreApplication::translate("main", "Icecream scheduler port"),
QCoreApplication::translate("main", "port", "scheduler port"));
parser.addOption(schedportOption);

#if ICEMON_DEVELOPER_BUILD
QCommandLineOption testmodeOption(QStringLiteral("testmode"),
QCoreApplication::translate("main", "Testing mode."));
parser.addOption(testmodeOption);
#endif

parser.process(app);

const QByteArray netName = parser.value(netnameOption).toLatin1();
const QByteArray schedName = parser.value(schednameOption).toLatin1();
const QString netName = parser.value(netnameOption);
const QString schedName = parser.value(schednameOption);

HostInfoManager hostInfoManager;

QScopedPointer<Monitor> monitor;
#if ICEMON_DEVELOPER_BUILD
if (parser.isSet(testmodeOption)) {
monitor.reset(new FakeMonitor(&hostInfoManager));
} else {
monitor.reset(new IcecreamMonitor(&hostInfoManager));
}
#else
monitor.reset(new IcecreamMonitor(&hostInfoManager));
#endif

MainWindow mainWindow;
if (!netName.isEmpty()) {
mainWindow.setCurrentNet(netName);
monitor->setCurrentNetname(netName);
}
if (!schedName.isEmpty()) {
mainWindow.setCurrentSched(schedName);
}
if (!parser.value(schedportOption).isEmpty())
{
mainWindow.setCurrentPort(parser.value(schedportOption).toUInt());
monitor->setCurrentSchedname(schedName);
}
if (parser.isSet(testmodeOption)) {
mainWindow.setTestModeEnabled(true);
if (!parser.value(schedportOption).isEmpty()) {
monitor->setCurrentSchedport(parser.value(schedportOption).toUInt());
}

MainWindow mainWindow;
mainWindow.setMonitor(monitor.get());
mainWindow.show();

return app.exec();
Expand Down
Loading
Loading