MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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
27
28typedef std::map<std::string, MLCountProfile*> MLCountProfileMap;
29typedef std::map<std::string, MLMemoryProfile*> MLMemoryProfileMap;
30
31
32typedef void MLMetaProfileIsDestroyedCB(void);
33
34
36{
37public:
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
55 {
56 return _subMetaProfiles;
57 }
58
61 {
62 _subMetaProfiles.push_back(subMetaProfile);
63 subMetaProfile->_superProfile = this;
64 }
65
66 /* @ingroup CountProfiling
67 * @{
68 */
74
77 MLCountProfile* getCountProfile(const std::string& key) const;
78
82 bool incrementCountValue(const std::string& key);
83
90 MLProfilingCountType getCountValue(const std::string& key, bool* ok = nullptr) const;
91
94 {
95 return _countProfileMap;
96 }
97
100 void setCountProfileDescription(const std::string& key, const std::string& description);
101 /* @}
102 */
103
104 /* @ingroup MemoryProfiling
105 * @{
106 */
114
117 MLMemoryProfile* getMemoryProfile(const std::string& key) const;
118
123 bool addMemory(const std::string& key, MLProfilingMemoryType memory);
124
132 MLProfilingMemoryType getMemory(const std::string& key, bool* ok = nullptr) const;
133
136
143 MLProfilingMemoryType getCurrentlyUsedMemory(const std::string& key, bool* ok = nullptr) const;
144
147
150 {
151 return _memoryProfileMap;
152 }
153
156 void setMemoryProfileDescription(const std::string& key, const std::string& description);
157 /* @}
158 */
159
160 /* @ingroup TimeProfiling
161 * @{
162 */
168 MLTimeProfileHandle startMeasuring(const std::string& function, int userId, void* userData = nullptr,
169 const std::string& filename = "", int linenumber = -1,
170 const std::string& nodeInfo = "")
171 {
172 return _timeProfile->startMeasuring(function, userId, userData, filename, linenumber, nodeInfo);
173 }
174
178 {
179 return _timeProfile->stopMeasuring(handle, ignoreIfEmpty);
180 }
181
184 {
185 return _timeProfile;
186 }
187 /* @}
188 */
189
191 void setDescription(const std::string& description_)
192 {
193 _description = description_;
194 }
196 const std::string& description() const
197 {
198 return _description;
199 }
200
202
203private:
204 MLMetaProfile(const std::string& description, MLMetaProfilePtr* metaProfilePtr);
205 // Disallow copying of the metaprofile.
207
208private:
209 MLCountProfileMap _countProfileMap;
210 MLMemoryProfileMap _memoryProfileMap;
211 MLTimeProfile* _timeProfile;
212
213 std::vector<MLMetaProfile*> _subMetaProfiles;
214
215 std::string _description;
216
217 MLMetaProfilePtr* _metaProfilePtr;
218
219 MLMetaProfile* _superProfile;
220
221 friend class MLMetaProfilePtr;
222 friend class MLProfilingManager;
223};
224
225
226#endif // _ML_META_PROFILE_H_
The pointer is automatically reset when the metaprofile is destroyed.
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.
MLCountProfile * createCountProfile(const std::string &key)
Creates a count profile.
MLTimeProfile * getTimeProfile() const
Returns the time profile.
const std::string & description() const
Returns the metaprofile's description.
const MLMemoryProfileMap & getMemoryProfileMap() const
Returns the map which contains memory profiles by functions.
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.
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.
MLCountProfile * getCountProfile(const std::string &key) const
Returns a count profile, or NULL if it does not exist.
MLMemoryProfile * getMemoryProfile(const std::string &key) const
Returns a memory profile, or NULL if it does not exist.
MLMemoryProfile * createMemoryProfile(const std::string &key, MLCurrentlyUsedMemoryTracker *tracker)
Creates a memory profile.
void setCountProfileDescription(const std::string &key, const std::string &description)
Sets the description of the count profile.
const std::vector< MLMetaProfile * > & getSubMetaProfiles() const
Returns the submetaprofiles.
const MLCountProfileMap & getCountProfileMap() const
Returns the map which contains count profiles by functions.
void addSubMetaProfile(MLMetaProfile *subMetaProfile)
Adds a submetaprofile.
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.
void setMemoryProfileDescription(const std::string &key, const std::string &description)
Sets the description of the memory profile.
static const char * functionTypeToString(MLProfilingFunctionType type)
void setDescription(const std::string &description_)
Sets the metaprofile's description.
unsigned int MLProfilingCountType
size_t MLProfilingMemoryType
std::map< std::string, MLMemoryProfile * > MLMemoryProfileMap
std::map< std::string, MLCountProfile * > MLCountProfileMap
void MLMetaProfileIsDestroyedCB(void)
#define MLPROFILINGMANAGER_EXPORT
Target mlrange_cast(Source arg)
Generic version of checked ML casts.