Skip to content

Commit

Permalink
Add resource statistics panel opened with F4
Browse files Browse the repository at this point in the history
  • Loading branch information
scrawl committed Feb 22, 2017
1 parent b40ca9b commit 8f79fa3
Show file tree
Hide file tree
Showing 32 changed files with 549 additions and 11 deletions.
13 changes: 12 additions & 1 deletion apps/openmw/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <components/resource/resourcesystem.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/resource/stats.hpp>

#include <components/compiler/extensions0.hpp>

Expand Down Expand Up @@ -169,7 +170,7 @@ void OMW::Engine::frame(float frametime)
mEnvironment.getWindowManager()->update();
}

int frameNumber = mViewer->getFrameStamp()->getFrameNumber();
unsigned int frameNumber = mViewer->getFrameStamp()->getFrameNumber();
osg::Stats* stats = mViewer->getViewerStats();
stats->setAttribute(frameNumber, "script_time_begin", osg::Timer::instance()->delta_s(mStartTick, beforeScriptTick));
stats->setAttribute(frameNumber, "script_time_taken", osg::Timer::instance()->delta_s(beforeScriptTick, afterScriptTick));
Expand All @@ -183,6 +184,14 @@ void OMW::Engine::frame(float frametime)
stats->setAttribute(frameNumber, "physics_time_taken", osg::Timer::instance()->delta_s(beforePhysicsTick, afterPhysicsTick));
stats->setAttribute(frameNumber, "physics_time_end", osg::Timer::instance()->delta_s(mStartTick, afterPhysicsTick));

if (stats->collectStats("resource"))
{
mResourceSystem->reportStats(frameNumber, stats);

stats->setAttribute(frameNumber, "WorkQueue", mWorkQueue->getNumItems());
stats->setAttribute(frameNumber, "WorkThread", mWorkQueue->getNumActiveThreads());
}

}
catch (const std::exception& e)
{
Expand Down Expand Up @@ -635,6 +644,8 @@ void OMW::Engine::go()

mViewer->addEventHandler(statshandler);

mViewer->addEventHandler(new Resource::StatsHandler);

Settings::Manager settings;
std::string settingspath;

Expand Down
14 changes: 14 additions & 0 deletions apps/openmw/mwrender/renderingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ namespace MWRender

void RenderingManager::update(float dt, bool paused)
{
reportStats();

mUnrefQueue->flush(mWorkQueue.get());

if (!paused)
Expand Down Expand Up @@ -901,6 +903,18 @@ namespace MWRender
mStateUpdater->setFogColor(color);
}

void RenderingManager::reportStats()
{
osg::Stats* stats = mViewer->getViewerStats();
unsigned int frameNumber = mViewer->getFrameStamp()->getFrameNumber();
if (stats->collectStats("resource"))
{
stats->setAttribute(frameNumber, "UnrefQueue", mUnrefQueue->getNumItems());

mTerrain->reportStats(frameNumber, stats);
}
}

void RenderingManager::processChangedSettings(const Settings::CategorySettingVector &changed)
{
for (Settings::CategorySettingVector::const_iterator it = changed.begin(); it != changed.end(); ++it)
Expand Down
2 changes: 2 additions & 0 deletions apps/openmw/mwrender/renderingmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ namespace MWRender
void updateAmbient();
void setFogColor(const osg::Vec4f& color);

void reportStats();

osg::ref_ptr<osgViewer::Viewer> mViewer;
osg::ref_ptr<osg::Group> mRootNode;
osg::ref_ptr<osg::Group> mSceneRoot;
Expand Down
3 changes: 2 additions & 1 deletion components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ add_component_dir (vfs
)

add_component_dir (resource
scenemanager keyframemanager imagemanager bulletshapemanager bulletshape niffilemanager objectcache multiobjectcache resourcesystem resourcemanager
scenemanager keyframemanager imagemanager bulletshapemanager bulletshape niffilemanager objectcache multiobjectcache resourcesystem resourcemanager stats
)

add_component_dir (shader
Expand Down Expand Up @@ -202,6 +202,7 @@ target_link_libraries(components
${OSGUTIL_LIBRARIES}
${OSGDB_LIBRARIES}
${OSGVIEWER_LIBRARIES}
${OSGTEXT_LIBRARIES}
${OSGGA_LIBRARIES}
${OSGFX_LIBRARIES}
${OSGANIMATION_LIBRARIES}
Expand Down
6 changes: 6 additions & 0 deletions components/resource/bulletshapemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,10 @@ void BulletShapeManager::updateCache(double referenceTime)
mInstanceCache->removeUnreferencedObjectsInCache();
}

void BulletShapeManager::reportStats(unsigned int frameNumber, osg::Stats *stats)
{
stats->setAttribute(frameNumber, "Shape", mCache->getCacheSize());
stats->setAttribute(frameNumber, "Shape Instance", mInstanceCache->getCacheSize());
}

}
2 changes: 2 additions & 0 deletions components/resource/bulletshapemanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace Resource
/// @see ResourceManager::updateCache
virtual void updateCache(double referenceTime);

void reportStats(unsigned int frameNumber, osg::Stats *stats);

private:
osg::ref_ptr<BulletShapeInstance> createInstance(const std::string& name);

Expand Down
5 changes: 5 additions & 0 deletions components/resource/imagemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,9 @@ namespace Resource
return mWarningImage;
}

void ImageManager::reportStats(unsigned int frameNumber, osg::Stats *stats)
{
stats->setAttribute(frameNumber, "Image", mCache->getCacheSize());
}

}
2 changes: 2 additions & 0 deletions components/resource/imagemanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace Resource

osg::Image* getWarningImage();

void reportStats(unsigned int frameNumber, osg::Stats* stats);

