MeVisLab Toolbox Reference
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() { return _singleton && _singleton->_isProfilingEnabled; }
51
53 static std::string byteToHumanReadable(size_t bytes);
54
56 static std::string timeToHumanReadable(double time);
57
59 static void setTimeProfilingGraphEnabled(bool enabled) { _singleton->_isTimeProfilingGraphEnabled = enabled; }
60
62 static bool isTimeProfilingGraphEnabled() { return _singleton && _singleton->_isTimeProfilingGraphEnabled; }
63
65 static void resetAllProfilingData();
66
68 static inline double getCurrentTime();
69
71 static ml::RecursiveMutex& globalMutex() { return _singleton->_mutex; }
72
74 static void enableTracing(const char* filename);
75
77 static void disableTracing();
78
80 static bool isTracingEnabled();
81
82private:
85
89 static MLMetaProfile* createMetaProfile(const std::string& description, MLMetaProfilePtr* metaProfilePtr);
90
91private:
92 std::vector<MLMetaProfile*> _metaProfiles;
93
94 ml::RecursiveMutex _mutex;
95
96 bool _isProfilingEnabled;
97 bool _isTimeProfilingGraphEnabled;
98
99 static MLProfilingManager* _singleton;
100
101 friend class MLMetaProfile;
102 friend class MLMetaProfilePtr;
103};
104
105
106
107//----------------------------------------------------------------------------------
108
110{
111 return ML_NAMESPACE::TimeCounter().getCurrentValueInSeconds();
112}
113
114
115
116#endif // _ML_PROFILING_MANAGER_H_
The pointer is automatically reset when the meta profile is destroyed.
static void setTimeProfilingGraphEnabled(bool enabled)
Sets if the time profiling graph is enabled.
static bool isProfilingEnabled()
Returns if profiling is enabled.
static void disableTracing()
Disables call tracing.
static void initialize()
Initializes the singleton.
static void setProfilingEnabled(bool enabled)
Sets if profiling is enabled.
static std::string byteToHumanReadable(size_t bytes)
Converts the number of bytes into a human readable representation.
static bool isTracingEnabled()
Returns if call tracing is enabled.
static void enableTracing(const char *filename)
Enable call tracing and set the trace filname.
static double getCurrentTime()
Returns the current time in seconds.
static ml::RecursiveMutex & globalMutex()
Get 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 if 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.