From 8affca612095b4a7e24840a6079331fb41cc3e0c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 3 Mar 2015 14:58:53 -0800 Subject: [PATCH] pass -t to children even if run in parent mode. monitor (parent) only interacts with its own children --- assignment-client/src/AssignmentClient.cpp | 12 +++++----- assignment-client/src/AssignmentClient.h | 4 ++-- assignment-client/src/AssignmentClientApp.cpp | 12 ++++++++-- assignment-client/src/AssignmentClientApp.h | 1 + .../src/AssignmentClientMonitor.cpp | 22 +++++++++++++++---- .../src/AssignmentClientMonitor.h | 7 ++++-- 6 files changed, 42 insertions(+), 16 deletions(-) diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index fba96c4967..a0da273462 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -40,8 +40,8 @@ SharedAssignmentPointer AssignmentClient::_currentAssignment; int hifiSockAddrMeta = qRegisterMetaType("HifiSockAddr"); -AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QString assignmentPool, QUuid walletUUID, - QString assignmentServerHostname, quint16 assignmentServerPort) : +AssignmentClient::AssignmentClient(int ppid, Assignment::Type requestAssignmentType, QString assignmentPool, + QUuid walletUUID, QString assignmentServerHostname, quint16 assignmentServerPort) : _assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME), _localASPortSharedMem(NULL), _localACMPortSharedMem(NULL) @@ -106,7 +106,7 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri NetworkAccessManager::getInstance(); // Hook up a timer to send this child's status to the Monitor once per second - setUpStatsToMonitor(); + setUpStatsToMonitor(ppid); } @@ -118,13 +118,13 @@ void AssignmentClient::stopAssignmentClient() { } -void AssignmentClient::setUpStatsToMonitor() { +void AssignmentClient::setUpStatsToMonitor(int ppid) { // Figure out the address to send out stats to quint16 localMonitorServerPort = DEFAULT_ASSIGNMENT_CLIENT_MONITOR_PORT; auto nodeList = DependencyManager::get(); - nodeList->getLocalServerPortFromSharedMemory(ASSIGNMENT_CLIENT_MONITOR_LOCAL_PORT_SMEM_KEY, - _localACMPortSharedMem, localMonitorServerPort); + nodeList->getLocalServerPortFromSharedMemory(QString(ASSIGNMENT_CLIENT_MONITOR_LOCAL_PORT_SMEM_KEY) + "-" + + QString::number(ppid), _localACMPortSharedMem, localMonitorServerPort); _assignmentClientMonitorSocket = HifiSockAddr(DEFAULT_ASSIGNMENT_CLIENT_MONITOR_HOSTNAME, localMonitorServerPort, true); // send a stats packet every 1 seconds diff --git a/assignment-client/src/AssignmentClient.h b/assignment-client/src/AssignmentClient.h index d1d93c78dc..08673ab04c 100644 --- a/assignment-client/src/AssignmentClient.h +++ b/assignment-client/src/AssignmentClient.h @@ -22,7 +22,7 @@ class AssignmentClient : public QObject { Q_OBJECT public: - AssignmentClient(Assignment::Type requestAssignmentType, QString assignmentPool, + AssignmentClient(int ppid, Assignment::Type requestAssignmentType, QString assignmentPool, QUuid walletUUID, QString assignmentServerHostname, quint16 assignmentServerPort); static const SharedAssignmentPointer& getCurrentAssignment() { return _currentAssignment; } @@ -35,7 +35,7 @@ private slots: void stopAssignmentClient(); private: - void setUpStatsToMonitor(); + void setUpStatsToMonitor(int ppid); Assignment _requestAssignment; static SharedAssignmentPointer _currentAssignment; QString _assignmentServerHostname; diff --git a/assignment-client/src/AssignmentClientApp.cpp b/assignment-client/src/AssignmentClientApp.cpp index cfb77c8542..17f2eac70d 100644 --- a/assignment-client/src/AssignmentClientApp.cpp +++ b/assignment-client/src/AssignmentClientApp.cpp @@ -78,6 +78,9 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) : const QCommandLineOption maxChildsOption(ASSIGNMENT_MAX_FORKS_OPTION, "maximum number of children", "child-count"); parser.addOption(maxChildsOption); + const QCommandLineOption ppidOption(PARENT_PID_OPTION, "parent's process id", "pid"); + parser.addOption(ppidOption); + if (!parser.parse(QCoreApplication::arguments())) { qCritical() << parser.errorText() << endl; @@ -109,6 +112,11 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) : maxForks = parser.value(maxChildsOption).toInt(); } + int ppid = 0; + if (parser.isSet(ppidOption)) { + ppid = parser.value(ppidOption).toInt(); + } + if (!numForks && minForks) { // if the user specified --min but not -n, set -n to --min numForks = minForks; @@ -174,11 +182,11 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) : if (numForks || minForks || maxForks) { - AssignmentClientMonitor monitor(numForks, minForks, maxForks, assignmentPool, + AssignmentClientMonitor monitor(numForks, minForks, maxForks, requestAssignmentType, assignmentPool, walletUUID, assignmentServerHostname, assignmentServerPort); exec(); } else { - AssignmentClient client(requestAssignmentType, assignmentPool, + AssignmentClient client(ppid, requestAssignmentType, assignmentPool, walletUUID, assignmentServerHostname, assignmentServerPort); exec(); } diff --git a/assignment-client/src/AssignmentClientApp.h b/assignment-client/src/AssignmentClientApp.h index 531035ef0e..7f75f63755 100644 --- a/assignment-client/src/AssignmentClientApp.h +++ b/assignment-client/src/AssignmentClientApp.h @@ -23,6 +23,7 @@ const QString CUSTOM_ASSIGNMENT_SERVER_PORT_OPTION = "p"; const QString ASSIGNMENT_NUM_FORKS_OPTION = "n"; const QString ASSIGNMENT_MIN_FORKS_OPTION = "min"; const QString ASSIGNMENT_MAX_FORKS_OPTION = "max"; +const QString PARENT_PID_OPTION = "ppid"; class AssignmentClientApp : public QCoreApplication { diff --git a/assignment-client/src/AssignmentClientMonitor.cpp b/assignment-client/src/AssignmentClientMonitor.cpp index a315fce1a9..1280b55b12 100644 --- a/assignment-client/src/AssignmentClientMonitor.cpp +++ b/assignment-client/src/AssignmentClientMonitor.cpp @@ -20,23 +20,26 @@ #include "PacketHeaders.h" #include "SharedUtil.h" -const char* NUM_FORKS_PARAMETER = "-n"; const QString ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME = "assignment-client-monitor"; AssignmentClientMonitor::AssignmentClientMonitor(const unsigned int numAssignmentClientForks, const unsigned int minAssignmentClientForks, const unsigned int maxAssignmentClientForks, - QString assignmentPool, QUuid walletUUID, QString assignmentServerHostname, + Assignment::Type requestAssignmentType, QString assignmentPool, + QUuid walletUUID, QString assignmentServerHostname, quint16 assignmentServerPort) : _numAssignmentClientForks(numAssignmentClientForks), _minAssignmentClientForks(minAssignmentClientForks), _maxAssignmentClientForks(maxAssignmentClientForks), + _requestAssignmentType(requestAssignmentType), _assignmentPool(assignmentPool), _walletUUID(walletUUID), _assignmentServerHostname(assignmentServerHostname), _assignmentServerPort(assignmentServerPort) { + qDebug() << "_requestAssignmentType =" << _requestAssignmentType; + // start the Logging class with the parent's target name LogHandler::getInstance().setTargetName(ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME); @@ -47,8 +50,10 @@ AssignmentClientMonitor::AssignmentClientMonitor(const unsigned int numAssignmen connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, this, &AssignmentClientMonitor::readPendingDatagrams); - nodeList->putLocalPortIntoSharedMemory(ASSIGNMENT_CLIENT_MONITOR_LOCAL_PORT_SMEM_KEY, this, - nodeList->getNodeSocket().localPort()); + qint64 pid = QCoreApplication::applicationPid (); + + nodeList->putLocalPortIntoSharedMemory(QString(ASSIGNMENT_CLIENT_MONITOR_LOCAL_PORT_SMEM_KEY) + "-" + QString::number(pid), + this, nodeList->getNodeSocket().localPort()); // use QProcess to fork off a process for each of the child assignment clients for (unsigned int i = 0; i < _numAssignmentClientForks; i++) { @@ -96,6 +101,15 @@ void AssignmentClientMonitor::spawnChildClient() { _childArguments.append("--" + CUSTOM_ASSIGNMENT_SERVER_PORT_OPTION); _childArguments.append(QString::number(_assignmentServerPort)); } + if (_requestAssignmentType != Assignment::AllTypes) { + _childArguments.append("--" + ASSIGNMENT_TYPE_OVERRIDE_OPTION); + _childArguments.append(QString::number(_requestAssignmentType)); + } + + // tell children which shared memory key to use + qint64 pid = QCoreApplication::applicationPid (); + _childArguments.append("--" + PARENT_PID_OPTION); + _childArguments.append(QString::number(pid)); // make sure that the output from the child process appears in our output assignmentClient->setProcessChannelMode(QProcess::ForwardedChannels); diff --git a/assignment-client/src/AssignmentClientMonitor.h b/assignment-client/src/AssignmentClientMonitor.h index dc88bfcd95..996220b1b4 100644 --- a/assignment-client/src/AssignmentClientMonitor.h +++ b/assignment-client/src/AssignmentClientMonitor.h @@ -28,8 +28,9 @@ class AssignmentClientMonitor : public QObject { Q_OBJECT public: AssignmentClientMonitor(const unsigned int numAssignmentClientForks, const unsigned int minAssignmentClientForks, - const unsigned int maxAssignmentClientForks, QString assignmentPool, QUuid walletUUID, - QString assignmentServerHostname, quint16 assignmentServerPort); + const unsigned int maxAssignmentClientForks, Assignment::Type requestAssignmentType, + QString assignmentPool, QUuid walletUUID, QString assignmentServerHostname, + quint16 assignmentServerPort); ~AssignmentClientMonitor(); void stopChildProcesses(); @@ -45,10 +46,12 @@ private: const unsigned int _minAssignmentClientForks; const unsigned int _maxAssignmentClientForks; + Assignment::Type _requestAssignmentType; QString _assignmentPool; QUuid _walletUUID; QString _assignmentServerHostname; quint16 _assignmentServerPort; + }; #endif // hifi_AssignmentClientMonitor_h