private:
osg::ref_ptr<osg::Image> mWarningImage;
osg::ref_ptr<osgDB::Options> mOptions;
Expand Down
5 changes: 5 additions & 0 deletions components/resource/keyframemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ namespace Resource
}
}

void KeyframeManager::reportStats(unsigned int frameNumber, osg::Stats *stats)
{
stats->setAttribute(frameNumber, "Keyframe", mCache->getCacheSize());
}



}
2 changes: 2 additions & 0 deletions components/resource/keyframemanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Resource
/// Retrieve a read-only keyframe resource by name (case-insensitive).
/// @note Throws an exception if the resource is not found.
osg::ref_ptr<const NifOsg::KeyframeHolder> get(const std::string& name);

void reportStats(unsigned int frameNumber, osg::Stats* stats);
};

}
Expand Down
6 changes: 6 additions & 0 deletions components/resource/multiobjectcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ namespace Resource
}
}

unsigned int MultiObjectCache::getCacheSize() const
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
return _objectCache.size();
}

}
4 changes: 3 additions & 1 deletion components/resource/multiobjectcache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ namespace Resource
/** call releaseGLObjects on all objects attached to the object cache.*/
void releaseGLObjects(osg::State* state);

unsigned int getCacheSize() const;

protected:

typedef std::multimap<std::string, osg::ref_ptr<osg::Object> > ObjectCacheMap;

ObjectCacheMap _objectCache;
OpenThreads::Mutex _objectCacheMutex;
mutable OpenThreads::Mutex _objectCacheMutex;

};

Expand Down
6 changes: 6 additions & 0 deletions components/resource/niffilemanager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "niffilemanager.hpp"

#include <osg/Object>
#include <osg/Stats>

#include <components/vfs/manager.hpp>

Expand Down Expand Up @@ -55,4 +56,9 @@ namespace Resource
}
}

void NifFileManager::reportStats(unsigned int frameNumber, osg::Stats *stats)
{
stats->setAttribute(frameNumber, "Nif", mCache->getCacheSize());
}

}
2 changes: 2 additions & 0 deletions components/resource/niffilemanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Resource
/// @note For performance reasons the NifFileManager does not handle case folding, needs
/// to be done in advance by other managers accessing the NifFileManager.
Nif::NIFFilePtr get(const std::string& name);

void reportStats(unsigned int frameNumber, osg::Stats *stats);
};

}
Expand Down
6 changes: 6 additions & 0 deletions components/resource/objectcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,10 @@ void ObjectCache::accept(osg::NodeVisitor &nv)
}
}

unsigned int ObjectCache::getCacheSize() const
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
return _objectCache.size();
}

}
5 changes: 4 additions & 1 deletion components/resource/objectcache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class ObjectCache : public osg::Referenced
/** call node->accept(nv); for all nodes in the objectCache. */
void accept(osg::NodeVisitor& nv);

/** Get the number of objects in the cache. */
unsigned int getCacheSize() const;

protected:

virtual ~ObjectCache();
Expand All @@ -81,7 +84,7 @@ class ObjectCache : public osg::Referenced
typedef std::map<std::string, ObjectTimeStampPair > ObjectCacheMap;

ObjectCacheMap _objectCache;
OpenThreads::Mutex _objectCacheMutex;
mutable OpenThreads::Mutex _objectCacheMutex;

};

Expand Down
7 changes: 7 additions & 0 deletions components/resource/resourcemanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace VFS
class Manager;
}

namespace osg
{
class Stats;
}

namespace Resource
{
class ObjectCache;
Expand All @@ -28,6 +33,8 @@ namespace Resource

const VFS::Manager* getVFS() const;

virtual void reportStats(unsigned int frameNumber, osg::Stats* stats) {}

protected:
const VFS::Manager* mVFS;
osg::ref_ptr<Resource::ObjectCache> mCache;
Expand Down
6 changes: 6 additions & 0 deletions components/resource/resourcesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ namespace Resource
return mVFS;
}

void ResourceSystem::reportStats(unsigned int frameNumber, osg::Stats *stats)
{
for (std::vector<ResourceManager*>::iterator it = mResourceManagers.begin(); it != mResourceManagers.end(); ++it)
(*it)->reportStats(frameNumber, stats);
}

}
7 changes: 7 additions & 0 deletions components/resource/resourcesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace VFS
class Manager;
}

namespace osg
{
class Stats;
}

namespace Resource
{

Expand Down Expand Up @@ -49,6 +54,8 @@ namespace Resource
/// @note May be called from any thread.
const VFS::Manager* getVFS() const;

void reportStats(unsigned int frameNumber, osg::Stats* stats);

private:
std::auto_ptr<SceneManager> mSceneManager;
std::auto_ptr<ImageManager> mImageManager;
Expand Down
11 changes: 11 additions & 0 deletions components/resource/scenemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,15 @@ namespace Resource
mInstanceCache->removeUnreferencedObjectsInCache();
}

void SceneManager::reportStats(unsigned int frameNumber, osg::Stats *stats)
{
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*mIncrementalCompileOperation->getToCompiledMutex());
stats->setAttribute(frameNumber, "Compiling", mIncrementalCompileOperation->getToCompile().size());
}

stats->setAttribute(frameNumber, "Node", mCache->getCacheSize());
stats->setAttribute(frameNumber, "Node Instance", mInstanceCache->getCacheSize());
}

}
2 changes: 2 additions & 0 deletions components/resource/scenemanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ namespace Resource
/// @see ResourceManager::updateCache
virtual void updateCache(double referenceTime);

virtual void reportStats(unsigned int frameNumber, osg::Stats* stats);

private:

osg::ref_ptr<osg::Node> createInstance(const std::string& name);
Expand Down
Loading

0 comments on commit 8f79fa3

Please sign in to comment.