MeVisLab Toolbox Reference
mlMetaProfile.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2009, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 // Class to combine count, memory and time profiles.
14 
15 #ifndef ML_META_PROFILE_H
16 #define ML_META_PROFILE_H
17 
19 #include "mlCountProfile.h"
20 #include "mlMemoryProfile.h"
21 #include "mlTimeProfile.h"
22 
23 #include <map>
24 #include <vector>
25 
26 class MLMetaProfilePtr;
27 
28 typedef std::map<std::string, MLCountProfile*> MLCountProfileMap;
29 typedef std::map<std::string, MLMemoryProfile*> MLMemoryProfileMap;
30 
31 
32 typedef void MLMetaProfileIsDestroyedCB(void);
33 
34 
36 {
37 public:
38  typedef enum {
39  MLCall = 0,
40  PythonCall = 1,
41  FieldNotificationCall = 2,
42  CppCall = 3,
43  GLRenderCall = 4,
44  PythonQtCall = 5,
45  MLWEMCall = 6,
46  MDLCommandCall = 7,
47  MainFunctionCall = 8,
48  CallTypeCount = 9
49  } MLProfilingFunctionType;
50 
52 
54  const std::vector<MLMetaProfile*>& getSubMetaProfiles() const { return _subMetaProfiles; }
55 
57  void addSubMetaProfile(MLMetaProfile* subMetaProfile) { _subMetaProfiles.push_back(subMetaProfile); subMetaProfile->_superProfile = this; }
58 
59  /* @ingroup CountProfiling
60  * @{
61  */
66  MLCountProfile* createCountProfile(const std::string& key);
67 
70  MLCountProfile* getCountProfile(const std::string& key) const;
71 
75  bool incrementCountValue(const std::string& key);
76 
83  MLProfilingCountType getCountValue(const std::string& key, bool* ok = nullptr) const;
84 
86  const MLCountProfileMap& getCountProfileMap() const { return _countProfileMap; }
87 
90  void setCountProfileDescription(const std::string& key, const std::string& description);
91  /* @}
92  */
93 
94  /* @ingroup MemoryProfiling
95  * @{
96  */
103  MLMemoryProfile* createMemoryProfile(const std::string& key,
105 
108  MLMemoryProfile* getMemoryProfile(const std::string& key) const;
109 
114  bool addMemory(const std::string& key, MLProfilingMemoryType memory);
115 
123  MLProfilingMemoryType getMemory(const std::string& key, bool* ok = nullptr) const;
124 
127 
134  MLProfilingMemoryType getCurrentlyUsedMemory(const std::string& key, bool* ok = nullptr) const;
135 
138 
140  const MLMemoryProfileMap& getMemoryProfileMap() const { return _memoryProfileMap; }
141 
144  void setMemoryProfileDescription(const std::string& key, const std::string& description);
145  /* @}
146  */
147 
148  /* @ingroup TimeProfiling
149  * @{
150  */
156  MLTimeProfileHandle startMeasuring(const std::string& function,
157  int userId,
158  void* userData=nullptr,
159  const std::string& filename="",
160  int linenumber=-1,
161  const std::string& nodeInfo="")
162  {
163  return _timeProfile->startMeasuring(function, userId, userData, filename, linenumber, nodeInfo);
164  }
165 
168  void stopMeasuring(MLTimeProfileHandle& handle, bool ignoreIfEmpty = false) { return _timeProfile->stopMeasuring(handle, ignoreIfEmpty); }
169 
171  MLTimeProfile* getTimeProfile() const { return _timeProfile; }
172  /* @}
173  */
174 
176  void setDescription(const std::string& description_) { _description = description_; }
178  const std::string& description() const { return _description; }
179 
181 
182 private:
183  MLMetaProfile(const std::string& description, MLMetaProfilePtr* metaProfilePtr);
184  // Disallow copying of the meta profile.
186 
187 private:
188  MLCountProfileMap _countProfileMap;
189  MLMemoryProfileMap _memoryProfileMap;
190  MLTimeProfile* _timeProfile;
191 
192  std::vector<MLMetaProfile*> _subMetaProfiles;
193 
194  std::string _description;
195 
196  MLMetaProfilePtr* _metaProfilePtr;
197 
198  MLMetaProfile* _superProfile;
199 
200  friend class MLMetaProfilePtr;
201  friend class MLProfilingManager;
202 };
203 
204 
205 #endif // _ML_META_PROFILE_H_
The pointer is automatically reset when the meta profile is destroyed.
const MLCountProfileMap & getCountProfileMap() const
Returns the map which contains count profiles by functions.
Definition: mlMetaProfile.h:86
MLMemoryProfile * getMemoryProfile(const std::string &key) const
Returns a memory profile, or NULL if it does not exist.
const std::vector< MLMetaProfile * > & getSubMetaProfiles() const
Returns the sub meta profiles.
Definition: mlMetaProfile.h:54
MLProfilingMemoryType getAllCurrentlyUsedMemory() const
Returns the sum of the currently used memory of all memory profiles.
MLProfilingMemoryType getAllMemory() const
Returns the sum of the overall used memory of all memory profiles.
const MLMemoryProfileMap & getMemoryProfileMap() const
Returns the map which contains memory profiles by functions.
MLTimeProfile * getTimeProfile() const
Returns the time profile.
MLCountProfile * createCountProfile(const std::string &key)
Creates a count profile.
static const char * functionTypeToString(MLProfilingFunctionType type)
void stopMeasuring(MLTimeProfileHandle &handle, bool ignoreIfEmpty=false)
Stops measuring time and associates the elapsed time.
MLProfilingMemoryType getCurrentlyUsedMemory(const std::string &key, bool *ok=nullptr) const
Returns the currently used memory in bytes of a memory profile.
MLMemoryProfile * createMemoryProfile(const std::string &key, MLCurrentlyUsedMemoryTracker *tracker)
Creates a memory profile.
MLTimeProfileHandle startMeasuring(const std::string &function, int userId, void *userData=nullptr, const std::string &filename="", int linenumber=-1, const std::string &nodeInfo="")
Starts measuring time.
bool incrementCountValue(const std::string &key)
Increments the count profile value by 1.
void setCountProfileDescription(const std::string &key, const std::string &description)
Sets the description of the count profile.
MLCountProfile * getCountProfile(const std::string &key) const
Returns a count profile, or NULL if it does not exist.
void addSubMetaProfile(MLMetaProfile *subMetaProfile)
Adds a sub meta profile.
Definition: mlMetaProfile.h:57
MLProfilingMemoryType getMemory(const std::string &key, bool *ok=nullptr) const
Returns the overall used memory in bytes of a memory profile.
bool addMemory(const std::string &key, MLProfilingMemoryType memory)
Adds allocated memory to a memory profile.
MLProfilingCountType getCountValue(const std::string &key, bool *ok=nullptr) const
Returns the current value of a count profile.
const std::string & description() const
Returns the meta profile's description.
void setMemoryProfileDescription(const std::string &key, const std::string &description)
Sets the description of the memory profile.
void setDescription(const std::string &description_)
Sets the meta profile's description.
unsigned int MLProfilingCountType
size_t MLProfilingMemoryType
std::map< std::string, MLMemoryProfile * > MLMemoryProfileMap
Definition: mlMetaProfile.h:29
std::map< std::string, MLCountProfile * > MLCountProfileMap
Definition: mlMetaProfile.h:26
void MLMetaProfileIsDestroyedCB(void)
Definition: mlMetaProfile.h:32
#define MLPROFILINGMANAGER_EXPORT