Added basic load and compile stats collection enabled by --stats command line.

This commit is contained in:
Robert Osfield 2019-03-25 14:09:04 +00:00
parent 0b5cb65cdd
commit dd32ee2945
2 changed files with 37 additions and 1 deletions

View File

@ -48,6 +48,7 @@ int main(int argc, char** argv)
arguments.getApplicationUsage()->addCommandLineOption("-p <filename>","Play specified camera path animation file, previously saved with 'z' key.");
arguments.getApplicationUsage()->addCommandLineOption("--speed <factor>","Speed factor for animation playing (1 == normal speed).");
arguments.getApplicationUsage()->addCommandLineOption("--device <device-name>","add named device to the viewer");
arguments.getApplicationUsage()->addCommandLineOption("--stats","print out load and compile timing stats");
osgViewer::Viewer viewer(arguments);
@ -71,6 +72,8 @@ int main(int argc, char** argv)
return 1;
}
bool printStats = arguments.read("--stats");
std::string url, username, password;
while(arguments.read("--login",url, username, password))
{
@ -147,6 +150,8 @@ int main(int argc, char** argv)
// add the screen capture handler
viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
osg::ElapsedTime elapsedTime;
// load the data
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
if (!loadedModel)
@ -155,6 +160,15 @@ int main(int argc, char** argv)
return 1;
}
if (printStats)
{
double loadTime = elapsedTime.elapsedTime_m();
std::cout<<"Load time "<<loadTime<<"ms"<<std::endl;
viewer.getStats()->collectStats("compile", true);
}
// any option left unread are converted into errors to write out later.
arguments.reportRemainingOptionsAsUnrecognized();

View File

@ -588,7 +588,29 @@ void Renderer::compile()
{
osgUtil::GLObjectsVisitor glov;
glov.setState(sceneView->getState());
glov.compile(*(sceneView->getSceneData()));
// collect stats if required
osg::View* view = _camera.valid() ? _camera->getView() : 0;
osg::Stats* stats = view ? view->getStats() : 0;
if (stats && stats->collectStats("compile"))
{
osg::ElapsedTime elapsedTime;
glov.compile(*(sceneView->getSceneData()));
double compileTime = elapsedTime.elapsedTime();
const osg::FrameStamp* fs = sceneView->getFrameStamp();
unsigned int frameNumber = fs ? fs->getFrameNumber() : 0;
stats->setAttribute(frameNumber, "compile", compileTime);
OSG_NOTICE<<"Compile time "<<compileTime*1000.0<<"ms"<<std::endl;
}
else
{
glov.compile(*(sceneView->getSceneData()));
}
}
sceneView->getState()->checkGLErrors("After Renderer::compile");