![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2012 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 00009 00010 #pragma once 00011 00012 #include <string> 00013 #include <vector> 00014 00015 #include <vrvCore/vrvCore.h> 00016 #include <vlutil/vlPerformanceStats.h> 00017 #include <boost/preprocessor/seq/for_each.hpp> 00018 #include <boost/preprocessor/facilities/expand.hpp> 00019 00020 namespace makVrv 00021 { 00038 #define DT_DECLARE_STATS_SET(name, id, stats_elements)\ 00039 DT_STATSSET_DECLARE_ENUM(id, stats_elements)\ 00040 \ 00041 void init##id##Stats(makVrv::DtPerformanceStatsManager& mgr)\ 00042 {\ 00043 static bool guard = false;\ 00044 guard = true;\ 00045 makVrv::DtStatsSet* id##_statsSet = new makVrv::DtStatsSet();\ 00046 id##_statsSet->myName = name;\ 00047 BOOST_PP_SEQ_FOR_EACH(DT_STATSSET_ADD, id##_statsSet, stats_elements)\ 00048 mgr.add(name, id##_statsSet);\ 00049 }\ 00050 00051 #define DT_STATSSET_QUOTE(x) #x 00052 #define DT_STATSSET_ENUM(r, name, elem) BOOST_PP_CAT(timer, BOOST_PP_CAT(_, BOOST_PP_CAT(name, BOOST_PP_CAT(_, elem)))), 00053 #define DT_STATSSET_ADD(r, stats_set_ptr, elem) stats_set_ptr->addStats(DT_STATSSET_QUOTE(elem)); 00054 #define DT_STATSSET_DECLARE_ENUM(name, seq) enum TimerStats_##name { BOOST_PP_SEQ_FOR_EACH(DT_STATSSET_ENUM, name, seq) timer_##name##_end}; 00055 00057 struct DT_DLL_VRVCORE DtTimeStat 00058 { 00059 std::string myDescription; 00060 DtTimeStatistic myStatistic; 00061 }; 00062 00065 class DT_DLL_VRVCORE DtStatsSet 00066 { 00067 public: 00069 void addStats(const std::string& name); 00070 00074 void startFrame(); 00075 00079 void endFrame(double frameDuration); 00080 00084 void addTime(unsigned int index, double t); 00085 00086 std::vector<DtTimeStat> myStats; 00087 double myTotalTime; 00088 std::vector<double> myPerFrameStats; 00089 DtPerformanceStats myStatsTimer; 00090 std::string myName; 00091 }; 00092 00098 class DT_DLL_VRVCORE ScopedStatTimer 00099 { 00100 public: 00102 ScopedStatTimer(unsigned int timerIndex, makVrv::DtStatsSet& statsSet); 00103 00105 virtual ~ScopedStatTimer(); 00106 00107 protected: 00108 DtTimedSection myTimedSection; 00109 makVrv::DtStatsSet& myStatsSet; 00110 unsigned int myIndex; 00111 }; 00112 00115 #define DT_SCOPED_STAT_TIMER(stats_element, stats_set_id, stats_set_ref)\ 00116 ScopedStatTimer scopedStatTimer_##stats_element(timer_##stats_set_id##_##stats_element, stats_set_ref) 00117 }