From 9e2f3fd0b496321c412d54daed6a53ab68e3071d Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 19 May 2024 20:03:34 +0200 Subject: [PATCH] Report stats for TileCachedRecastMeshManager --- components/detournavigator/navmeshmanager.cpp | 5 ++++- components/detournavigator/stats.cpp | 12 ++++++++++-- components/detournavigator/stats.hpp | 11 ++++++++++- .../tilecachedrecastmeshmanager.cpp | 14 +++++++++++++- .../tilecachedrecastmeshmanager.hpp | 4 +++- components/resource/stats.cpp | 4 ++++ 6 files changed, 44 insertions(+), 6 deletions(-) diff --git a/components/detournavigator/navmeshmanager.cpp b/components/detournavigator/navmeshmanager.cpp index 3b62866ed7..bb0a8e3451 100644 --- a/components/detournavigator/navmeshmanager.cpp +++ b/components/detournavigator/navmeshmanager.cpp @@ -217,7 +217,10 @@ namespace DetourNavigator Stats NavMeshManager::getStats() const { - return Stats{ .mUpdater = mAsyncNavMeshUpdater.getStats() }; + return Stats{ + .mUpdater = mAsyncNavMeshUpdater.getStats(), + .mRecast = mRecastMeshManager.getStats(), + }; } RecastMeshTiles NavMeshManager::getRecastMeshTiles() const diff --git a/components/detournavigator/stats.cpp b/components/detournavigator/stats.cpp index da56f91a38..39251b0f76 100644 --- a/components/detournavigator/stats.cpp +++ b/components/detournavigator/stats.cpp @@ -32,11 +32,19 @@ namespace DetourNavigator out.setAttribute(frameNumber, "NavMesh Cache Get", static_cast(stats.mCache.mGetCount)); out.setAttribute(frameNumber, "NavMesh Cache Hit", static_cast(stats.mCache.mHitCount)); } + + void reportStats(const TileCachedRecastMeshManagerStats& stats, unsigned int frameNumber, osg::Stats& out) + { + out.setAttribute(frameNumber, "NavMesh Recast Tiles", static_cast(stats.mTiles)); + out.setAttribute(frameNumber, "NavMesh Recast Objects", static_cast(stats.mObjects)); + out.setAttribute(frameNumber, "NavMesh Recast Heightfields", static_cast(stats.mHeightfields)); + out.setAttribute(frameNumber, "NavMesh Recast Water", static_cast(stats.mWater)); + } } void reportStats(const Stats& stats, unsigned int frameNumber, osg::Stats& out) { - if (stats.mUpdater.has_value()) - reportStats(*stats.mUpdater, frameNumber, out); + reportStats(stats.mUpdater, frameNumber, out); + reportStats(stats.mRecast, frameNumber, out); } } diff --git a/components/detournavigator/stats.hpp b/components/detournavigator/stats.hpp index 0b62b9e669..38a9febc26 100644 --- a/components/detournavigator/stats.hpp +++ b/components/detournavigator/stats.hpp @@ -50,9 +50,18 @@ namespace DetourNavigator NavMeshTilesCacheStats mCache; }; + struct TileCachedRecastMeshManagerStats + { + std::size_t mTiles = 0; + std::size_t mObjects = 0; + std::size_t mHeightfields = 0; + std::size_t mWater = 0; + }; + struct Stats { - std::optional mUpdater; + AsyncNavMeshUpdaterStats mUpdater; + TileCachedRecastMeshManagerStats mRecast; }; void reportStats(const Stats& stats, unsigned int frameNumber, osg::Stats& out); diff --git a/components/detournavigator/tilecachedrecastmeshmanager.cpp b/components/detournavigator/tilecachedrecastmeshmanager.cpp index 3e3927bf65..51e2087b78 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.cpp @@ -1,8 +1,10 @@ #include "tilecachedrecastmeshmanager.hpp" + #include "changetype.hpp" #include "gettilespositions.hpp" #include "recastmeshbuilder.hpp" #include "settingsutils.hpp" +#include "stats.hpp" #include "updateguard.hpp" #include @@ -11,7 +13,6 @@ #include #include -#include namespace DetourNavigator { @@ -429,6 +430,17 @@ namespace DetourNavigator return std::move(mChangedTiles); } + TileCachedRecastMeshManagerStats TileCachedRecastMeshManager::getStats() const + { + const std::lock_guard lock(mMutex); + return TileCachedRecastMeshManagerStats{ + .mTiles = mCache.size(), + .mObjects = mObjects.size(), + .mHeightfields = mHeightfields.size(), + .mWater = mWater.size(), + }; + } + TileCachedRecastMeshManager::IndexPoint TileCachedRecastMeshManager::makeIndexPoint( const TilePosition& tilePosition) { diff --git a/components/detournavigator/tilecachedrecastmeshmanager.hpp b/components/detournavigator/tilecachedrecastmeshmanager.hpp index 12e8ddee2e..553e664a5f 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.hpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.hpp @@ -28,11 +28,11 @@ #include #include #include -#include namespace DetourNavigator { class RecastMesh; + struct TileCachedRecastMeshManagerStats; class TileCachedRecastMeshManager { @@ -81,6 +81,8 @@ namespace DetourNavigator std::map takeChangedTiles(const UpdateGuard* guard); + TileCachedRecastMeshManagerStats getStats() const; + private: struct Report { diff --git a/components/resource/stats.cpp b/components/resource/stats.cpp index 963a9cf45d..34c3bc560c 100644 --- a/components/resource/stats.cpp +++ b/components/resource/stats.cpp @@ -119,6 +119,10 @@ namespace Resource "NavMesh CachedTiles", "NavMesh Cache Get", "NavMesh Cache Hit", + "NavMesh Recast Tiles", + "NavMesh Recast Objects", + "NavMesh Recast Heightfields", + "NavMesh Recast Water", }; std::vector statNames;