1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-09 18:40:14 +00:00

Merge pull request #2261 from elsid/navigator_stats

Navigator stats
This commit is contained in:
Bret Curtis 2019-03-18 08:57:38 +01:00 committed by GitHub
commit b80e55fd3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 117 additions and 20 deletions

View File

@ -32,6 +32,8 @@
#include <components/version/version.hpp> #include <components/version/version.hpp>
#include <components/detournavigator/navigator.hpp>
#include "mwinput/inputmanagerimp.hpp" #include "mwinput/inputmanagerimp.hpp"
#include "mwgui/windowmanagerimp.hpp" #include "mwgui/windowmanagerimp.hpp"
@ -198,6 +200,8 @@ bool OMW::Engine::frame(float frametime)
stats->setAttribute(frameNumber, "WorkQueue", mWorkQueue->getNumItems()); stats->setAttribute(frameNumber, "WorkQueue", mWorkQueue->getNumItems());
stats->setAttribute(frameNumber, "WorkThread", mWorkQueue->getNumActiveThreads()); stats->setAttribute(frameNumber, "WorkThread", mWorkQueue->getNumActiveThreads());
mEnvironment.getWorld()->getNavigator()->reportStats(frameNumber, *stats);
} }
} }

View File

@ -5,6 +5,8 @@
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <osg/Stats>
namespace namespace
{ {
using DetourNavigator::ChangeType; using DetourNavigator::ChangeType;
@ -102,6 +104,20 @@ namespace DetourNavigator
mDone.wait(lock, [&] { return mJobs.empty(); }); mDone.wait(lock, [&] { return mJobs.empty(); });
} }
void AsyncNavMeshUpdater::reportStats(unsigned int frameNumber, osg::Stats& stats) const
{
std::size_t jobs = 0;
{
const std::lock_guard<std::mutex> lock(mMutex);
jobs = mJobs.size();
}
stats.setAttribute(frameNumber, "NavMesh UpdateJobs", jobs);
mNavMeshTilesCache.reportStats(frameNumber, stats);
}
void AsyncNavMeshUpdater::process() throw() void AsyncNavMeshUpdater::process() throw()
{ {
log("start process jobs"); log("start process jobs");

View File

@ -44,6 +44,8 @@ namespace DetourNavigator
void wait(); void wait();
void reportStats(unsigned int frameNumber, osg::Stats& stats) const;
private: private:
struct Job struct Job
{ {
@ -72,7 +74,7 @@ namespace DetourNavigator
std::reference_wrapper<TileCachedRecastMeshManager> mRecastMeshManager; std::reference_wrapper<TileCachedRecastMeshManager> mRecastMeshManager;
std::reference_wrapper<OffMeshConnectionsManager> mOffMeshConnectionsManager; std::reference_wrapper<OffMeshConnectionsManager> mOffMeshConnectionsManager;
std::atomic_bool mShouldStop; std::atomic_bool mShouldStop;
std::mutex mMutex; mutable std::mutex mMutex;
std::condition_variable mHasJob; std::condition_variable mHasJob;
std::condition_variable mDone; std::condition_variable mDone;
Jobs mJobs; Jobs mJobs;

View File

@ -192,6 +192,8 @@ namespace DetourNavigator
virtual std::map<osg::Vec3f, SharedNavMeshCacheItem> getNavMeshes() const = 0; virtual std::map<osg::Vec3f, SharedNavMeshCacheItem> getNavMeshes() const = 0;
virtual const Settings& getSettings() const = 0; virtual const Settings& getSettings() const = 0;
virtual void reportStats(unsigned int frameNumber, osg::Stats& stats) const = 0;
}; };
} }

View File

@ -138,6 +138,11 @@ namespace DetourNavigator
return mSettings; return mSettings;
} }
void NavigatorImpl::reportStats(unsigned int frameNumber, osg::Stats& stats) const
{
mNavMeshManager.reportStats(frameNumber, stats);
}
void NavigatorImpl::updateAvoidShapeId(const ObjectId id, const ObjectId avoidId) void NavigatorImpl::updateAvoidShapeId(const ObjectId id, const ObjectId avoidId)
{ {
updateId(id, avoidId, mWaterIds); updateId(id, avoidId, mWaterIds);

View File

@ -48,6 +48,8 @@ namespace DetourNavigator
const Settings& getSettings() const override; const Settings& getSettings() const override;
void reportStats(unsigned int frameNumber, osg::Stats& stats) const override;
private: private:
Settings mSettings; Settings mSettings;
NavMeshManager mNavMeshManager; NavMeshManager mNavMeshManager;

View File

@ -79,6 +79,8 @@ namespace DetourNavigator
return mDefaultSettings; return mDefaultSettings;
} }
void reportStats(unsigned int /*frameNumber*/, osg::Stats& /*stats*/) const override {}
private: private:
Settings mDefaultSettings {}; Settings mDefaultSettings {};
SharedNavMeshCacheItem mEmptyNavMeshCacheItem; SharedNavMeshCacheItem mEmptyNavMeshCacheItem;

View File

