MeVisLabToolboxReference
|
00001 // **InsertLicense** code 00002 //---------------------------------------------------------------------------------- 00003 // Class for collecting time profiling information. 00004 // 00005 // \file mlTimeProfile.h 00006 // \author Marcus Barann 00007 // \date 7/2009 00008 // 00009 //---------------------------------------------------------------------------------- 00010 #ifndef _ML_TIME_PROFILE_H_ 00011 #define _ML_TIME_PROFILE_H_ 00012 00013 #include "mlProfilingManagerDllExport.h" 00014 00015 #include "../Include/mlCallGraph.h" 00016 00017 #include <boost/thread/thread.hpp> 00018 #include <boost/shared_ptr.hpp> 00019 00020 #include <map> 00021 #include <vector> 00022 00023 #define ML_TIME_PROFILE_CREATE_SCOPED_LOCK() \ 00024 boost::mutex::scoped_lock callGraphMutexLock(MLTimeProfile::_callGraphMutex); 00025 00026 class MLMetaProfile; 00027 class MLTimeProfile; 00028 class MLCallGraphNode; 00029 00030 typedef boost::shared_ptr<MLCallGraphFunction> MLCallGraphFunctionPtr; 00031 00032 typedef std::vector<MLCallGraphNode*> MLCallGraphNodesVector; 00033 typedef std::map<std::string, MLCallGraphNodesVector> MLCallGraphNodesByKeyMap; 00034 typedef MLCallGraphNodesByKeyMap::iterator MLCallGraphNodesByKeyMapIterator; 00035 typedef std::map<MLCallGraphFunctionId, MLCallGraphFunctionPtr> MLCallGraphFunctionMap; 00036 typedef std::vector<MLCallGraphFunctionPtr> MLCallGraphFunctionList; 00037 00038 typedef std::map<MLCallGraphFunctionId, MLTimeStatistics*> MLTimeStatisticsByFunctionMap; 00039 typedef MLTimeStatisticsByFunctionMap::iterator MLTimeStatisticsByFunctionMapIterator; 00040 00041 00042 class MLPROFILINGMANAGER_EXPORT MLTimeProfileHandle 00043 { 00044 public: 00045 MLTimeProfileHandle(); 00046 00047 private: 00048 MLTimeProfileHandle(MLCallGraphNode* callGraphNode); 00049 00050 MLCallGraphNode* _callGraphNode; 00051 00052 friend class MLTimeProfile; 00053 friend class ProfilingTest_TestCallGraphIsRecursive_Test; 00054 friend class ProfilingTest_TestProfileAccumulation_Test; 00055 }; 00056 00057 00058 class MLPROFILINGMANAGER_EXPORT MLTimeProfile 00059 { 00060 public: 00061 MLTimeProfile(const MLMetaProfile* metaProfile = NULL); 00062 ~MLTimeProfile(); 00063 00067 MLTimeProfileHandle startMeasuring(const std::string& function, 00068 int userId, 00069 void* userData, 00070 const std::string& filename, 00071 int linenumber); 00072 00075 void stopMeasuring(MLTimeProfileHandle& handle); 00076 00078 void reset(); 00079 00081 const MLMetaProfile* metaProfile() const; 00082 00084 MLProfilingTimeType allElapsedTime() const { return _allElapsedTime; } 00085 00087 MLProfilingTimeType allConsumedTime() const { return _allConsumedTime; } 00088 00090 static MLCallGraphNode& callGraph(); 00091 00093 const MLCallGraphFunctionMap& functionMap() const { return _functionMap; } 00094 00096 static const MLCallGraphFunctionMap& globalFunctionMap() { return _globalFunctionMap; } 00097 00099 static const MLCallGraphFunctionList& globalFunctionList() { return _globalFunctionList; } 00100 00102 MLCallGraphFunctionId getFunctionId(const std::string& identifier) const; 00103 00105 static MLCallGraphFunctionPtr getFunctionGlobal(const std::string& identifier); 00106 00108 MLCallGraphFunctionPtr getFunction(MLCallGraphFunctionId functionId) const; 00109 00111 static MLProfilingTimeType globalElapsedTime(); 00112 00114 static void setReduceCallGraph(bool reduceCallGraph) { _reduceCallGraph = reduceCallGraph; }; 00115 00117 static void initialize(); 00118 00120 static void deinitialize(); 00121 00122 private: 00126 void deleteFunction(const MLCallGraphFunctionPtr& function); 00127 00129 static void addGlobalFunction(const MLCallGraphFunctionPtr& function); 00130 00134 static void deleteGlobalFunction(const MLCallGraphFunctionPtr& function); 00135 00138 void removeCallGraphNode(MLCallGraphNode* node); 00139 00141 void updateStatistics(MLTimeStatistics& statistics, 00142 bool updateElapsedTime, 00143 MLProfilingTimeType elapsedTime, 00144 MLProfilingTimeType consumedTime); 00146 static void resetGlobalData(); 00147 00148 public: 00149 static MLCallGraphFunctionPtr mainFunction; 00150 00151 private: 00152 MLCallGraphFunctionMap _functionMap; 00153 00154 MLProfilingTimeType _allElapsedTime; 00155 MLProfilingTimeType _allConsumedTime; 00156 00157 const MLMetaProfile* _metaProfile; 00158 00159 MLCallGraphNodesVector _callGraphNodes; 00160 00161 static bool _reduceCallGraph; 00162 00163 static MLCallGraphFunctionId _lastFunctionId; 00164 static MLCallGraphFunctionMap _globalFunctionMap; 00165 // duplicates the global function map values, but is required for performance reasons 00166 static MLCallGraphFunctionList _globalFunctionList; 00167 00168 static MLCallGraphNode* _callGraph; 00169 static MLCallGraphNode* _lastCallGraphNode; 00170 static boost::mutex _callGraphMutex; 00171 00172 friend class MLAccumulatedProfile; 00173 friend class MLCallGraphNode; 00174 friend class MLProfilingManager; 00175 00176 friend class MLABModuleProfile; 00177 }; 00178 00179 00180 #endif // _ML_TIME_PROFILE_H_