Orfeo Toolbox  4.0
itkMemoryUsageObserver.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkMemoryUsageObserver_h
19 #define __itkMemoryUsageObserver_h
20 
21 #include "itkConfigure.h"
22 #include "itkMacro.h"
23 #include "itkObject.h"
24 #include "itkObjectFactory.h"
25 #include "itkIntTypes.h"
26 
27 #if defined( WIN32 ) || defined( _WIN32 )
28  #include <windows.h>
29  #define SUPPORT_TOOLHELP32
30  #if defined( SUPPORT_TOOLHELP32 )
31 typedef LONG NTSTATUS;
32  #endif
33 #endif
34 
35 namespace itk
36 {
46 class ITKCommon_EXPORT MemoryUsageObserverBase
47 {
48 public:
51 
53  virtual ~MemoryUsageObserverBase();
54 
56  virtual MemoryLoadType GetMemoryUsage() = 0;
57 };
58 
59 #if defined( WIN32 ) || defined( _WIN32 )
60 class ITKCommon_EXPORT WindowsMemoryUsageObserver:public MemoryUsageObserverBase
61 {
62 public:
63  WindowsMemoryUsageObserver();
65  virtual ~WindowsMemoryUsageObserver();
66 
68  virtual MemoryLoadType GetMemoryUsage();
69 
70 protected:
71 #if defined( SUPPORT_TOOLHELP32 )
72  typedef NTSTATUS ( WINAPI * PZwQuerySystemInformation )(UINT, PVOID, ULONG, PULONG);
73 
74  // handle ntdll.dll library
75  HMODULE m_hNTLib;
76  // Windows native API function to query system information
77  PZwQuerySystemInformation ZwQuerySystemInformation;
78 #endif // defined(SUPPORT_TOOLHELP32)
79 };
80 #endif // defined(WIN32) || defined(_WIN32)
81 
82 #ifdef linux
83 class ITKCommon_EXPORT LinuxMemoryUsageObserver:public MemoryUsageObserverBase
84 {
85 public:
87  virtual ~LinuxMemoryUsageObserver();
88  virtual MemoryLoadType GetMemoryUsage();
89 };
90 #endif // linux
91 
92 #if defined( __APPLE__ )
93 class ITKCommon_EXPORT MacOSXMemoryUsageObserver:public MemoryUsageObserverBase
94 {
95 public:
97  virtual ~MacOSXMemoryUsageObserver();
98  virtual MemoryLoadType GetMemoryUsage();
99 };
100 #endif // Mac OS X
101 
102 #if defined( __SUNPRO_CC ) || defined ( __sun__ )
103 class ITKCommon_EXPORT SunSolarisMemoryUsageObserver:public MemoryUsageObserverBase
104 {
105 public:
107  virtual ~SunSolarisMemoryUsageObserver();
108  virtual MemoryLoadType GetMemoryUsage();
109 };
110 #endif // Sun Solaris
111 
112 #if !defined( WIN32 ) && !defined( _WIN32 )
114 {
115 public:
118  virtual MemoryLoadType GetMemoryUsage();
119 };
120 #if !defined( __APPLE__ ) && !defined( __SUNPRO_CC ) && !defined ( __sun__ ) && !defined( __FreeBSD__ ) \
121  && !defined( __OpenBSD__ )
122 
127 {
128 public:
130  virtual ~MallinfoMemoryUsageObserver();
131  virtual MemoryLoadType GetMemoryUsage();
132 };
133 #endif // Mallinfo
134 #endif // !defined(WIN32) && !defined(_WIN32)
135 
136 /* \class MemoryUsageObserver
137  * The best MemoryUsageObserver has been chosen for each OS.
138  * However, SysResourceMemoryUsageObserver is far from being accurate. Other
139  * way of getting the Memory Usage shall be used.
140  * For FreeBSD, some alternatives would be to parse the output of
141  * "sysctl vm.vmtotal" or "sysctl -a | grep -i memory"
142 */
143 class ITKCommon_EXPORT MemoryUsageObserver:
144 #if defined( WIN32 ) || defined( _WIN32 )
145  public WindowsMemoryUsageObserver
146 #elif defined( linux )
147  public LinuxMemoryUsageObserver
148 #elif defined( __SUNPRO_CC ) || defined ( __sun__ )
149  public SunSolarisMemoryUsageObserver
150 #elif defined( __APPLE__ )
151  public MacOSXMemoryUsageObserver
152 #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ )
154 #else
156 #endif
157 {
158 public:
161 };
162 } // end of namespace itk
163 
164 #endif // __itkMemoryUsageObserver_h

Generated at Sat Mar 8 2014 15:12:40 for Orfeo Toolbox with doxygen 1.8.3.1