ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkMemoryUsageObserver.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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)
31using NTSTATUS = LONG;
32# endif
33#endif
34
35namespace itk
36{
45
46class ITKCommon_EXPORT MemoryUsageObserverBase
47{
48public:
51
54
56 virtual MemoryLoadType
58};
59
60#if defined(WIN32) || defined(_WIN32)
61class ITKCommon_EXPORT WindowsMemoryUsageObserver : public MemoryUsageObserverBase
62{
63public:
64 WindowsMemoryUsageObserver();
66 virtual ~WindowsMemoryUsageObserver();
67
69 virtual MemoryLoadType
70 GetMemoryUsage();
71
72protected:
73# if defined(SUPPORT_TOOLHELP32)
74 using PZwQuerySystemInformation = NTSTATUS(WINAPI *)(UINT, PVOID, ULONG, PULONG);
75
76 // handle ntdll.dll library
77 HMODULE m_hNTLib{ nullptr };
78 // Windows native API function to query system information
79 PZwQuerySystemInformation ZwQuerySystemInformation{ nullptr };
80# endif // defined(SUPPORT_TOOLHELP32)
81};
82#endif // defined(WIN32) || defined(_WIN32)
83
84#ifdef __linux__
85class ITKCommon_EXPORT LinuxMemoryUsageObserver : public MemoryUsageObserverBase
86{
87public:
89 ~LinuxMemoryUsageObserver() override;
90
91 MemoryLoadType
92 GetMemoryUsage() override;
93};
94#endif // __linux__
95
96#if defined(__APPLE__)
97class ITKCommon_EXPORT MacOSXMemoryUsageObserver : public MemoryUsageObserverBase
98{
99public:
101 ~MacOSXMemoryUsageObserver() override;
102
103 MemoryLoadType
104 GetMemoryUsage() override;
105};
106#endif // Mac OS X
107
108#if defined(__SUNPRO_CC) || defined(__sun__)
109class ITKCommon_EXPORT SunSolarisMemoryUsageObserver : public MemoryUsageObserverBase
110{
111public:
113 virtual ~SunSolarisMemoryUsageObserver();
114
115 virtual MemoryLoadType
116 GetMemoryUsage();
117};
118#endif // Sun Solaris
119
120#if !defined(WIN32) && !defined(_WIN32)
122{
123public:
126
128 GetMemoryUsage() override;
129};
130
131# if defined(ITK_HAS_MALLINFO) || defined(ITK_HAS_MALLINFO2)
136class ITKCommon_EXPORT MallinfoMemoryUsageObserver : public MemoryUsageObserverBase
137{
138public:
140 ~MallinfoMemoryUsageObserver() override;
141
142 MemoryLoadType
143 GetMemoryUsage() override;
144};
145
146# endif // Mallinfo
147#endif // !defined(WIN32) && !defined(_WIN32)
148
149/* \class MemoryUsageObserver
150 * The best MemoryUsageObserver has been chosen for each OS.
151 * However, SysResourceMemoryUsageObserver is far from being accurate. Other
152 * way of getting the Memory Usage shall be used.
153 * For FreeBSD, some alternatives would be to parse the output of
154 * "sysctl vm.vmtotal" or "sysctl -a | grep -i memory"
155 */
156class ITKCommon_EXPORT MemoryUsageObserver
157 :
158#if defined(WIN32) || defined(_WIN32)
159 public WindowsMemoryUsageObserver
160#elif defined(__linux__)
161 public LinuxMemoryUsageObserver
162#elif defined(__SUNPRO_CC) || defined(__sun__)
163 public SunSolarisMemoryUsageObserver
164#elif defined(__APPLE__)
165 public MacOSXMemoryUsageObserver
166#elif defined(__FreeBSD__) || defined(__OpenBSD__)
168#else
169 public MallinfoMemoryUsageObserver
170#endif
171{
172public:
175};
176} // end of namespace itk
177
178#endif // itkMemoryUsageObserver_h
virtual MemoryLoadType GetMemoryUsage()=0
Provides the memory usage of the process.
~MemoryUsageObserver() override
MemoryLoadType GetMemoryUsage() override
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86