@ -212,6 +212,11 @@ namespace DetourNavigator
return mCache; return mCache;
} }
void NavMeshManager::reportStats(unsigned int frameNumber, osg::Stats& stats) const
{
mAsyncNavMeshUpdater.reportStats(frameNumber, stats);
}
void NavMeshManager::addChangedTiles(const btCollisionShape& shape, const btTransform& transform, void NavMeshManager::addChangedTiles(const btCollisionShape& shape, const btTransform& transform,
const ChangeType changeType) const ChangeType changeType)
{ {

View File

@ -50,6 +50,8 @@ namespace DetourNavigator
std::map<osg::Vec3f, SharedNavMeshCacheItem> getNavMeshes() const; std::map<osg::Vec3f, SharedNavMeshCacheItem> getNavMeshes() const;
void reportStats(unsigned int frameNumber, osg::Stats& stats) const;
private: private:
const Settings& mSettings; const Settings& mSettings;
TileCachedRecastMeshManager mRecastMeshManager; TileCachedRecastMeshManager mRecastMeshManager;

View File

@ -1,6 +1,8 @@
#include "navmeshtilescache.hpp" #include "navmeshtilescache.hpp"
#include "exceptions.hpp" #include "exceptions.hpp"
#include <osg/Stats>
#include <cstring> #include <cstring>
namespace DetourNavigator namespace DetourNavigator
@ -113,6 +115,24 @@ namespace DetourNavigator
return Value(*this, iterator); return Value(*this, iterator);
} }
void NavMeshTilesCache::reportStats(unsigned int frameNumber, osg::Stats& stats) const
{
std::size_t navMeshCacheSize = 0;
std::size_t usedNavMeshTiles = 0;
std::size_t cachedNavMeshTiles = 0;
{
const std::lock_guard<std::mutex> lock(mMutex);
navMeshCacheSize = mUsedNavMeshDataSize;
usedNavMeshTiles = mBusyItems.size();
cachedNavMeshTiles = mFreeItems.size();
}
stats.setAttribute(frameNumber, "NavMesh CacheSize", navMeshCacheSize);
stats.setAttribute(frameNumber, "NavMesh UsedTiles", usedNavMeshTiles);
stats.setAttribute(frameNumber, "NavMesh CachedTiles", cachedNavMeshTiles);
}
void NavMeshTilesCache::removeLeastRecentlyUsed() void NavMeshTilesCache::removeLeastRecentlyUsed()
{ {
const auto& item = mFreeItems.back(); const auto& item = mFreeItems.back();

View File

@ -12,6 +12,11 @@
#include <mutex> #include <mutex>
#include <cassert> #include <cassert>
namespace osg
{
class Stats;
}
namespace DetourNavigator namespace DetourNavigator
{ {
struct NavMeshDataRef struct NavMeshDataRef
@ -105,6 +110,8 @@ namespace DetourNavigator
const RecastMesh& recastMesh, const std::vector<OffMeshConnection>& offMeshConnections, const RecastMesh& recastMesh, const std::vector<OffMeshConnection>& offMeshConnections,
NavMeshData&& value); NavMeshData&& value);
void reportStats(unsigned int frameNumber, osg::Stats& stats) const;
private: private:
class KeyView class KeyView
{ {
@ -164,7 +171,7 @@ namespace DetourNavigator
std::map<KeyView, ItemIterator> mMap; std::map<KeyView, ItemIterator> mMap;
}; };
std::mutex mMutex; mutable std::mutex mMutex;
std::size_t mMaxNavMeshDataSize; std::size_t mMaxNavMeshDataSize;
std::size_t mUsedNavMeshDataSize; std::size_t mUsedNavMeshDataSize;
std::size_t mFreeNavMeshDataSize; std::size_t mFreeNavMeshDataSize;

View File

@ -2,6 +2,7 @@
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <algorithm>
#include <osg/PolygonMode> #include <osg/PolygonMode>
@ -197,14 +198,14 @@ class ResourceStatsTextDrawCallback : public osg::Drawable::DrawCallback
{ {
public: public:
ResourceStatsTextDrawCallback(osg::Stats* stats, const std::vector<std::string>& statNames) ResourceStatsTextDrawCallback(osg::Stats* stats, const std::vector<std::string>& statNames)
: _stats(stats) : mStats(stats)
, _statNames(statNames) , mStatNames(statNames)
{ {
} }
virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const
{ {
if (!_stats) return; if (!mStats) return;
osgText::Text* text = (osgText::Text*)(drawable); osgText::Text* text = (osgText::Text*)(drawable);
@ -218,14 +219,14 @@ public:
unsigned int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber()-1; unsigned int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber()-1;
for (std::vector<std::string>::const_iterator it = _statNames.begin(); it != _statNames.end(); ++it) for (const auto& statName : mStatNames.get())
{ {
if (it->empty()) if (statName.empty())
viewStr << std::endl; viewStr << std::endl;
else else
{ {
double value = 0.0; double value = 0.0;
if (_stats->getAttribute(frameNumber, *it, value)) if (mStats->getAttribute(frameNumber, statName, value))
viewStr << std::setw(8) << value << std::endl; viewStr << std::setw(8) << value << std::endl;
else else
viewStr << std::setw(8) << "." << std::endl; viewStr << std::setw(8) << "." << std::endl;
@ -237,8 +238,8 @@ public:
text->drawImplementation(renderInfo); text->drawImplementation(renderInfo);
} }
osg::ref_ptr<osg::Stats> _stats; osg::ref_ptr<osg::Stats> mStats;
std::vector<std::string> _statNames; std::reference_wrapper<const std::vector<std::string>> mStatNames;
}; };
void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer) void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
@ -255,7 +256,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
stateset->setAttribute(new osg::PolygonMode(), osg::StateAttribute::PROTECTED); stateset->setAttribute(new osg::PolygonMode(), osg::StateAttribute::PROTECTED);
#endif #endif
osg::Vec3 pos(_statsWidth-300.f, _statsHeight-500.0f,0.0f); osg::Vec3 pos(_statsWidth-420.f, _statsHeight-500.0f,0.0f);
osg::Vec4 backgroundColor(0.0, 0.0, 0.0f, 0.3); osg::Vec4 backgroundColor(0.0, 0.0, 0.0f, 0.3);
osg::Vec4 staticTextColor(1.0, 1.0, 0.0f, 1.0); osg::Vec4 staticTextColor(1.0, 1.0, 0.0f, 1.0);
osg::Vec4 dynamicTextColor(1.0, 1.0, 1.0f, 1.0); osg::Vec4 dynamicTextColor(1.0, 1.0, 1.0f, 1.0);
@ -269,12 +270,41 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
_resourceStatsChildNum = _switch->getNumChildren(); _resourceStatsChildNum = _switch->getNumChildren();
_switch->addChild(group, false); _switch->addChild(group, false);
const char* statNames[] = {"Compiling", "WorkQueue", "WorkThread", "", "Texture", "StateSet", "Node", "Node Instance", "Shape", "Shape Instance", "Image", "Nif", "Keyframe", "", "Terrain Chunk", "Terrain Texture", "Land", "Composite", "", "UnrefQueue"}; static const std::vector<std::string> statNames({
"Compiling",
"WorkQueue",
"WorkThread",
"",
"Texture",
"StateSet",
"Node",
"Node Instance",
"Shape",
"Shape Instance",
"Image",
"Nif",
"Keyframe",
"",
"Terrain Chunk",
"Terrain Texture",
"Land",
"Composite",
"",
"UnrefQueue",
"",
"NavMesh UpdateJobs",
"NavMesh CacheSize",
"NavMesh UsedTiles",
"NavMesh CachedTiles",
});
int numLines = sizeof(statNames) / sizeof(statNames[0]); static const auto longest = std::max_element(statNames.begin(), statNames.end(),
[] (const std::string& lhs, const std::string& rhs) { return lhs.size() < rhs.size(); });
const int numLines = statNames.size();
const float statNamesWidth = 13 * _characterSize + 2 * backgroundMargin;
group->addChild(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, _characterSize + backgroundMargin, 0), group->addChild(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, _characterSize + backgroundMargin, 0),
10 * _characterSize + 2 * backgroundMargin, statNamesWidth,
numLines * _characterSize + 2 * backgroundMargin, numLines * _characterSize + 2 * backgroundMargin,
backgroundColor)); backgroundColor));
@ -288,18 +318,18 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
std::ostringstream viewStr; std::ostringstream viewStr;
viewStr.clear(); viewStr.clear();
viewStr.setf(std::ios::left, std::ios::adjustfield); viewStr.setf(std::ios::left, std::ios::adjustfield);
viewStr.width(14); viewStr.width(longest->size());
for (size_t i = 0; i<sizeof(statNames)/sizeof(statNames[0]); ++i) for (const auto& statName : statNames)
{ {
viewStr << statNames[i] << std::endl; viewStr << statName << std::endl;
} }
staticText->setText(viewStr.str()); staticText->setText(viewStr.str());
pos.x() += 10 * _characterSize + 2 * backgroundMargin + backgroundSpacing; pos.x() += statNamesWidth + backgroundSpacing;
group->addChild(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, _characterSize + backgroundMargin, 0), group->addChild(createBackgroundRectangle(pos + osg::Vec3(-backgroundMargin, _characterSize + backgroundMargin, 0),
5 * _characterSize + 2 * backgroundMargin, 7 * _characterSize + 2 * backgroundMargin,
numLines * _characterSize + 2 * backgroundMargin, numLines * _characterSize + 2 * backgroundMargin,
backgroundColor)); backgroundColor));
@ -311,7 +341,7 @@ void StatsHandler::setUpScene(osgViewer::ViewerBase *viewer)
statsText->setCharacterSize(_characterSize); statsText->setCharacterSize(_characterSize);
statsText->setPosition(pos); statsText->setPosition(pos);
statsText->setText(""); statsText->setText("");
statsText->setDrawCallback(new ResourceStatsTextDrawCallback(viewer->getViewerStats(), std::vector<std::string>(statNames, statNames + numLines))); statsText->setDrawCallback(new ResourceStatsTextDrawCallback(viewer->getViewerStats(), statNames));
} }
} }