The Gaudi Framework  v30r3 (a5ef0a68)
Memory.cpp
Go to the documentation of this file.
1 //====================================================================
2 // Memory.cpp
3 //--------------------------------------------------------------------
4 //
5 // Package : System (The LHCb System service)
6 //
7 // Description: Information of memory usage from a given process
8 //
9 // Author : M.Frank
10 // Created : 13/11/00
11 // Changes :
12 //
13 //====================================================================
14 #define GAUDIKERNEL_MEMORY_CPP
15 
16 #ifdef _WIN32
17 #include "process.h"
18 #define getpid _getpid
19 #else
20 #include "libgen.h"
21 #include "sys/times.h"
22 #include "unistd.h"
23 #include <cstdio>
24 #include <errno.h>
25 #include <string.h>
26 #endif
27 
28 // Framework include files
29 #include "GaudiKernel/Memory.h"
30 #include "ProcessDescriptor.h"
31 #include <limits.h>
32 
34 long System::adjustMemory( MemoryUnit unit, long value )
35 {
36  if ( value != -1 ) {
37  switch ( unit ) {
38  case Byte:
39  break;
40  case kByte:
41  value = value / 1024;
42  break;
43  case MByte:
44  value = ( value / 1024 ) / 1024;
45  break;
46  case GByte:
47  value = ( ( value / 1024 ) / 1024 ) / 1024;
48  break;
49  case TByte:
50  value = ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024;
51  break;
52  case PByte:
53  value = ( ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024;
54  break;
55  case EByte:
56  value = ( ( ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024;
57  break;
58  default:
59  value = -1;
60  break;
61  }
62  }
63  return value;
64 }
65 
67 long System::basePriority( InfoType fetch, long pid )
68 {
70  if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.BasePriority;
71  return 0;
72 }
73 
76 {
77  static const long s_pid = ::getpid();
78  return s_pid;
79 }
80 
82 long System::parentID( InfoType fetch, long pid )
83 {
85  if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.InheritedFromUniqueProcessId;
86  return 0;
87 }
88 
90 long System::affinityMask( InfoType fetch, long pid )
91 {
93  if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.AffinityMask;
94  return 0;
95 }
96 
98 long System::exitStatus( InfoType fetch, long pid )
99 {
101  if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.ExitStatus;
102  return -2;
103 }
104 
106 long System::priorityBoost( InfoType fetch, long pid )
107 {
108  long info;
109  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return info;
110  return -2;
111 }
112 
114 long System::nonPagedMemoryPeak( MemoryUnit unit, InfoType fetch, long pid )
115 {
116  VM_COUNTERS info;
117  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
118  return adjustMemory( unit, info.QuotaPeakNonPagedPoolUsage );
119  return -2;
120 }
121 
123 long System::nonPagedMemory( MemoryUnit unit, InfoType fetch, long pid )
124 {
125  VM_COUNTERS info;
126  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
127  return adjustMemory( unit, info.QuotaNonPagedPoolUsage );
128  return -2;
129 }
130 
132 long System::nonPagedMemoryLimit( MemoryUnit unit, InfoType fetch, long pid )
133 {
135  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
136  return adjustMemory( unit, quota.NonPagedPoolLimit );
137  return 0;
138 }
139 
141 long System::pagedMemory( MemoryUnit unit, InfoType fetch, long pid )
142 {
143  VM_COUNTERS info;
144  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
145  return adjustMemory( unit, info.QuotaPagedPoolUsage );
146  return -2;
147 }
148 
150 long System::pagedMemoryPeak( MemoryUnit unit, InfoType fetch, long pid )
151 {
152  VM_COUNTERS info;
153  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
154  return adjustMemory( unit, info.QuotaPeakPagedPoolUsage );
155  return -2;
156 }
157 
159 long System::pagedMemoryLimit( MemoryUnit unit, InfoType fetch, long pid )
160 {
162  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
163  return adjustMemory( unit, quota.PagedPoolLimit );
164  return 0;
165 }
166 
168 long System::numPageFault( InfoType fetch, long pid )
169 {
170  VM_COUNTERS info;
171  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return info.PageFaultCount;
172  return -2;
173 }
174 
176 long System::pagefileUsage( MemoryUnit unit, InfoType fetch, long pid )
177 {
178  VM_COUNTERS info;
179  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.PagefileUsage );
180  return -2;
181 }
182 
184 long System::pagefileUsagePeak( MemoryUnit unit, InfoType fetch, long pid )
185 {
186  VM_COUNTERS info;
187  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
188  return adjustMemory( unit, info.PeakPagefileUsage );
189  return -2;
190 }
191 
193 long System::pagefileUsageLimit( MemoryUnit unit, InfoType fetch, long pid )
194 {
196  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
197  if ( long( quota.PagefileLimit ) < 0 ) return -1; // LONG_MAX;
198  return adjustMemory( unit, quota.PagefileLimit );
199  }
200  return -2;
201 }
202 
204 long System::mappedMemory( MemoryUnit unit, InfoType fetch, long pid )
205 {
206  VM_COUNTERS info;
207  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.WorkingSetSize );
208  return -2;
209 }
210 
212 long System::mappedMemoryPeak( MemoryUnit unit, InfoType fetch, long pid )
213 {
214  VM_COUNTERS info;
215  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
216  return adjustMemory( unit, info.PeakWorkingSetSize );
217  return -2;
218 }
219 
221 long System::minMemoryLimit( MemoryUnit unit, InfoType fetch, long pid )
222 {
223  QUOTA_LIMITS quota;
224  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
225  return adjustMemory( unit, quota.MinimumWorkingSetSize );
226  return 0;
227 }
228 
230 long System::maxMemoryLimit( MemoryUnit unit, InfoType fetch, long pid )
231 {
232  QUOTA_LIMITS quota;
233  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
234  return adjustMemory( unit, quota.MaximumWorkingSetSize );
235  return 0;
236 }
237 
239 long System::virtualMemory( MemoryUnit unit, InfoType fetch, long pid )
240 {
241  VM_COUNTERS info;
242  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.VirtualSize );
243  return -2;
244 }
245 
247 long System::virtualMemoryPeak( MemoryUnit unit, InfoType fetch, long pid )
248 {
249  VM_COUNTERS info;
250  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.PeakVirtualSize );
251  return -2;
252 }
253 
255 long System::virtualMemoryLimit( MemoryUnit unit, InfoType fetch, long pid )
256 {
257  QUOTA_LIMITS quota;
258  if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
259  if ( long( quota.PagefileLimit ) == -1 ) return -1; // LONG_MAX;
260  return adjustMemory( unit, quota.PagefileLimit );
261  }
262  return 0;
263 }
GAUDI_API long maxMemoryLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
System Process Limits: Maximum amount of virtual memory this process is allowed to use...
Definition: Memory.cpp:230
GAUDI_API long mappedMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:212
unsigned long QuotaPeakPagedPoolUsage
GAUDI_API long parentID(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Parent&#39;s process ID.
Definition: Memory.cpp:82
unsigned long PagefileUsage
GAUDI_API long exitStatus(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Exit status (does not really make sense for the running process...
Definition: Memory.cpp:98
GAUDI_API long nonPagedMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Current usage of non paged memory.
Definition: Memory.cpp:123
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
unsigned long MaximumWorkingSetSize
unsigned long PeakPagefileUsage
unsigned long PagefileLimit
GAUDI_API long priorityBoost(InfoType fetch=PriorityBoost, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:106
unsigned long WorkingSetSize
GAUDI_API long pagedMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Maximum of paged memory occupied by the process &#39;pid&#39;. ...
Definition: Memory.cpp:150
unsigned long PeakWorkingSetSize
unsigned long VirtualSize
GAUDI_API long nonPagedMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Peak usage of non paged memory.
Definition: Memory.cpp:114
unsigned long PageFaultCount
GAUDI_API long nonPagedMemoryLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
System Process Limits: Maximum amount of non-paged memory this process is allowed to use...
Definition: Memory.cpp:132
GAUDI_API long affinityMask(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Affinity mask.
Definition: Memory.cpp:90
unsigned long QuotaNonPagedPoolUsage
GAUDI_API long virtualMemoryLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
System Process Limits: Maximum amount of the page file this process is allowed to use...
Definition: Memory.cpp:255
GAUDI_API long pagedMemoryLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
Basic Process Information: Amount of paged memory that can be occupied by the process &#39;pid&#39;...
Definition: Memory.cpp:159
unsigned long PeakVirtualSize
GAUDI_API long pagefileUsageLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
Basic Process Information: Peak usage of page file.
Definition: Memory.cpp:193
MemoryUnit
Unit of memory.
Definition: Memory.h:56
GAUDI_API long mappedMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:204
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long pagefileUsagePeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Peak usage of page file.
Definition: Memory.cpp:184
Process Quotas NtQueryInformationProcess using ProcessQuotaLimits NtQueryInformationProcess using Pro...
GAUDI_API long numPageFault(InfoType fetch=Memory, long pid=-1)
Basic Process Information: Number of page faults.
Definition: Memory.cpp:168
Process Virtual Memory Counters NtQueryInformationProcess using ProcessVmCounters.
GAUDI_API long virtualMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:239
GAUDI_API long minMemoryLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
System Process Limits: Minimum amount of virtual memory this process may use.
Definition: Memory.cpp:221
Process Pooled Quota Usage and Limits NtQueryInformationProcess using ProcessPooledUsageAndLimits.
GAUDI_API long procID()
Basic Process Information: Process ID.
Definition: Memory.cpp:75
GAUDI_API long basePriority(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Base priority.
Definition: Memory.cpp:67
GAUDI_API long virtualMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:247
unsigned long MinimumWorkingSetSize
unsigned long QuotaPeakNonPagedPoolUsage
GAUDI_API long pagefileUsage(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Current page file usage.
Definition: Memory.cpp:176
GAUDI_API long pagedMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Amount of paged memory currently occupied by the process &#39;pid&#39;...
Definition: Memory.cpp:141
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:19
unsigned long QuotaPagedPoolUsage