diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index 0d7919687..0bdcc3681 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -48,6 +48,7 @@ int main(int argc, char** argv) arguments.getApplicationUsage()->addCommandLineOption("-p ","Play specified camera path animation file, previously saved with 'z' key."); arguments.getApplicationUsage()->addCommandLineOption("--speed ","Speed factor for animation playing (1 == normal speed)."); arguments.getApplicationUsage()->addCommandLineOption("--device ","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 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 "<collectStats("compile", true); + } + + // any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); diff --git a/src/osgViewer/Renderer.cpp b/src/osgViewer/Renderer.cpp index 59775885e..ab9330818 100644 --- a/src/osgViewer/Renderer.cpp +++ b/src/osgViewer/Renderer.cpp @@ -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 "<getSceneData())); + } } sceneView->getState()->checkGLErrors("After Renderer::compile");