From 924053f2ecee0654f9aecca6c3315b9264cbf267 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 14 Oct 2013 15:10:56 -0700 Subject: [PATCH] added additional debugging of VoxelNode memory usage, shrunk size of VoxelNode by better alignment --- interface/src/Application.cpp | 10 ++++- .../voxel-server-library/src/VoxelServer.cpp | 1 + libraries/voxels/src/VoxelNode.cpp | 5 ++- libraries/voxels/src/VoxelNode.h | 42 +++++++++++-------- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 070062f164..6a6a9789a3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2993,13 +2993,19 @@ void Application::displayStats() { drawtext(10, statsVerticalOffset + 230, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); voxelStats.str(""); - voxelStats << "Voxels Memory Nodes: " << VoxelNode::getVoxelMemoryUsage() / 1000000.f << "MB " + voxelStats << + "Voxels Memory Nodes: " << VoxelNode::getVoxelMemoryUsage() / 1000000.f << "MB " + "Octcodes: " << VoxelNode::getOctcodeMemoryUsage() / 1000000.f << "MB " "Geometry RAM: " << _voxels.getVoxelMemoryUsageRAM() / 1000000.f << "MB " << "VBO: " << _voxels.getVoxelMemoryUsageVBO() / 1000000.f << "MB "; if (_voxels.hasVoxelMemoryUsageGPU()) { voxelStats << "GPU: " << _voxels.getVoxelMemoryUsageGPU() / 1000000.f << "MB "; } - + + // Some debugging for memory usage of VoxelNodes + //voxelStats << "VoxelNode size: " << sizeof(VoxelNode) << " bytes "; + //voxelStats << "AABox size: " << sizeof(AABox) << " bytes "; + drawtext(10, statsVerticalOffset + 250, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); voxelStats.str(""); diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index e4517672a0..f02069af2e 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -137,6 +137,7 @@ int VoxelServer::civetwebRequestHandler(struct mg_connection* connection) { mg_printf(connection, "%s", "Your Voxel Server is running.\r\n"); mg_printf(connection, "%s", "Current Statistics\r\n"); mg_printf(connection, "Voxel Node Memory Usage: %f MB\r\n", VoxelNode::getVoxelMemoryUsage() / 1000000.f); + mg_printf(connection, "Octcode Memory Usage: %f MB\r\n", VoxelNode::getOctcodeMemoryUsage() / 1000000.f); VoxelTree* theTree = VoxelServer::GetInstance()->getTree(); unsigned long nodeCount = theTree->rootNode->getSubTreeNodeCount(); diff --git a/libraries/voxels/src/VoxelNode.cpp b/libraries/voxels/src/VoxelNode.cpp index 154d573836..ad83b5a9cf 100644 --- a/libraries/voxels/src/VoxelNode.cpp +++ b/libraries/voxels/src/VoxelNode.cpp @@ -22,6 +22,7 @@ #include "VoxelTree.h" uint64_t VoxelNode::_voxelMemoryUsage = 0; +uint64_t VoxelNode::_octcodeMemoryUsage = 0; VoxelNode::VoxelNode() { unsigned char* rootCode = new unsigned char[1]; @@ -60,14 +61,14 @@ void VoxelNode::init(unsigned char * octalCode) { markWithChangedTime(); _voxelMemoryUsage += sizeof(VoxelNode); - _voxelMemoryUsage += bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(_octalCode)); + _octcodeMemoryUsage += bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(_octalCode)); } VoxelNode::~VoxelNode() { notifyDeleteHooks(); _voxelMemoryUsage -= sizeof(VoxelNode); - _voxelMemoryUsage -= bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(_octalCode)); + _octcodeMemoryUsage -= bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(_octalCode)); delete[] _octalCode; diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index 6a92ab1e42..41196c81b5 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -128,6 +128,7 @@ public: unsigned long getSubTreeLeafNodeCount() const { return _subtreeLeafNodeCount; } static uint64_t getVoxelMemoryUsage() { return _voxelMemoryUsage; } + static uint64_t getOctcodeMemoryUsage() { return _octcodeMemoryUsage; } private: void calculateAABox(); @@ -135,28 +136,35 @@ private: void notifyDeleteHooks(); void notifyUpdateHooks(); - nodeColor _trueColor; + VoxelNode* _children[8]; /// Client and server, pointers to child nodes, 64 bytes + AABox _box; /// Client and server, axis aligned box for bounds of this voxel, 48 bytes + unsigned char* _octalCode; /// Client and server, pointer to octal code for this node, 8 bytes + + uint64_t _lastChanged; /// Client and server, timestamp this node was last changed, 8 bytes + unsigned long _subtreeNodeCount; /// Client and server, nodes below this node, 8 bytes + unsigned long _subtreeLeafNodeCount; /// Client and server, leaves below this node, 8 bytes + + glBufferIndex _glBufferIndex; /// Client only, vbo index for this voxel if being rendered, 8 bytes + VoxelSystem* _voxelSystem; /// Client only, pointer to VoxelSystem rendering this voxel, 8 bytes + + float _density; /// Client and server, If leaf: density = 1, if internal node: 0-1 density of voxels inside, 4 bytes + int _childCount; /// Client and server, current child nodes set to non-null in _children, 4 bytes + + nodeColor _trueColor; /// Client and server, true color of this voxel, 4 bytes #ifndef NO_FALSE_COLOR // !NO_FALSE_COLOR means, does have false color - nodeColor _currentColor; - bool _falseColored; + nodeColor _currentColor; /// Client only, false color of this voxel, 4 bytes + bool _falseColored; /// Client only, is this voxel false colored, 1 bytes #endif - glBufferIndex _glBufferIndex; - VoxelSystem* _voxelSystem; - bool _isDirty; - uint64_t _lastChanged; - bool _shouldRender; - AABox _box; - unsigned char* _octalCode; - VoxelNode* _children[8]; - int _childCount; - unsigned long _subtreeNodeCount; - unsigned long _subtreeLeafNodeCount; - float _density; // If leaf: density = 1, if internal node: 0-1 density of voxels inside - uint16_t _sourceID; + + bool _isDirty; /// Client only, has this voxel changed since being rendered, 1 byte + bool _shouldRender; /// Client only, should this voxel render at this time, 1 byte + uint16_t _sourceID; /// Client only, stores node id of voxel server that sent his voxel, 2 bytes + static std::vector _deleteHooks; static std::vector _updateHooks; static uint64_t _voxelMemoryUsage; + static uint64_t _octcodeMemoryUsage; }; -#endif /* defined(__hifi__VoxelNode__) */ +#endif /* defined(__hifi__VoxelNode__) */ \ No newline at end of file