MeVisLabToolboxReference
MeVis/Foundation/Sources/MLProfilingManager/Include/mlMetaProfile.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00003 // Class to combine count, memory and time profiles.
00004 //
00005 // \file    mlMetaProfile.h
00006 // \author  Marcus Barann
00007 // \date    8/2009
00008 //
00009 //----------------------------------------------------------------------------------
00010 #ifndef _ML_META_PROFILE_H_
00011 #define _ML_META_PROFILE_H_
00012 
00013 #include "mlProfilingManagerDllExport.h"
00014 #include "mlCountProfile.h"
00015 #include "mlMemoryProfile.h"
00016 #include "mlTimeProfile.h"
00017 
00018 #include <map>
00019 #include <vector>
00020 
00021 class MLMetaProfilePtr;
00022 
00023 typedef std::map<std::string, MLCountProfile*>  MLCountProfileMap;
00024 typedef std::map<std::string, MLMemoryProfile*> MLMemoryProfileMap;
00025 
00026 
00027 typedef void MLMetaProfileIsDestroyedCB(void);
00028 
00029 
00030 class MLPROFILINGMANAGER_EXPORT MLMetaProfile
00031 {
00032 public:
00033   typedef enum {
00034     MLCall = 0,
00035     PythonCall = 1,
00036     FieldNotificationCall = 2,
00037     CppCall = 3,
00038     GLRenderCall = 4,
00039     PythonQtCall = 5,
00040     MLWEMCall = 6,
00041     MDLCommandCall = 7,
00042     MainFunctionCall = 8,
00043     CallTypeCount = 9
00044   } MLProfilingFunctionType;
00045 
00047   const std::vector<MLMetaProfile*>& getSubMetaProfiles() const { return _subMetaProfiles; }
00048 
00050   void addSubMetaProfile(MLMetaProfile* subMetaProfile) { _subMetaProfiles.push_back(subMetaProfile); subMetaProfile->_superProfile = this; }
00051 
00052   /* @ingroup CountProfiling
00053    * @{
00054    */
00059   MLCountProfile* createCountProfile(const std::string& key);
00060 
00063   MLCountProfile* getCountProfile(const std::string& key) const;
00064 
00068   bool incrementCountValue(const std::string& key);
00069 
00076   MLProfilingCountType getCountValue(const std::string& key, bool* ok = NULL) const;
00077 
00079   const MLCountProfileMap& getCountProfileMap() const { return _countProfileMap; }
00080 
00083   void setCountProfileDescription(const std::string& key, const std::string& description);
00084   /* @}
00085    */
00086 
00087   /* @ingroup MemoryProfiling
00088    * @{
00089    */
00096   MLMemoryProfile* createMemoryProfile(const std::string& key,
00097                                        MLCurrentlyUsedMemoryTracker* tracker);
00098 
00101   MLMemoryProfile* getMemoryProfile(const std::string& key) const;
00102 
00107   bool addMemory(const std::string& key, MLProfilingMemoryType memory);
00108 
00116   MLProfilingMemoryType getMemory(const std::string& key, bool* ok = NULL) const;
00117 
00119   MLProfilingMemoryType getAllMemory() const;
00120 
00127   MLProfilingMemoryType getCurrentlyUsedMemory(const std::string& key, bool* ok = NULL) const;
00128 
00130   MLProfilingMemoryType getAllCurrentlyUsedMemory() const;
00131 
00133   const MLMemoryProfileMap& getMemoryProfileMap() const { return _memoryProfileMap; }
00134 
00137   void setMemoryProfileDescription(const std::string& key, const std::string& description);
00138   /* @}
00139    */
00140 
00141   /* @ingroup TimeProfiling
00142    * @{
00143    */
00149   MLTimeProfileHandle startMeasuring(const std::string& function,
00150                                      int userId,
00151                                      void* userData=NULL,
00152                                      const std::string& filename="",
00153                                      int linenumber=-1)
00154   {
00155     return _timeProfile->startMeasuring(function, userId, userData, filename, linenumber);
00156   }
00157 
00160   void stopMeasuring(MLTimeProfileHandle& handle)  { return _timeProfile->stopMeasuring(handle); }
00161 
00163   MLTimeProfile* getTimeProfile() const { return _timeProfile; }
00164   /* @}
00165    */
00166 
00168   void setDescription(const std::string& description_) { _description = description_; }
00170   const std::string& description() const { return _description; }
00171 
00172   ~MLMetaProfile();
00173 
00174 private:
00175   MLMetaProfile(const std::string& description, MLMetaProfilePtr* metaProfilePtr);
00176   // Disallow copying of the meta profile.
00177   MLMetaProfile(const MLMetaProfile&);
00178 
00179 private:
00180   MLCountProfileMap     _countProfileMap;
00181   MLMemoryProfileMap    _memoryProfileMap;
00182   MLTimeProfile*        _timeProfile;
00183 
00184   std::vector<MLMetaProfile*> _subMetaProfiles;
00185 
00186   std::string _description;
00187 
00188   MLMetaProfilePtr* _metaProfilePtr;
00189 
00190   MLMetaProfile* _superProfile;
00191 
00192   friend class MLMetaProfilePtr;
00193   friend class MLProfilingManager;
00194 };
00195 
00196 
00197 #endif // _ML_META_PROFILE_H_