ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkMemoryUsageObserver.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkMemoryUsageObserver_h
00019 #define __itkMemoryUsageObserver_h
00020 
00021 #include "itkConfigure.h"
00022 #include "itkMacro.h"
00023 #include "itkObject.h"
00024 #include "itkObjectFactory.h"
00025 #include "itkIntTypes.h"
00026 
00027 #if defined( WIN32 ) || defined( _WIN32 )
00028   #include <windows.h>
00029   #define SUPPORT_TOOLHELP32
00030   #if defined( SUPPORT_TOOLHELP32 )
00031 typedef LONG NTSTATUS;
00032   #endif
00033 #endif
00034 
00035 namespace itk
00036 {
00046 class ITKCommon_EXPORT MemoryUsageObserverBase
00047 {
00048 public:
00050   typedef SizeValueType MemoryLoadType;
00051 
00053   virtual ~MemoryUsageObserverBase();
00054 
00056   virtual MemoryLoadType GetMemoryUsage() = 0;
00057 };
00058 
00059 #if defined( WIN32 ) || defined( _WIN32 )
00060 class ITKCommon_EXPORT WindowsMemoryUsageObserver:public MemoryUsageObserverBase
00061 {
00062 public:
00063   WindowsMemoryUsageObserver();
00065   virtual ~WindowsMemoryUsageObserver();
00066 
00068   virtual MemoryLoadType GetMemoryUsage();
00069 
00070 protected:
00071 #if defined( SUPPORT_TOOLHELP32 )
00072   typedef NTSTATUS ( WINAPI * PZwQuerySystemInformation )(UINT, PVOID, ULONG, PULONG);
00073 
00074   // handle ntdll.dll library
00075   HMODULE m_hNTLib;
00076   // Windows native API function to query system information
00077   PZwQuerySystemInformation ZwQuerySystemInformation;
00078 #endif // defined(SUPPORT_TOOLHELP32)
00079 };
00080 #endif // defined(WIN32) || defined(_WIN32)
00081 
00082 #ifdef linux
00083 class ITKCommon_EXPORT LinuxMemoryUsageObserver:public MemoryUsageObserverBase
00084 {
00085 public:
00087   virtual ~LinuxMemoryUsageObserver();
00088   virtual MemoryLoadType GetMemoryUsage();
00089 };
00090 #endif // linux
00091 
00092 
00093 #if defined( __APPLE__ )
00094 class ITKCommon_EXPORT MacOSXMemoryUsageObserver:public MemoryUsageObserverBase
00095 {
00096 public:
00098   virtual ~MacOSXMemoryUsageObserver();
00099   virtual MemoryLoadType GetMemoryUsage();
00100 };
00101 #endif // Mac OS X
00102 
00103 
00104 #if defined( __SUNPRO_CC ) || defined ( __sun__ )
00105 class ITKCommon_EXPORT SunSolarisMemoryUsageObserver:public MemoryUsageObserverBase
00106 {
00107 public:
00109   virtual ~SunSolarisMemoryUsageObserver();
00110   virtual MemoryLoadType GetMemoryUsage();
00111 };
00112 #endif // Sun Solaris
00113 
00114 
00115 #if !defined( WIN32 ) && !defined( _WIN32 )
00116 class ITKCommon_EXPORT SysResourceMemoryUsageObserver:public MemoryUsageObserverBase
00117 {
00118 public:
00120   virtual ~SysResourceMemoryUsageObserver();
00121   virtual MemoryLoadType GetMemoryUsage();
00122 };
00123 #if !defined( __APPLE__ ) && !defined( __SUNPRO_CC ) && !defined ( __sun__ ) && !defined( __FreeBSD__ ) \
00124   && !defined( __OpenBSD__ )
00125 
00128 
00136 
00141 
00147 
00155 
00172