From 8bb2bd2ecfd9f5eae727e5484c9daa2ba3a9fbd4 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 25 Nov 2013 00:26:37 -0800 Subject: [PATCH] get voxel packet statistics to work and add them to server status page --- .../src/VoxelSendThread.cpp | 8 +++-- .../src/VoxelSendThread.h | 9 ++--- .../voxel-server-library/src/VoxelServer.cpp | 31 +++++++++++++++- libraries/voxels/src/VoxelPacket.cpp | 35 ++++++++++++++++--- libraries/voxels/src/VoxelPacket.h | 13 ++++--- 5 files changed, 81 insertions(+), 15 deletions(-) diff --git a/libraries/voxel-server-library/src/VoxelSendThread.cpp b/libraries/voxel-server-library/src/VoxelSendThread.cpp index e4f6c10856..f01b300cef 100644 --- a/libraries/voxel-server-library/src/VoxelSendThread.cpp +++ b/libraries/voxel-server-library/src/VoxelSendThread.cpp @@ -111,7 +111,9 @@ int VoxelSendThread::handlePacketSend(Node* node, VoxelNodeData* nodeData, int& memcpy(statsMessage + statsMessageLength, nodeData->getPacket(), nodeData->getPacketLength()); statsMessageLength += nodeData->getPacketLength(); - int thisWastedBytes = MAX_PACKET_SIZE - statsMessageLength; // the statsMessageLength at this point includes data + // since a stats message is only included on end of scene, don't consider any of these bytes "wasted", since + // there was nothing else to send. + int thisWastedBytes = 0; _totalWastedBytes += thisWastedBytes; _totalBytes += nodeData->getPacketLength(); _totalPackets++; @@ -129,7 +131,9 @@ int VoxelSendThread::handlePacketSend(Node* node, VoxelNodeData* nodeData, int& // not enough room in the packet, send two packets NodeList::getInstance()->getNodeSocket()->send(node->getActiveSocket(), statsMessage, statsMessageLength); - int thisWastedBytes = MAX_PACKET_SIZE - statsMessageLength; // the statsMessageLength is only the stats + // since a stats message is only included on end of scene, don't consider any of these bytes "wasted", since + // there was nothing else to send. + int thisWastedBytes = 0; _totalWastedBytes += thisWastedBytes; _totalBytes += nodeData->getPacketLength(); _totalPackets++; diff --git a/libraries/voxel-server-library/src/VoxelSendThread.h b/libraries/voxel-server-library/src/VoxelSendThread.h index 607e1a9e0d..f088163f4d 100644 --- a/libraries/voxel-server-library/src/VoxelSendThread.h +++ b/libraries/voxel-server-library/src/VoxelSendThread.h @@ -22,6 +22,11 @@ class VoxelSendThread : public virtual GenericThread { public: VoxelSendThread(const QUuid& nodeUUID, VoxelServer* myServer); + + static uint64_t _totalBytes; + static uint64_t _totalWastedBytes; + static uint64_t _totalPackets; + protected: /// Implements generic processing behavior for this thread. virtual bool process(); @@ -37,10 +42,6 @@ private: VoxelPacket _tempPacket; bool _encodedSomething; - static uint64_t _totalBytes; - static uint64_t _totalWastedBytes; - static uint64_t _totalPackets; - }; #endif // __voxel_server__VoxelSendThread__ diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index cf650117f2..36db9ee1ca 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -262,6 +262,36 @@ int VoxelServer::civetwebRequestHandler(struct mg_connection* connection) { mg_printf(connection, "%s", "\r\n"); mg_printf(connection, "%s", "\r\n"); + + // display outbound packet stats + mg_printf(connection, "%s", "Voxel Packet Statistics...\r\n"); + uint64_t totalOutboundPackets = VoxelSendThread::_totalPackets; + uint64_t totalOutboundBytes = VoxelSendThread::_totalBytes; + uint64_t totalWastedBytes = VoxelSendThread::_totalWastedBytes; + uint64_t totalBytesOfOctalCodes = VoxelPacket::_totalBytesOfOctalCodes; + uint64_t totalBytesOfBitMasks = VoxelPacket::_totalBytesOfBitMasks; + uint64_t totalBytesOfColor = VoxelPacket::_totalBytesOfColor; + + const int COLUMN_WIDTH = 10; + mg_printf(connection, " Total Outbound Packets: %s packets\r\n", + locale.toString((uint)totalOutboundPackets).rightJustified(COLUMN_WIDTH, ' ').toLocal8Bit().constData()); + mg_printf(connection, " Total Outbound Bytes: %s bytes\r\n", + locale.toString((uint)totalOutboundBytes).rightJustified(COLUMN_WIDTH, ' ').toLocal8Bit().constData()); + mg_printf(connection, " Total Wasted Bytes: %s bytes\r\n", + locale.toString((uint)totalWastedBytes).rightJustified(COLUMN_WIDTH, ' ').toLocal8Bit().constData()); + mg_printf(connection, " Total OctalCode Bytes: %s bytes (%5.2f%%)\r\n", + locale.toString((uint)totalBytesOfOctalCodes).rightJustified(COLUMN_WIDTH, ' ').toLocal8Bit().constData(), + ((float)totalBytesOfOctalCodes / (float)totalOutboundBytes) * AS_PERCENT); + mg_printf(connection, " Total BitMasks Bytes: %s bytes (%5.2f%%)\r\n", + locale.toString((uint)totalBytesOfBitMasks).rightJustified(COLUMN_WIDTH, ' ').toLocal8Bit().constData(), + ((float)totalBytesOfBitMasks / (float)totalOutboundBytes) * AS_PERCENT); + mg_printf(connection, " Total Color Bytes: %s bytes (%5.2f%%)\r\n", + locale.toString((uint)totalBytesOfColor).rightJustified(COLUMN_WIDTH, ' ').toLocal8Bit().constData(), + ((float)totalBytesOfColor / (float)totalOutboundBytes) * AS_PERCENT); + + mg_printf(connection, "%s", "\r\n"); + mg_printf(connection, "%s", "\r\n"); + // display inbound packet stats mg_printf(connection, "%s", "Voxel Edit Statistics... [RESET]\r\n"); uint64_t averageTransitTimePerPacket = theServer->_voxelServerPacketProcessor->getAverageTransitTimePerPacket(); @@ -274,7 +304,6 @@ int VoxelServer::civetwebRequestHandler(struct mg_connection* connection) { float averageVoxelsPerPacket = totalPacketsProcessed == 0 ? 0 : totalVoxelsProcessed / totalPacketsProcessed; - const int COLUMN_WIDTH = 10; mg_printf(connection, " Total Inbound Packets: %s packets\r\n", locale.toString((uint)totalPacketsProcessed).rightJustified(COLUMN_WIDTH, ' ').toLocal8Bit().constData()); mg_printf(connection, " Total Inbound Voxels: %s voxels\r\n", diff --git a/libraries/voxels/src/VoxelPacket.cpp b/libraries/voxels/src/VoxelPacket.cpp index bd7ec7230c..f0d2c97ace 100644 --- a/libraries/voxels/src/VoxelPacket.cpp +++ b/libraries/voxels/src/VoxelPacket.cpp @@ -10,9 +10,9 @@ #include "VoxelPacket.h" bool VoxelPacket::_debug = false; -uint64_t VoxelPacket::_bytesOfOctalCodes = 0; -uint64_t VoxelPacket::_bytesOfBitMasks = 0; -uint64_t VoxelPacket::_bytesOfColor = 0; +uint64_t VoxelPacket::_totalBytesOfOctalCodes = 0; +uint64_t VoxelPacket::_totalBytesOfBitMasks = 0; +uint64_t VoxelPacket::_totalBytesOfColor = 0; @@ -33,6 +33,11 @@ void VoxelPacket::reset() { _compressedBytes = 0; _bytesInUseLastCheck = 0; _dirty = false; + + _bytesOfOctalCodes = 0; + _bytesOfBitMasks = 0; + _bytesOfColor = 0; + _bytesOfOctalCodesCurrentSubTree = 0; } VoxelPacket::~VoxelPacket() { @@ -84,6 +89,7 @@ bool VoxelPacket::updatePriorBytes(int offset, const unsigned char* replacementB } bool VoxelPacket::startSubTree(const unsigned char* octcode) { + _bytesOfOctalCodesCurrentSubTree = _bytesOfOctalCodes; bool success = false; int possibleStartAt = _bytesInUse; int length = 0; @@ -101,6 +107,7 @@ bool VoxelPacket::startSubTree(const unsigned char* octcode) { } if (success) { _bytesOfOctalCodes += length; + _totalBytesOfOctalCodes += length; } return success; } @@ -146,15 +153,33 @@ void VoxelPacket::discardSubTree() { _bytesAvailable += bytesInSubTree; _subTreeAt = _bytesInUse; // should be the same actually... _dirty = true; + + // rewind to start of this subtree, other items rewound by endLevel() + int reduceBytesOfOctalCodes = _bytesOfOctalCodes - _bytesOfOctalCodesCurrentSubTree; + _bytesOfOctalCodes = _bytesOfOctalCodesCurrentSubTree; + _totalBytesOfOctalCodes -= reduceBytesOfOctalCodes; } LevelDetails VoxelPacket::startLevel() { - LevelDetails key(_bytesInUse,0,0,0); + LevelDetails key(_bytesInUse, _bytesOfOctalCodes, _bytesOfBitMasks, _bytesOfColor); return key; } void VoxelPacket::discardLevel(LevelDetails key) { int bytesInLevel = _bytesInUse - key._startIndex; + + // reset statistics... + int reduceBytesOfOctalCodes = _bytesOfOctalCodes - key._bytesOfOctalCodes; + int reduceBytesOfBitMasks = _bytesOfBitMasks - key._bytesOfBitmasks; + int reduceBytesOfColor = _bytesOfColor - key._bytesOfColor; + + _bytesOfOctalCodes = key._bytesOfOctalCodes; + _bytesOfBitMasks = key._bytesOfBitmasks; + _bytesOfColor = key._bytesOfColor; + + _totalBytesOfOctalCodes -= reduceBytesOfOctalCodes; + _totalBytesOfBitMasks -= reduceBytesOfBitMasks; + _totalBytesOfColor -= reduceBytesOfColor; if (_debug) { printf("discardLevel() BEFORE _dirty=%s bytesInLevel=%d _compressedBytes=%d _bytesInUse=%d\n", @@ -201,6 +226,7 @@ bool VoxelPacket::appendBitMask(unsigned char bitmask) { bool success = append(bitmask); // handles checking compression if (success) { _bytesOfBitMasks++; + _totalBytesOfBitMasks++; } return success; } @@ -221,6 +247,7 @@ bool VoxelPacket::appendColor(const nodeColor& color) { } if (success) { _bytesOfColor += BYTES_PER_COLOR; + _totalBytesOfColor += BYTES_PER_COLOR; } return success; } diff --git a/libraries/voxels/src/VoxelPacket.h b/libraries/voxels/src/VoxelPacket.h index bb8b8bbb02..4edf21f033 100644 --- a/libraries/voxels/src/VoxelPacket.h +++ b/libraries/voxels/src/VoxelPacket.h @@ -113,6 +113,10 @@ public: static uint64_t _checkCompressTime; static uint64_t _checkCompressCalls; + + static uint64_t _totalBytesOfOctalCodes; + static uint64_t _totalBytesOfBitMasks; + static uint64_t _totalBytesOfColor; private: /// appends raw bytes, might fail if byte would cause packet to be too large @@ -137,10 +141,11 @@ private: bool _dirty; // statistics... - static uint64_t _bytesOfOctalCodes; - static uint64_t _bytesOfBitMasks; - static uint64_t _bytesOfColor; - + int _bytesOfOctalCodes; + int _bytesOfBitMasks; + int _bytesOfColor; + int _bytesOfOctalCodesCurrentSubTree; + static bool _debug; };