MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlProfilingManager.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// The profiling manager class.
14
15#ifndef ML_PROFILING_MANAGER_H
16#define ML_PROFILING_MANAGER_H
17
19#include "mlMetaProfile.h"
20#include <map>
21#include <string>
22#include <vector>
23
24#include <mlTimeCounter.h>
25#include <mlMutex.h>
26
27class MLCountProfile;
28class MLMemoryProfile;
29class MLTimeProfile;
30
33#define MLPROFILINGMANAGER_GLOBAL_LOCK() ml::RecursiveLock profilingManagerLock(MLProfilingManager::globalMutex());
34
35//----------------------------------------------------------------------------------
36
38{
39public:
41 static void initialize();
42
44 static void deinitialize();
45
47 static void setProfilingEnabled(bool enabled);
48
50 static bool isProfilingEnabled()
51 {
52 return _singleton && _singleton->_isProfilingEnabled;
53 }
54
56 static std::string byteToHumanReadable(size_t bytes);
57
59 static std::string timeToHumanReadable(double time);
60
62 static void setTimeProfilingGraphEnabled(bool enabled)
63 {
64 _singleton->_isTimeProfilingGraphEnabled = enabled;
65 }
66
69 {
70 return _singleton && _singleton->_isTimeProfilingGraphEnabled;
71 }
72
74 static void resetAllProfilingData();
75
77 static inline double getCurrentTime();
78
81 {
82 return _singleton->_mutex;
83 }
84
86 static void enableTracing(const char* filename);
87
89 static void disableTracing();
90
92 static bool isTracingEnabled();
93
94private:
97
101 static MLMetaProfile* createMetaProfile(const std::string& description, MLMetaProfilePtr* metaProfilePtr);
102
103private:
104 std::vector<MLMetaProfile*> _metaProfiles;
105
106 ml::RecursiveMutex _mutex;
107
108 bool _isProfilingEnabled;
109 bool _isTimeProfilingGraphEnabled;
110
111 static MLProfilingManager* _singleton;
112
113 friend class MLMetaProfile;
114 friend class MLMetaProfilePtr;
115};
116
117
118//----------------------------------------------------------------------------------
119
121{
122 return ML_NAMESPACE::TimeCounter().getCurrentValueInSeconds();
123}
124
125
126#endif // _ML_PROFILING_MANAGER_H_
The pointer is automatically reset when the metaprofile is destroyed.
static void setTimeProfilingGraphEnabled(bool enabled)
Sets whether the time profiling graph is enabled.
static bool isProfilingEnabled()
Returns whether profiling is enabled.
static void disableTracing()
Disables call tracing.
static void initialize()
Initializes the singleton.
static void setProfilingEnabled(bool enabled)
Sets whether profiling is enabled.
static std::string byteToHumanReadable(size_t bytes)
Converts the number of bytes into a human-readable representation.
static bool isTracingEnabled()
Returns whether call tracing is enabled.
static void enableTracing(const char *filename)
Enables call tracing and set the trace filname.
static double getCurrentTime()
Returns the current time in seconds.
static ml::RecursiveMutex & globalMutex()
Returns access to the global recursive mutex of the profiling.
static void resetAllProfilingData()
Resets all profiling data.
static std::string timeToHumanReadable(double time)
Converts the time into a human-readable representation.
static void deinitialize()
Destroys the singleton.
static bool isTimeProfilingGraphEnabled()
Returns whether the time profiling graph is enabled.
boost::recursive_mutex RecursiveMutex
Defines a recursive mutex.
Definition mlMutex.h:32
#define MLPROFILINGMANAGER_EXPORT
Target mlrange_cast(Source arg)
Generic version of checked ML casts.