![]() |
|
|
Generated: 8 Jan 2009 |
00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/src/Lib/Memory.cpp,v 1.1 2001/03/14 15:30:16 mato Exp $ 00002 //==================================================================== 00003 // Memory.cpp 00004 //-------------------------------------------------------------------- 00005 // 00006 // Package : System (The LHCb System service) 00007 // 00008 // Description: Information of memory usage from a given process 00009 // 00010 // Author : M.Frank 00011 // Created : 13/11/00 00012 // Changes : 00013 // 00014 //==================================================================== 00015 #define GAUDIKERNEL_MEMORY_CPP 00016 00017 #ifdef _WIN32 00018 #include "process.h" 00019 #define getpid _getpid 00020 #else 00021 #include <errno.h> 00022 #include <string.h> 00023 #include "sys/times.h" 00024 #include "unistd.h" 00025 #include "libgen.h" 00026 #include <cstdio> 00027 #endif 00028 00029 // Framework include files 00030 #include <limits.h> 00031 #include "GaudiKernel/Memory.h" 00032 #include "ProcessDescriptor.h" 00033 00035 long System::adjustMemory( MemoryUnit unit, long value ) { 00036 if ( value != -1 ) { 00037 switch ( unit ) { 00038 case Byte: value = value; break; 00039 case kByte: value = value/1024; break; 00040 case MByte: value = (value/1024)/1024; break; 00041 case GByte: value = ((value/1024)/1024)/1024; break; 00042 case TByte: value = (((value/1024)/1024)/1024)/1024; break; 00043 case PByte: value = ((((value/1024)/1024)/1024)/1024)/1024; break; 00044 case EByte: value = (((((value/1024)/1024)/1024)/1024)/1024)/1024; break; 00045 default: value = -1; break; 00046 } 00047 } 00048 return value; 00049 } 00050 00052 long System::basePriority(InfoType fetch, long pid) { 00053 PROCESS_BASIC_INFORMATION info; 00054 if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) ) 00055 return info.BasePriority; 00056 return 0; 00057 } 00058 00060 long System::procID() { 00061 static long s_pid = ::getpid(); 00062 return s_pid; 00063 } 00064 00066 long System::parentID(InfoType fetch, long pid) { 00067 PROCESS_BASIC_INFORMATION info; 00068 if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) ) 00069 return info.InheritedFromUniqueProcessId; 00070 return 0; 00071 } 00072 00074 long System::affinityMask(InfoType fetch, long pid) { 00075 PROCESS_BASIC_INFORMATION info; 00076 if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) ) 00077 return info.AffinityMask; 00078 return 0; 00079 } 00080 00082 long System::exitStatus(InfoType fetch, long pid) { 00083 PROCESS_BASIC_INFORMATION info; 00084 if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) ) 00085 return info.ExitStatus; 00086 return -2; 00087 } 00088 00090 long System::priorityBoost(InfoType fetch, long pid) { 00091 long info; 00092 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00093 return info; 00094 return -2; 00095 } 00096 00098 long System::nonPagedMemoryPeak(MemoryUnit unit, InfoType fetch, long pid) { 00099 VM_COUNTERS info; 00100 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00101 return adjustMemory(unit, info.QuotaPeakNonPagedPoolUsage); 00102 return -2; 00103 } 00104 00106 long System::nonPagedMemory(MemoryUnit unit, InfoType fetch, long pid) { 00107 VM_COUNTERS info; 00108 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00109 return adjustMemory(unit, info.QuotaNonPagedPoolUsage); 00110 return -2; 00111 } 00112 00114 long System::nonPagedMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) { 00115 POOLED_USAGE_AND_LIMITS quota; 00116 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) 00117 return adjustMemory(unit, quota.NonPagedPoolLimit); 00118 return 0; 00119 } 00120 00122 long System::pagedMemory(MemoryUnit unit, InfoType fetch, long pid) { 00123 VM_COUNTERS info; 00124 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00125 return adjustMemory(unit, info.QuotaPagedPoolUsage); 00126 return -2; 00127 } 00128 00130 long System::pagedMemoryPeak(MemoryUnit unit, InfoType fetch, long pid) { 00131 VM_COUNTERS info; 00132 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00133 return adjustMemory(unit, info.QuotaPeakPagedPoolUsage); 00134 return -2; 00135 } 00136 00138 long System::pagedMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) { 00139 POOLED_USAGE_AND_LIMITS quota; 00140 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) 00141 return adjustMemory(unit, quota.PagedPoolLimit); 00142 return 0; 00143 } 00144 00146 long System::numPageFault(InfoType fetch, long pid) { 00147 VM_COUNTERS info; 00148 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00149 return info.PageFaultCount; 00150 return -2; 00151 } 00152 00154 long System::pagefileUsage(MemoryUnit unit, InfoType fetch, long pid) { 00155 VM_COUNTERS info; 00156 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00157 return adjustMemory(unit, info.PagefileUsage); 00158 return -2; 00159 } 00160 00162 long System::pagefileUsagePeak(MemoryUnit unit, InfoType fetch, long pid) { 00163 VM_COUNTERS info; 00164 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00165 return adjustMemory(unit, info.PeakPagefileUsage); 00166 return -2; 00167 } 00168 00170 long System::pagefileUsageLimit(MemoryUnit unit, InfoType fetch, long pid) { 00171 POOLED_USAGE_AND_LIMITS quota; 00172 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) { 00173 if ( long(quota.PagefileLimit) < 0 ) 00174 return -1;//LONG_MAX; 00175 return adjustMemory(unit, quota.PagefileLimit); 00176 } 00177 return -2; 00178 } 00179 00181 long System::mappedMemory(MemoryUnit unit, InfoType fetch, long pid) { 00182 VM_COUNTERS info; 00183 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00184 return adjustMemory(unit, info.WorkingSetSize); 00185 return -2; 00186 } 00187 00189 long System::mappedMemoryPeak(MemoryUnit unit, InfoType fetch, long pid) { 00190 VM_COUNTERS info; 00191 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00192 return adjustMemory(unit, info.PeakWorkingSetSize); 00193 return -2; 00194 } 00195 00197 long System::minMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) { 00198 QUOTA_LIMITS quota; 00199 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) 00200 return adjustMemory(unit, quota.MinimumWorkingSetSize); 00201 return 0; 00202 } 00203 00205 long System::maxMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) { 00206 QUOTA_LIMITS quota; 00207 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) 00208 return adjustMemory(unit, quota.MaximumWorkingSetSize); 00209 return 0; 00210 } 00211 00213 long System::virtualMemory(MemoryUnit unit, InfoType fetch, long pid) { 00214 VM_COUNTERS info; 00215 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00216 return adjustMemory(unit, info.VirtualSize); 00217 return -2; 00218 } 00219 00221 long System::virtualMemoryPeak(MemoryUnit unit, InfoType fetch, long pid) { 00222 VM_COUNTERS info; 00223 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) 00224 return adjustMemory(unit, info.PeakVirtualSize); 00225 return -2; 00226 } 00227 00229 long System::virtualMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) { 00230 QUOTA_LIMITS quota; 00231 if ( fetch != NoFetch && getProcess()->query(pid, fetch, "a) ) { 00232 if ( long(quota.PagefileLimit) == -1 ) 00233 return -1;//LONG_MAX; 00234 return adjustMemory(unit, quota.PagefileLimit); 00235 } 00236 return 0; 00237 } 00238