From 6a4406ad12ccc05b467e86a5bdf910eb5f681838 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Thu, 3 Oct 2019 17:46:52 -0700 Subject: [PATCH 1/2] Put generic stats in sendStatsPacket() stub --- assignment-client/src/scripts/EntityScriptServer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/assignment-client/src/scripts/EntityScriptServer.cpp b/assignment-client/src/scripts/EntityScriptServer.cpp index ea002a27c6..9c00f2fbe6 100644 --- a/assignment-client/src/scripts/EntityScriptServer.cpp +++ b/assignment-client/src/scripts/EntityScriptServer.cpp @@ -556,7 +556,9 @@ void EntityScriptServer::checkAndCallPreload(const EntityItemID& entityID, bool } void EntityScriptServer::sendStatsPacket() { - + QJsonObject statsObject; + // Add ESS-specific ... + ThreadedAssignment::addPacketStatsAndSendStatsPacket(statsObject); } void EntityScriptServer::handleOctreePacket(QSharedPointer message, SharedNodePointer senderNode) { From 67d80cdd15848247b0f5a28f906f08d93aba3fb3 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Fri, 4 Oct 2019 15:38:05 -0700 Subject: [PATCH 2/2] Add per-Node & ESS-specific stats --- .../src/scripts/EntityScriptServer.cpp | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/assignment-client/src/scripts/EntityScriptServer.cpp b/assignment-client/src/scripts/EntityScriptServer.cpp index 9c00f2fbe6..174cf73094 100644 --- a/assignment-client/src/scripts/EntityScriptServer.cpp +++ b/assignment-client/src/scripts/EntityScriptServer.cpp @@ -557,8 +557,50 @@ void EntityScriptServer::checkAndCallPreload(const EntityItemID& entityID, bool void EntityScriptServer::sendStatsPacket() { QJsonObject statsObject; - // Add ESS-specific ... - ThreadedAssignment::addPacketStatsAndSendStatsPacket(statsObject); + + QJsonObject octreeStats; + octreeStats["elementCount"] = (double)OctreeElement::getNodeCount(); + octreeStats["internalElementCount"] = (double)OctreeElement::getInternalNodeCount(); + octreeStats["leafElementCount"] = (double)OctreeElement::getLeafNodeCount(); + statsObject["octree_stats"] = octreeStats; + + QJsonObject scriptEngineStats; + int numberRunningScripts = 0; + const auto scriptEngine = _entitiesScriptEngine; + if (scriptEngine) { + numberRunningScripts = scriptEngine->getNumRunningEntityScripts(); + } + scriptEngineStats["number_running_scripts"] = numberRunningScripts; + statsObject["script_engine_stats"] = scriptEngineStats; + + + auto nodeList = DependencyManager::get(); + QJsonObject nodesObject; + nodeList->eachNode([&](const SharedNodePointer& node) { + QJsonObject clientStats; + const QString uuidString(uuidStringWithoutCurlyBraces(node->getUUID())); + clientStats["node_type"] = NodeType::getNodeTypeName(node->getType()); + auto& nodeStats = node->getConnectionStats(); + + static const QString NODE_OUTBOUND_KBPS_STAT_KEY("outbound_kbit/s"); + static const QString NODE_INBOUND_KBPS_STAT_KEY("inbound_kbit/s"); + + // add the key to ask the domain-server for a username replacement, if it has it + clientStats[USERNAME_UUID_REPLACEMENT_STATS_KEY] = uuidString; + + clientStats[NODE_OUTBOUND_KBPS_STAT_KEY] = node->getOutboundKbps(); + clientStats[NODE_INBOUND_KBPS_STAT_KEY] = node->getInboundKbps(); + + using namespace std::chrono; + const float statsPeriod = duration(nodeStats.endTime - nodeStats.startTime).count(); + clientStats["unreliable_packet/s"] = (nodeStats.sentUnreliablePackets + nodeStats.receivedUnreliablePackets) / statsPeriod; + clientStats["reliable_packet/s"] = (nodeStats.sentPackets + nodeStats.receivedPackets) / statsPeriod; + + nodesObject[uuidString] = clientStats; + }); + + statsObject["nodes"] = nodesObject; + addPacketStatsAndSendStatsPacket(statsObject); } void EntityScriptServer::handleOctreePacket(QSharedPointer message, SharedNodePointer senderNode) {